1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-11-07 03:22:33 +01:00

Fix video playing again

This commit is contained in:
kelteseth 2018-02-18 16:46:47 +01:00
parent 12fd518216
commit c9522fba52
6 changed files with 142 additions and 117 deletions

View File

@ -105,13 +105,19 @@ void Settings::setWallpaper(int monitorIndex, QUrl absoluteStoragePath)
decreaseActiveWallpaperCounter(); decreaseActiveWallpaperCounter();
} }
} }
increaseActiveWallpaperCounter(); increaseActiveWallpaperCounter();
auto pro = new QProcess(); auto pro = new QProcess();
QStringList proArgs; QObject::connect(pro, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), [=](int exitCode, QProcess::ExitStatus exitStatus) {
proArgs.append(absoluteStoragePath.toString()); qDebug() << "EX: " <<exitCode;
});
QStringList proArgs;
proArgs.append(QString::number(monitorIndex));
proArgs.append(absoluteStoragePath.toString());
qDebug() << proArgs;
m_windows.append(pro); m_windows.append(pro);
m_windows.last()->start(m_screenPlayWindowPath.toString()); pro->start(m_screenPlayWindowPath.toString(),proArgs);
} }
void Settings::setWidget(QUrl absoluteStoragePath) void Settings::setWidget(QUrl absoluteStoragePath)
@ -232,7 +238,6 @@ void Settings::removeAll()
m_wallpapers.at(i).data()->destroyWallpaper(); m_wallpapers.at(i).data()->destroyWallpaper();
} }
for (int i = 0; i < m_windows.size(); ++i) { for (int i = 0; i < m_windows.size(); ++i) {
} }
setActiveWallpaperCounter(0); setActiveWallpaperCounter(0);
} }

View File

