1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-09-03 09:09:48 +02: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();
}
}
increaseActiveWallpaperCounter();
auto pro = new QProcess();
QStringList proArgs;
proArgs.append(absoluteStoragePath.toString());
QObject::connect(pro, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), [=](int exitCode, QProcess::ExitStatus exitStatus) {
qDebug() << "EX: " <<exitCode;
});
QStringList proArgs;
proArgs.append(QString::number(monitorIndex));
proArgs.append(absoluteStoragePath.toString());
qDebug() << proArgs;
m_windows.append(pro);
m_windows.last()->start(m_screenPlayWindowPath.toString());
pro->start(m_screenPlayWindowPath.toString(),proArgs);
}
void Settings::setWidget(QUrl absoluteStoragePath)
@ -232,7 +238,6 @@ void Settings::removeAll()
m_wallpapers.at(i).data()->destroyWallpaper();
}
for (int i = 0; i < m_windows.size(); ++i) {
}
setActiveWallpaperCounter(0);
}

View File

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

View File

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

View File

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

View File

@ -1,7 +1,5 @@
#include "mainwindow.h"
#include <QJsonDocument>
BOOL WINAPI SearchForWorkerWindow(HWND hwnd, LPARAM lparam)
{
// 0xXXXXXXX "" WorkerW
@ -33,7 +31,7 @@ MainWindow::MainWindow(int i, QString projectPath, QScreen* parent)
if (!(parseError.error == QJsonParseError::NoError)) {
qWarning("Settings Json Parse Error ");
return;
QApplication::exit(-4);
}
m_project = configJsonDocument.object();
@ -51,8 +49,6 @@ MainWindow::MainWindow(int i, QString projectPath, QScreen* parent)
if (m_project.contains("file"))
m_projectFile = m_project.value("file").toString();
this->m_hwnd = (HWND)this->winId();
// Recalculate window coordiantes because of point (0,0)
// Is at the origin monitor or the most left
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++) {
QScreen* screen = QApplication::screens().at(i);
qDebug() << screen->availableGeometry().x();
if (screen->availableGeometry().x() < 0) {
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");
// 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,
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
ShowWindow(m_worker_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);
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_EXSTYLE,
WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR | WS_EX_NOACTIVATE | WS_EX_TOPMOST | WS_EX_TRANSPARENT | WS_EX_TOOLWINDOW);
SetParent(m_hwnd, m_worker_hwnd);
SetWindowLongPtr(m_hwnd, GWL_STYLE, WS_CHILDWINDOW | WS_CAPTION | WS_THICKFRAME | WS_MINIMIZE | WS_MAXIMIZE | WS_SYSMENU | WS_POPUP);
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);
Qt::WindowFlags flags = this->flags();
this->setFlags(flags | Qt::FramelessWindowHint | Qt::WindowStaysOnBottomHint);
this->show();
m_quickRenderer = QSharedPointer<QQuickView>(new QQuickView(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()->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");
animation->setDuration(250);
animation->setEasingCurve(QEasingCurve::OutCubic);
animation->setStartValue(0);
animation->setEndValue(1);
m_quickRenderer.data()->show();
ShowWindow(m_worker_hwnd, SW_SHOWDEFAULT);
ShowWindow(m_hwnd, SW_SHOWDEFAULT);
animation->start();
@ -119,7 +114,6 @@ MainWindow::MainWindow(int i, QString projectPath, QScreen* parent)
if (m_project.contains("type")) {
if (m_project.value("type") == "video") {
QString tmpPath = m_projectPath.toString() + "/" + m_projectFile;
tmpPath.replace("/", "\\\\");
emit playVideo(tmpPath);
} else if (m_project.value("type") == "scene") {
return;
@ -130,20 +124,25 @@ MainWindow::MainWindow(int i, QString projectPath, QScreen* parent)
void MainWindow::destroyThis()
{
ShowWindow(m_worker_hwnd, SW_HIDE);
ShowWindow(m_hwnd, SW_HIDE);
QCoreApplication::quit();
/*
QPropertyAnimation* animation = new QPropertyAnimation(this, "opacity");
animation->setDuration(5000);
animation->setStartValue(1);
animation->setEndValue(0);
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

View File

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