From 324ab64637ebd40df9e8937b2aab3f9dc3030a3d Mon Sep 17 00:00:00 2001 From: kelteseth Date: Mon, 20 Aug 2018 15:18:56 +0200 Subject: [PATCH] Add working webm player. WARNING: THERE IS NO ERROR FOR PLAYING MP4 YET IMPLEMENTED! --- ScreenPlayWindow/SPWmain.cpp | 11 ++- ScreenPlayWindow/ScreenPlayWindow.pro | 17 +++-- ScreenPlayWindow/index.html | 23 ++++++ ScreenPlayWindow/main.qml | 101 ++++++++++++------------- ScreenPlayWindow/src/SPWmainwindow.cpp | 34 ++++++--- ScreenPlayWindow/src/SPWmainwindow.h | 23 +++++- 6 files changed, 130 insertions(+), 79 deletions(-) create mode 100644 ScreenPlayWindow/index.html diff --git a/ScreenPlayWindow/SPWmain.cpp b/ScreenPlayWindow/SPWmain.cpp index 97725f96..9eaf605a 100644 --- a/ScreenPlayWindow/SPWmain.cpp +++ b/ScreenPlayWindow/SPWmain.cpp @@ -5,13 +5,11 @@ int main(int argc, char* argv[]) { QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); - QApplication::setAttribute(Qt::AA_UseOpenGLES); - QApplication a(argc, argv); - QStringList argumentList = a.arguments(); + QStringList argumentList = a.arguments(); - if(argumentList.length() != 7) { + if (argumentList.length() != 7) { return -3; } @@ -23,8 +21,9 @@ int main(int argc, char* argv[]) } // Args: which monitor, path to project, wallpaper secret to identify the connected socket - MainWindow w(monitor,argumentList.at(2), argumentList.at(3),argumentList.at(4),argumentList.at(5),argumentList.at(6)); - //MainWindow w(0,"D:/672870/827148653"); + //MainWindow w(monitor, argumentList.at(2), argumentList.at(3), argumentList.at(4), argumentList.at(5), argumentList.at(6)); + //MainWindow w(0,"D:/672870/827148653","","","",""); + MainWindow w(monitor, argumentList.at(2), argumentList.at(3), argumentList.at(4), argumentList.at(5), argumentList.at(6)); return a.exec(); } diff --git a/ScreenPlayWindow/ScreenPlayWindow.pro b/ScreenPlayWindow/ScreenPlayWindow.pro index 2e9795c4..8b15c843 100644 --- a/ScreenPlayWindow/ScreenPlayWindow.pro +++ b/ScreenPlayWindow/ScreenPlayWindow.pro @@ -1,7 +1,7 @@ TEMPLATE = app QT += qml quick quickcontrols2 widgets core CONFIG += c++17 -CONFIG += qtquickcompiler +#CONFIG += qtquickcompiler msvc: LIBS += -luser32 TARGETPATH = ScreenPlayWindow @@ -28,9 +28,15 @@ CONFIG(debug, debug|release) { } +install_it.files += index.html \ + +INSTALLS += install_it + +DISTFILES += \ + index.html + # Additional import path used to resolve QML modules in Qt Creator's code model -QML_IMPORT_PATH += [QtAVSourceCodeDir]/qml -QML_IMPORT_PATH += "C:\msys64\mingw64\share\qt5\qml" +QML_IMPORT_PATH = # Additional import path used to resolve QML modules just for Qt Quick Designer QML_DESIGNER_IMPORT_PATH = @@ -46,8 +52,3 @@ DEFINES += QT_DEPRECATED_WARNINGS qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target - -win32 { - INCLUDEPATH += "C:\msys64\mingw64\include" -} - diff --git a/ScreenPlayWindow/index.html b/ScreenPlayWindow/index.html new file mode 100644 index 00000000..c91f842e --- /dev/null +++ b/ScreenPlayWindow/index.html @@ -0,0 +1,23 @@ + + + + + + + + + diff --git a/ScreenPlayWindow/main.qml b/ScreenPlayWindow/main.qml index aad9a8ee..39222abd 100644 --- a/ScreenPlayWindow/main.qml +++ b/ScreenPlayWindow/main.qml @@ -1,36 +1,28 @@ import QtQuick 2.9 +import QtWebEngine 1.6 import net.aimber.screenplaysdk 1.0 Rectangle { id: root - color: "gray" + color: "transparent" anchors.fill: parent property string tmpVideoPath property var jsonProjectFile - Component.onCompleted: { - - - // jsonProjectFile = JSON.parse(mainwindow.projectConfig) - - // if(jsonProjectFile.type === "qmlScene"){ - - // } - } - ScreenPlaySDK { id: spSDK contentType: "ScreenPlayWindow" appID: mainwindow.appID onIncommingMessageError: { - //rctError.opacity = 1 - //txtDebug.text = "ERROR: " + msg.toString() + } onIncommingMessage: { - var obj2 = 'import QtQuick 2.9; Item {Component.onCompleted: sceneLoader.item.' + key + ' = ' + value + '; }' - var newObject = Qt.createQmlObject(obj2.toString(), root, "err") - newObject.destroy(10000) + + + // var obj2 = 'import QtQuick 2.9; Item {Component.onCompleted: sceneLoader.item.' + key + ' = ' + value + '; }' + // var newObject = Qt.createQmlObject(obj2.toString(), root, "err") + // newObject.destroy(10000) } onSdkConnected: { @@ -38,8 +30,6 @@ Rectangle { } onSdkDisconnected: { - //name.text = "disconnected" - screenVideo.state = "destroy" mainwindow.destroyThis() } } @@ -48,53 +38,60 @@ Rectangle { target: mainwindow onPlayVideo: { - screenVideo.videoPath = path - //screenVideoLoader.setSource("qrc:/ScreenVideo.qml", {videoPath: path}) + } onPlayQmlScene: { - var tmp = Qt.resolvedUrl("file:///" + file) - print(tmp) - sceneLoader.setSource(tmp) - mainwindow.init() + } - onDecoderChanged:{ - screenVideo.decoder = decoder + onDecoderChanged: { + } - onFillModeChanged:{ - screenVideo.fillMode = fillMode + onFillModeChanged: { + } - onLoopsChanged:{ - screenVideo.loops = loops + onLoopsChanged: { + } - onVolumeChanged:{ - screenVideo.volume = volume + onVolumeChanged: { + } } - ScreenVideo { - id: screenVideo - } - - // Loader { - // id:screenVideoLoader - // anchors.fill: parent - // } - Loader { - id: sceneLoader + WebEngineView { + id: webView anchors.fill: parent + url: Qt.resolvedUrl("file:///" + mainwindow.getApplicationPath() + "/index.html") + onLoadProgressChanged: { + print(loadProgress) + if (loadProgress === 100) { + timerShowDelay.start() + } + } + userScripts: [scriptPlayer] + onJavaScriptConsoleMessage: print(message) + settings.allowRunningInsecureContent: true + + WebEngineScript { + id: scriptPlayer + injectionPoint: WebEngineScript.DocumentReady + worldId: WebEngineScript.MainWorld + sourceCode: { + return "var videoPlayer = document.getElementById('videoPlayer'); + var videoSource = document.getElementById('videoSource'); + videoSource.src = \"file:///" + mainwindow.fullContentPath + "\"; + videoPlayer.load();" + } + } + + } - Rectangle { - id: rctError - opacity: 0 - height: 300 - width: 600 - anchors.centerIn: parent - Text { - id: txtDebug - font.pixelSize: 32 - anchors.centerIn: parent + Timer { + id: timerShowDelay + interval: 2000 + onTriggered: { + mainwindow.init() } } } diff --git a/ScreenPlayWindow/src/SPWmainwindow.cpp b/ScreenPlayWindow/src/SPWmainwindow.cpp index b48b35aa..cf399803 100644 --- a/ScreenPlayWindow/src/SPWmainwindow.cpp +++ b/ScreenPlayWindow/src/SPWmainwindow.cpp @@ -1,4 +1,5 @@ #include "SPWmainwindow.h" + #ifdef Q_OS_WIN BOOL WINAPI SearchForWorkerWindow(HWND hwnd, LPARAM lparam) @@ -14,6 +15,7 @@ BOOL WINAPI SearchForWorkerWindow(HWND hwnd, LPARAM lparam) return TRUE; } #endif + MainWindow::MainWindow(int i, QString projectPath, QString id, QString decoder, QString volume, QString fillmode, QScreen* parent) : QWindow(parent) { @@ -52,6 +54,20 @@ MainWindow::MainWindow(int i, QString projectPath, QString id, QString decoder, if (m_project.contains("file")) m_projectFile = m_project.value("file").toString(); + if (m_project.contains("type")) { + if (m_project.value("type") == "video") { + QString tmpPath = m_projectPath.toString() + "/" + m_projectFile; + setFullContentPath(tmpPath); + + emit playVideo(tmpPath); + } else if (m_project.value("type") == "scene") { + return; + } else if (m_project.value("type") == "qmlScene") { + QString tmpPath = m_projectPath.toString() + "/" + m_projectFile; + emit playQmlScene(tmpPath); + } + } + // Recalculate window coordiantes because of point (0,0) // Is at the origin monitor or the most left QScreen* screen = QApplication::screens().at(i); @@ -116,28 +132,17 @@ MainWindow::MainWindow(int i, QString projectPath, QString id, QString decoder, } }); - if (m_project.contains("type")) { - if (m_project.value("type") == "video") { - QString tmpPath = m_projectPath.toString() + "/" + m_projectFile; - emit playVideo(tmpPath); - } else if (m_project.value("type") == "scene") { - return; - } else if (m_project.value("type") == "qmlScene") { - QString tmpPath = m_projectPath.toString() + "/" + m_projectFile; - emit playQmlScene(tmpPath); - } - } #endif } void MainWindow::init() { setOpacity(0); #ifdef Q_OS_WIN - ShowWindow(m_worker_hwnd, SW_SHOWDEFAULT); ShowWindow(m_hwnd, SW_SHOWDEFAULT); #endif + setOpacity(0); QPropertyAnimation* animation = new QPropertyAnimation(this, "opacity"); animation->setDuration(200); //animation->setEasingCurve(QEasingCurve::OutCubic); @@ -146,6 +151,11 @@ void MainWindow::init() animation->start(); } +QString MainWindow::getApplicationPath() +{ + return QApplication::applicationDirPath(); +} + void MainWindow::setScreenNumber(const QVector& screenNumber) { m_screenNumber = screenNumber; diff --git a/ScreenPlayWindow/src/SPWmainwindow.h b/ScreenPlayWindow/src/SPWmainwindow.h index ccc49b7d..996bcc97 100644 --- a/ScreenPlayWindow/src/SPWmainwindow.h +++ b/ScreenPlayWindow/src/SPWmainwindow.h @@ -1,6 +1,5 @@ #pragma once - #include #include #include @@ -16,9 +15,11 @@ #include #include #include + #ifdef Q_OS_WIN #include #endif + class MainWindow : public QWindow { Q_OBJECT @@ -36,6 +37,7 @@ public: Q_PROPERTY(QString fillMode READ fillMode WRITE setFillMode NOTIFY fillModeChanged) Q_PROPERTY(bool loops READ loops WRITE setLoops NOTIFY loopsChanged) Q_PROPERTY(float volume READ volume WRITE setVolume NOTIFY volumeChanged) + Q_PROPERTY(QString fullContentPath READ fullContentPath WRITE setFullContentPath NOTIFY fullContentPathChanged) QString projectConfig() const @@ -86,6 +88,11 @@ public: return m_decoder; } + QString fullContentPath() const + { + return m_fullContentPath; + } + public slots: void destroyThis(); void init(); @@ -155,6 +162,17 @@ public slots: emit decoderChanged(m_decoder); } + QString getApplicationPath(); + + void setFullContentPath(QString fullContentPath) + { + if (m_fullContentPath == fullContentPath) + return; + + m_fullContentPath = fullContentPath; + emit fullContentPathChanged(m_fullContentPath); + } + signals: void playVideo(QString path); void playQmlScene(QString file); @@ -167,6 +185,8 @@ signals: void volumeChanged(float volume); void decoderChanged(QString decoder); + void fullContentPathChanged(QString fullContentPath); + private: #ifdef Q_OS_WIN HWND m_hwnd; @@ -185,4 +205,5 @@ private: bool m_loops; float m_volume; QString m_decoder; + QString m_fullContentPath; };