@ -2,53 +2,58 @@ import QtQuick 2.9
import QtAV 1.7 import QtAV 1.7
Rectangle { Rectangle {
color: "black"
id: screenVideoPlayer id: screenVideoPlayer
color: "black"
anchors.fill: parent anchors.fill: parent
property string videoPath property string videoPath
property bool isPlaying: false onVideoPathChanged: {
Component.onCompleted: screenVideoPlayer.isPlaying = true player.source = Qt.resolvedUrl("file:///" + videoPath)
onIsPlayingChanged: { print("######### " + player.source)
if(isPlaying){ state = "playing"
player.play() player.play()
state = "playing"
} else {
player.pause()
state = ""
}
} }
// Connections{ property bool isPlaying: true
// target: wallpaper
// onPrepareDestroy:{
// player.stop();
// wallpaper.destroyWindow()
// }
// onVolumeChanged:{
// player.volume = wallpaper.volume
// }
// onIsPlayingChanged:{
// if(wallpaper.isPlaying){
// player.play()
// } else {
// player.pause()
// }
// }
// onDecoderChanged:{
// player.videoCodecPriority = [decoder]
// }
// onFillModeChanged:{
// if(fillMode === "Stretch"){
// videoOut.fillMode = VideoOutput2.Stretch
// } else if(fillMode === "PreserveAspectFit"){
// videoOut.fillMode = VideoOutput2.PreserveAspectFit
// }else if(fillMode === "PreserveAspectCrop"){
// videoOut.fillMode = VideoOutput2.PreserveAspectCrop
// }
// }
// }
// onIsPlayingChanged: {
// if(isPlaying){
// player.play()
// state = "playing"
// } else {
// player.pause()
// state = ""
// }
// }
// Connections{
// target: wallpaper
// onPrepareDestroy:{
// player.stop();
// wallpaper.destroyWindow()
// }
// onVolumeChanged:{
// player.volume = wallpaper.volume
// }
// onIsPlayingChanged:{
// if(wallpaper.isPlaying){
// player.play()
// } else {
// player.pause()
// }
// }
// onDecoderChanged:{
// player.videoCodecPriority = [decoder]
// }
// onFillModeChanged:{
// if(fillMode === "Stretch"){
// videoOut.fillMode = VideoOutput2.Stretch
// } else if(fillMode === "PreserveAspectFit"){
// videoOut.fillMode = VideoOutput2.PreserveAspectFit
// }else if(fillMode === "PreserveAspectCrop"){
// videoOut.fillMode = VideoOutput2.PreserveAspectCrop
// }
// }
// }
VideoOutput2 { VideoOutput2 {
id: videoOut id: videoOut
@ -61,10 +66,17 @@ Rectangle {
MediaPlayer { MediaPlayer {
id: player id: player
videoCodecPriority: ["CUDA", "VAAPI", "D3D11", "DXVA", "FFmpeg"] videoCodecPriority: ["CUDA", "VAAPI", "D3D11", "DXVA", "FFmpeg"]
loops: MediaPlayer.Infinite loops: MediaPlayer.Infinite
volume: 0 volume: 0
source: "d:/672870/860170953/horde_1980.mp4" onStatusChanged: {
print("STATUS: " + player.status)
if(player.status === MediaPlayer.Loaded){
print("init")
mainwindow.init()
}
}
} }
states: [ states: [

View File

@ -1,18 +1,30 @@
#include "src/mainwindow.h" #include "src/mainwindow.h"
#include <QApplication> #include <QApplication>
#include <QStringList>
int main(int argc, char* argv[])
int main(int argc, char *argv[])
{ {
//QCoreApplication::addLibraryPath("C:/msys64/mingw64/bin"); //QCoreApplication::addLibraryPath("C:/msys64/mingw64/bin");
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication::setAttribute(Qt::AA_UseOpenGLES);
QApplication a(argc, argv); QApplication a(argc, argv);
QStringList argumentList = a.arguments(); QStringList argumentList = a.arguments();
//MainWindow w(argumentList.at(0)); if(argumentList.length() != 3) {
//MainWindow w(0,"D:/672870/860170953"); return -3;
//MainWindow w1(1,"D:/672870/818696361"); }
MainWindow w2(2,"D:/672870/860170953");
bool ok = false;
int monitor = argumentList.at(1).toInt(&ok);
if (!ok) {
return -4;
}
MainWindow w(monitor,argumentList.at(2));
//MainWindow w(0,"D:/672870/786361026");
return a.exec(); return a.exec();
} }

View File

@ -1,48 +1,46 @@
import QtQuick 2.9 import QtQuick 2.9
import net.aimber.screenplaysdk 1.0 //import net.aimber.screenplaysdk 1.0
Rectangle { Rectangle {
color: "gray" color: "gray"
anchors.fill: parent anchors.fill: parent
property string tmpVideoPath
// ScreenPlaySDK {
// contentType: "wallpaper"
ScreenPlaySDK { // onIncommingMessageError: {
contentType: "wallpaper" // name.text = msg
// }
onIncommingMessageError: { // onSdkConnected: {
name.text = msg // name.text = "connected"
} // }
onSdkConnected: { // onSdkDisconnected: {
name.text = "connected" // name.text = "disconnected"
} // mainwindow.destroyThis()
// }
// }
onSdkDisconnected: { // Text {
name.text = "disconnected" // id: name
//mainwindow.destroyThis() // text: qsTr("text")
} // anchors.centerIn: parent
} // font.pixelSize: 64
// color: "orange"
// }
Connections { Connections {
target: mainwindow target: mainwindow
onPlayVideo:{ onPlayVideo: {
loaderVideo.active = true screenVideo.videoPath = path
print(path)
//loaderVideo.item.videoPath = path
} }
} }
Loader {
id:loaderVideo
anchors.fill: parent ScreenVideo {
asynchronous: true id:screenVideo
active: false
source: "qrc:/ScreenVideo.qml"
onStateChanged: {
if(status == Loader.Ready){
loaderVideo.item.isPlaying = true
}
}
} }
} }

View File

@ -1,7 +1,5 @@
#include "mainwindow.h" #include "mainwindow.h"
#include <QJsonDocument>
BOOL WINAPI SearchForWorkerWindow(HWND hwnd, LPARAM lparam) BOOL WINAPI SearchForWorkerWindow(HWND hwnd, LPARAM lparam)
{ {
// 0xXXXXXXX "" WorkerW // 0xXXXXXXX "" WorkerW
@ -33,7 +31,7 @@ MainWindow::MainWindow(int i, QString projectPath, QScreen* parent)
if (!(parseError.error == QJsonParseError::NoError)) { if (!(parseError.error == QJsonParseError::NoError)) {
qWarning("Settings Json Parse Error "); qWarning("Settings Json Parse Error ");
return; QApplication::exit(-4);
} }
m_project = configJsonDocument.object(); m_project = configJsonDocument.object();
@ -51,8 +49,6 @@ MainWindow::MainWindow(int i, QString projectPath, QScreen* parent)
if (m_project.contains("file")) if (m_project.contains("file"))
m_projectFile = m_project.value("file").toString(); m_projectFile = m_project.value("file").toString();
this->m_hwnd = (HWND)this->winId();
// Recalculate window coordiantes because of point (0,0) // Recalculate window coordiantes because of point (0,0)
// Is at the origin monitor or the most left // Is at the origin monitor or the most left
QScreen* screen = QApplication::screens().at(i); QScreen* screen = QApplication::screens().at(i);
@ -61,7 +57,6 @@ MainWindow::MainWindow(int i, QString projectPath, QScreen* parent)
for (int i = 0; i < QApplication::screens().count(); i++) { for (int i = 0; i < QApplication::screens().count(); i++) {
QScreen* screen = QApplication::screens().at(i); QScreen* screen = QApplication::screens().at(i);
qDebug() << screen->availableGeometry().x();
if (screen->availableGeometry().x() < 0) { if (screen->availableGeometry().x() < 0) {
offsetX += (screen->availableGeometry().x() * -1); offsetX += (screen->availableGeometry().x() * -1);
} }
@ -70,6 +65,7 @@ MainWindow::MainWindow(int i, QString projectPath, QScreen* parent)
} }
} }
m_hwnd = (HWND)this->winId();
HWND progman_hwnd = FindWindowW(L"Progman", L"Program Manager"); HWND progman_hwnd = FindWindowW(L"Progman", L"Program Manager");
// Spawn new worker window below desktop (using some undocumented Win32 magic) // Spawn new worker window below desktop (using some undocumented Win32 magic)
@ -80,38 +76,37 @@ MainWindow::MainWindow(int i, QString projectPath, QScreen* parent)
SendMessageTimeoutW(progman_hwnd, WM_SPAWN_WORKER, 0xD, 0x1, SMTO_NORMAL, SendMessageTimeoutW(progman_hwnd, WM_SPAWN_WORKER, 0xD, 0x1, SMTO_NORMAL,
1000, nullptr); 1000, nullptr);
EnumWindows(SearchForWorkerWindow, reinterpret_cast<LPARAM>(&m_worker_hwnd)); bool foundWorker = EnumWindows(SearchForWorkerWindow, reinterpret_cast<LPARAM>(&m_worker_hwnd));
if (!foundWorker) {
qDebug() << "No worker window found";
}
//Hide first to avoid flickering //Hide first to avoid flickering
ShowWindow(m_worker_hwnd, SW_HIDE); ShowWindow(m_worker_hwnd, SW_HIDE);
ShowWindow(m_hwnd, SW_HIDE); ShowWindow(m_hwnd, SW_HIDE);
MoveWindow(m_hwnd, screen->geometry().x() + offsetX, screen->geometry().y() + offsetY, screen->size().width(), screen->size().height(), true); MoveWindow(m_hwnd, screen->geometry().x() + offsetX, screen->geometry().y() + offsetY, screen->size().width(), screen->size().height(), true);
SetParent(m_hwnd, m_worker_hwnd); SetParent(m_hwnd, m_worker_hwnd);
SetWindowLongPtr(m_hwnd, GWL_STYLE,
WS_CAPTION | WS_THICKFRAME | WS_MINIMIZE | WS_MAXIMIZE | WS_SYSMENU); SetWindowLongPtr(m_hwnd, GWL_STYLE, WS_CHILDWINDOW | WS_CAPTION | WS_THICKFRAME | WS_MINIMIZE | WS_MAXIMIZE | WS_SYSMENU | WS_POPUP);
SetWindowLongPtr(m_hwnd, GWL_EXSTYLE, SetWindowLongPtr(m_hwnd, GWL_EXSTYLE, WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR | WS_EX_NOACTIVATE | WS_EX_TOPMOST | WS_EX_TRANSPARENT | WS_EX_TOOLWINDOW);
WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR | WS_EX_NOACTIVATE | WS_EX_TOPMOST | WS_EX_TRANSPARENT | WS_EX_TOOLWINDOW);
Qt::WindowFlags flags = this->flags(); Qt::WindowFlags flags = this->flags();
this->setFlags(flags | Qt::FramelessWindowHint | Qt::WindowStaysOnBottomHint); this->setFlags(flags | Qt::FramelessWindowHint | Qt::WindowStaysOnBottomHint);
this->show();
m_quickRenderer = QSharedPointer<QQuickView>(new QQuickView(this)); m_quickRenderer = QSharedPointer<QQuickView>(new QQuickView(this));
m_quickRenderer.data()->rootContext()->setContextProperty("mainwindow", this); m_quickRenderer.data()->rootContext()->setContextProperty("mainwindow", this);
m_quickRenderer.data()->setGeometry(0,0, screen->size().width(), screen->size().height());
m_quickRenderer.data()->setResizeMode(QQuickView::ResizeMode::SizeRootObjectToView);
m_quickRenderer.data()->setSource(QUrl("qrc:/main.qml")); m_quickRenderer.data()->setSource(QUrl("qrc:/main.qml"));
m_quickRenderer.data()->setGeometry(0, 0, width(), height());
m_quickRenderer.data()->setResizeMode(QQuickView::ResizeMode::SizeRootObjectToView);
m_quickRenderer.data()->setFlags(flags | Qt::FramelessWindowHint | Qt::WindowStaysOnBottomHint);
QPropertyAnimation* animation = new QPropertyAnimation(this, "opacity"); QPropertyAnimation* animation = new QPropertyAnimation(this, "opacity");
animation->setDuration(250); animation->setDuration(250);
animation->setEasingCurve(QEasingCurve::OutCubic); animation->setEasingCurve(QEasingCurve::OutCubic);
animation->setStartValue(0); animation->setStartValue(0);
animation->setEndValue(1); animation->setEndValue(1);
m_quickRenderer.data()->show();
ShowWindow(m_worker_hwnd, SW_SHOWDEFAULT);
ShowWindow(m_hwnd, SW_SHOWDEFAULT);
animation->start(); animation->start();
@ -119,7 +114,6 @@ MainWindow::MainWindow(int i, QString projectPath, QScreen* parent)
if (m_project.contains("type")) { if (m_project.contains("type")) {
if (m_project.value("type") == "video") { if (m_project.value("type") == "video") {
QString tmpPath = m_projectPath.toString() + "/" + m_projectFile; QString tmpPath = m_projectPath.toString() + "/" + m_projectFile;
tmpPath.replace("/", "\\\\");
emit playVideo(tmpPath); emit playVideo(tmpPath);
} else if (m_project.value("type") == "scene") { } else if (m_project.value("type") == "scene") {
return; return;
@ -130,20 +124,25 @@ MainWindow::MainWindow(int i, QString projectPath, QScreen* parent)
void MainWindow::destroyThis() void MainWindow::destroyThis()
{ {
ShowWindow(m_worker_hwnd, SW_HIDE);
ShowWindow(m_hwnd, SW_HIDE);
QCoreApplication::quit();
/*
QPropertyAnimation* animation = new QPropertyAnimation(this, "opacity"); QPropertyAnimation* animation = new QPropertyAnimation(this, "opacity");
animation->setDuration(5000); animation->setDuration(5000);
animation->setStartValue(1); animation->setStartValue(1);
animation->setEndValue(0); animation->setEndValue(0);
animation->start(); animation->start();
QObject::connect(animation,&QPropertyAnimation::finished, [&]() { QObject::connect(animation, &QPropertyAnimation::finished, [&]() {
ShowWindow(m_worker_hwnd, SW_HIDE);
ShowWindow(m_hwnd, SW_HIDE);
QCoreApplication::quit();
});
}
});*/ void MainWindow::init()
{
ShowWindow(m_worker_hwnd, SW_SHOWDEFAULT);
ShowWindow(m_hwnd, SW_SHOWDEFAULT);
m_quickRenderer.data()->show();
this->show();
} }
QUrl MainWindow::projectPath() const QUrl MainWindow::projectPath() const

View File

@ -1,7 +1,10 @@
#pragma once #pragma once
#include <QApplication> #include <QApplication>
#include <QEasingCurve> #include <QEasingCurve>
#include <QJsonDocument>
#include <QJsonObject>
#include <QObject> #include <QObject>
#include <QPropertyAnimation> #include <QPropertyAnimation>
#include <QQmlContext> #include <QQmlContext>
@ -11,22 +14,19 @@
#include <QWindow> #include <QWindow>
#include <QtQuick/QQuickView> #include <QtQuick/QQuickView>
#include <QtQuick/QQuickWindow> #include <QtQuick/QQuickWindow>
#include <QJsonObject>
#include "qt_windows.h" #include "qt_windows.h"
class MainWindow : public QWindow { class MainWindow : public QWindow {
Q_OBJECT Q_OBJECT
public: public:
explicit MainWindow(int i, QString projectPath, QScreen* parent = 0); explicit MainWindow(int i, QString projectPath, QScreen* parent = 0);
void init();
~MainWindow(); ~MainWindow();
QUrl projectPath() const; QUrl projectPath() const;
void setProjectPath(const QUrl &projectPath); void setProjectPath(const QUrl& projectPath);
public slots: public slots:
void destroyThis(); void destroyThis();
void init();
signals: signals:
void playVideo(QString path); void playVideo(QString path);
@ -38,5 +38,4 @@ private:
QUrl m_projectPath; QUrl m_projectPath;
QString m_projectFile; QString m_projectFile;
QJsonObject m_project; QJsonObject m_project;
}; };