Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a DBus message handler that plays a video via Qt #1931

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions webview/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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 \
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion webview/ScreenlyWebview.pro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
TEMPLATE = app

QT += webenginecore webenginewidgets dbus
QT += webengine webenginewidgets dbus multimedia multimediawidgets
CONFIG += c++11

SOURCES += src/main.cpp \
Expand Down
50 changes: 49 additions & 1 deletion webview/src/mainwindow.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
#include <QStandardPaths>
#include <QTimer>
#include <QWebEngineSettings>

#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)
Expand All @@ -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;
}
7 changes: 7 additions & 0 deletions webview/src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <QMainWindow>
#include <QWebEngineView>
#include <QMediaPlayer>
#include <QVideoWidget>

#include "view.h"

Expand All @@ -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;
};
Loading