diff --git a/webview/Dockerfile b/webview/Dockerfile index cc89d5a81..458588efd 100644 --- a/webview/Dockerfile +++ b/webview/Dockerfile @@ -8,11 +8,6 @@ RUN apt-get update && \ apt-utils \ firebird-dev \ freetds-dev \ - gstreamer1.0-tools \ - gstreamer1.0-plugins-base \ - gstreamer1.0-plugins-good \ - gstreamer1.0-plugins-ugly \ - gstreamer1.0-x \ libasound2-dev \ libavcodec-dev \ libavformat-dev \ @@ -31,8 +26,6 @@ RUN apt-get update && \ libgles2-mesa-dev \ libglib2.0-dev \ libgst-dev \ - libgstreamer-plugins-base1.0-dev \ - libgstreamer1.0-dev \ libicu-dev \ libinput-dev \ libiodbc2-dev \ @@ -96,7 +89,22 @@ RUN apt-get update && \ nodejs \ ruby \ va-driver-all \ - wget + wget \ + libgstreamer1.0-dev \ + libgstreamer-plugins-base1.0-dev \ + libgstreamer-plugins-bad1.0-dev \ + gstreamer1.0-plugins-base \ + gstreamer1.0-plugins-good \ + gstreamer1.0-plugins-bad \ + gstreamer1.0-plugins-ugly \ + gstreamer1.0-libav \ + gstreamer1.0-tools \ + gstreamer1.0-x \ + gstreamer1.0-alsa \ + gstreamer1.0-gl \ + gstreamer1.0-gtk3 \ + gstreamer1.0-qt5 \ + gstreamer1.0-pulseaudio # Really make sure we don't have this package installed # as it will break the build of QTWebEngine diff --git a/webview/ScreenlyWebview.pro b/webview/ScreenlyWebview.pro index 82aaf6989..b33d83817 100644 --- a/webview/ScreenlyWebview.pro +++ b/webview/ScreenlyWebview.pro @@ -1,6 +1,6 @@ TEMPLATE = app -QT += webenginecore webenginewidgets dbus +QT += webengine webenginewidgets dbus multimedia multimediawidgets CONFIG += c++11 SOURCES += src/main.cpp \ diff --git a/webview/src/mainwindow.cpp b/webview/src/mainwindow.cpp index e26bb67f3..c0b5d3600 100644 --- a/webview/src/mainwindow.cpp +++ b/webview/src/mainwindow.cpp @@ -1,16 +1,20 @@ #include +#include #include #include "mainwindow.h" #include "view.h" - MainWindow::MainWindow() : QMainWindow() { view = new View(this); view -> settings() -> setAttribute(QWebEngineSettings::LocalStorageEnabled, false); view -> settings() -> setAttribute(QWebEngineSettings::ShowScrollBars, false); setCentralWidget(view); + + player = new QMediaPlayer(this, QMediaPlayer::Flags(QMediaPlayer::VideoSurface)); + videoWidget = new QVideoWidget; + player->setVideoOutput(videoWidget); } void MainWindow::loadPage(const QString &uri) @@ -22,3 +26,47 @@ void MainWindow:: loadImage(const QString &uri) { view -> loadImage(uri); } + +void MainWindow::loadVideo(const QString &uri, unsigned int durationInSecs) +{ + qDebug() << "Type: Video, URI: " << uri << ", Duration: " << durationInSecs << "s"; + + if (ready) + { + ready = false; + player->setMedia(QUrl::fromLocalFile(uri)); + + // Show a blank screen for a second before playing the video. + // This is to prevent the non-video content from being displayed for a short time + // after the video has finished playing. + view->loadImage("null"); + QEventLoop loop; + QTimer::singleShot(1000, &loop, SLOT(quit())); + loop.exec(); + + view->hide(); + videoWidget->setFullScreen(true); + videoWidget->show(); + + player->play(); + + // Convert duration from seconds to milliseconds. + unsigned int additionalDurationInMs = 1000; // This prevents the video for being stopped too early. + unsigned int durationInMs = durationInSecs * 1000 + additionalDurationInMs; + + // @TODO: Use the state() method instead to check if the video is still playing. + // At the moment, state() returns QMediaPlayer::StoppedState even if the video is still playing. + QTimer::singleShot(durationInMs, this, [=](){ + player->stop(); + ready = true; + + videoWidget->hide(); + view->show(); + }); + } +} + +bool MainWindow::isReady() +{ + return ready; +} diff --git a/webview/src/mainwindow.h b/webview/src/mainwindow.h index b972b5e9d..3d318e271 100644 --- a/webview/src/mainwindow.h +++ b/webview/src/mainwindow.h @@ -2,6 +2,8 @@ #include #include +#include +#include #include "view.h" @@ -15,7 +17,12 @@ class MainWindow : public QMainWindow public slots: void loadPage(const QString &uri); void loadImage(const QString &uri); + void loadVideo(const QString &uri, unsigned int durationInSecs); + bool isReady(); private: View *view; + QMediaPlayer *player; + QVideoWidget *videoWidget; + bool ready = true; };