Skip to content

Commit

Permalink
Fixed media playback bug from history
Browse files Browse the repository at this point in the history
  • Loading branch information
vladozar committed Nov 28, 2017
1 parent 320e859 commit 2ec15cc
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 17 deletions.
40 changes: 33 additions & 7 deletions mediawidget.cpp
Expand Up @@ -25,9 +25,9 @@
MediaWidget::MediaWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::MediaWidget)//,
// m_AudioOutput(Phonon::VideoCategory)
{
ui->setupUi(this);
isReadyToPlay = false;
player = new QMediaPlayer(this);

mediaControls = new MediaControl(this);
Expand Down Expand Up @@ -130,6 +130,7 @@ void MediaWidget::loadMediaLibrary()

void MediaWidget::statusChanged(QMediaPlayer::MediaStatus status)
{
qDebug()<<"statusChanged"<<status;
switch (status) {
case QMediaPlayer::BufferingMedia:
case QMediaPlayer::LoadingMedia:
Expand All @@ -143,6 +144,10 @@ void MediaWidget::statusChanged(QMediaPlayer::MediaStatus status)
case QMediaPlayer::InvalidMedia:
displayErrorMessage();
break;
case QMediaPlayer::LoadedMedia:
case QMediaPlayer::BufferedMedia:
isReadyToPlay = true;
break;
}
}

Expand Down Expand Up @@ -224,11 +229,12 @@ void MediaWidget::dragMoveEvent(QDragMoveEvent *e)
}


void MediaWidget::playFile(QString filePath)
void MediaWidget::playFile(QUrl filePath)
{
isReadyToPlay = false;
player->stop();
currentMediaUrl = QUrl::fromLocalFile(filePath);
QMediaContent m(currentMediaUrl);
currentMediaUrl = filePath;
QMediaContent m(filePath);
player->setMedia(m);
}

Expand Down Expand Up @@ -290,27 +296,31 @@ void MediaWidget::insertFiles(QStringList &files)
{
QFileInfo f(file);
mediaFileNames.append(f.fileName());
mediaFilePaths.append(file);
mediaFilePaths.append(QUrl::fromLocalFile(file));
sq.exec(QString("INSERT INTO Media (long_Path, short_path) VALUES('%1', '%2')").arg(file).arg(f.fileName()));
ui->listWidgetMediaFiles->addItem(f.fileName());
}
}

void MediaWidget::hasVideoChanged(bool bHasVideo)
{
qDebug()<<"hasVideoChanged"<<bHasVideo;
if(!bHasVideo && videoWidget->isFullScreen())
videoWidget->setFullScreen(false);
ui->labelInfo->setVisible(!bHasVideo);
ui->pushButtonGoLive->setEnabled(bHasVideo);
videoWidget->setVisible(bHasVideo);
// isReadyToPlay = true;
}

void MediaWidget::prepareForProjection()
{
player->pause();
VideoInfo v;
v.fileName = mediaFileNames.at(ui->listWidgetMediaFiles->currentRow());
v.filePath = mediaFilePaths.at(ui->listWidgetMediaFiles->currentRow());
// v.fileName = mediaFileNames.at(ui->listWidgetMediaFiles->currentRow());
// v.filePath = mediaFilePaths.at(ui->listWidgetMediaFiles->currentRow());
v.fileName = currentMediaUrl.fileName();
v.filePath = currentMediaUrl.toString();
emit toProjector(v);
}

Expand Down Expand Up @@ -379,17 +389,33 @@ VideoInfo MediaWidget::getMedia()

void MediaWidget::setMediaFromSchedule(VideoInfo &v)
{
if(currentMediaUrl == v.filePath)
{
// Same current Media File, do not update.
return;
}
ui->listWidgetMediaFiles->clearSelection();
playFile(v.filePath);
player->pause();
}

void MediaWidget::goLiveFromSchedule()
{
while (!isReadyToPlay)
{
Sleep(100);
}
qDebug()<<videoWidget->isVisible()<<ui->pushButtonGoLive->isEnabled();
if(ui->pushButtonGoLive->isEnabled())
{
qDebug()<<"Go Live is Enabled";
prepareForProjection();
}
else
{
qDebug()<<"Start Playing";
player->play();
}
}

bool MediaWidget::isValidMedia()
Expand Down
6 changes: 4 additions & 2 deletions mediawidget.hpp
Expand Up @@ -61,7 +61,7 @@ public slots:
void toProjector(VideoInfo &vid);

private slots:
void playFile(QString filePath);
void playFile(QUrl filePath);
void updateInfo();

void handleDrop(QDropEvent *e);
Expand Down Expand Up @@ -94,9 +94,11 @@ private slots:

QString audioExt;
QString videoExt;
QStringList mediaFilePaths;
QList<QUrl> mediaFilePaths;
QStringList mediaFileNames;
QUrl currentMediaUrl;

bool isReadyToPlay;
};

#endif // MEDIAWIDGET_HPP
13 changes: 7 additions & 6 deletions projectordisplayscreen.cpp
Expand Up @@ -180,13 +180,14 @@ void ProjectorDisplayScreen::setBackVideo(QString path)
item2->setProperty("fillMode",Qt::IgnoreAspectRatio);
}

void ProjectorDisplayScreen::setVideoSource(QObject* playerObject, QString path)
void ProjectorDisplayScreen::setVideoSource(QObject* playerObject, QUrl path)
{
#if (defined(Q_OS_UNIX))
// Prefix "file://" to the file name only for Unix like systems.
path = "file://" + path;
#endif
playerObject->setProperty("source",path);
//#if (defined(Q_OS_UNIX))
// // Prefix "file://" to the file name only for Unix like systems.
// path = "file://" + path;
//#endif
// playerObject->setProperty("source",path);
playerObject->setProperty("source",path.toString());
}

void ProjectorDisplayScreen::updateScreen()
Expand Down
2 changes: 1 addition & 1 deletion projectordisplayscreen.hpp
Expand Up @@ -74,7 +74,7 @@ private slots:
void setBackPixmap(QPixmap p, QColor c);
void setTextPixmap(QPixmap p);
void setBackVideo(QString path);
void setVideoSource(QObject *playerObject, QString path);
void setVideoSource(QObject *playerObject, QUrl path);
void updateScreen();

void exitSlideClicked();
Expand Down
3 changes: 2 additions & 1 deletion videoinfo.hpp
Expand Up @@ -21,13 +21,14 @@
#define VIDEOINFO_HPP

#include <QString>
#include <QUrl>

class VideoInfo
{
public:
VideoInfo();
public:
QString filePath;
QUrl filePath;
QString fileName;
int aspectRatio;
};
Expand Down

0 comments on commit 2ec15cc

Please sign in to comment.