From 2ec15cce5cda42ec125eb3e3bc1a8d999f4dcd70 Mon Sep 17 00:00:00 2001 From: Vladislav Kobzar Date: Tue, 28 Nov 2017 09:36:29 -0500 Subject: [PATCH] Fixed media playback bug from history --- mediawidget.cpp | 40 +++++++++++++++++++++++++++++++------- mediawidget.hpp | 6 ++++-- projectordisplayscreen.cpp | 13 +++++++------ projectordisplayscreen.hpp | 2 +- videoinfo.hpp | 3 ++- 5 files changed, 47 insertions(+), 17 deletions(-) diff --git a/mediawidget.cpp b/mediawidget.cpp index b64af2f..ff5539f 100644 --- a/mediawidget.cpp +++ b/mediawidget.cpp @@ -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); @@ -130,6 +130,7 @@ void MediaWidget::loadMediaLibrary() void MediaWidget::statusChanged(QMediaPlayer::MediaStatus status) { + qDebug()<<"statusChanged"<stop(); - currentMediaUrl = QUrl::fromLocalFile(filePath); - QMediaContent m(currentMediaUrl); + currentMediaUrl = filePath; + QMediaContent m(filePath); player->setMedia(m); } @@ -290,7 +296,7 @@ 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()); } @@ -298,19 +304,23 @@ void MediaWidget::insertFiles(QStringList &files) void MediaWidget::hasVideoChanged(bool bHasVideo) { + qDebug()<<"hasVideoChanged"<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); } @@ -379,6 +389,11 @@ 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(); @@ -386,10 +401,21 @@ void MediaWidget::setMediaFromSchedule(VideoInfo &v) void MediaWidget::goLiveFromSchedule() { + while (!isReadyToPlay) + { + Sleep(100); + } + qDebug()<isVisible()<pushButtonGoLive->isEnabled(); if(ui->pushButtonGoLive->isEnabled()) + { + qDebug()<<"Go Live is Enabled"; prepareForProjection(); + } else + { + qDebug()<<"Start Playing"; player->play(); + } } bool MediaWidget::isValidMedia() diff --git a/mediawidget.hpp b/mediawidget.hpp index d5a2de7..2d24f91 100644 --- a/mediawidget.hpp +++ b/mediawidget.hpp @@ -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); @@ -94,9 +94,11 @@ private slots: QString audioExt; QString videoExt; - QStringList mediaFilePaths; + QList mediaFilePaths; QStringList mediaFileNames; QUrl currentMediaUrl; + + bool isReadyToPlay; }; #endif // MEDIAWIDGET_HPP diff --git a/projectordisplayscreen.cpp b/projectordisplayscreen.cpp index 6a5f39a..14c117d 100644 --- a/projectordisplayscreen.cpp +++ b/projectordisplayscreen.cpp @@ -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() diff --git a/projectordisplayscreen.hpp b/projectordisplayscreen.hpp index fe46e11..744c673 100644 --- a/projectordisplayscreen.hpp +++ b/projectordisplayscreen.hpp @@ -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(); diff --git a/videoinfo.hpp b/videoinfo.hpp index 56fe870..a4e8b7b 100644 --- a/videoinfo.hpp +++ b/videoinfo.hpp @@ -21,13 +21,14 @@ #define VIDEOINFO_HPP #include +#include class VideoInfo { public: VideoInfo(); public: - QString filePath; + QUrl filePath; QString fileName; int aspectRatio; };