2021-10-08 10:14:11 +02:00
|
|
|
import QtQuick
|
2021-07-15 12:07:39 +02:00
|
|
|
import QtMultimedia
|
2022-05-05 13:02:54 +02:00
|
|
|
import ScreenPlayWallpaper
|
2021-07-15 12:07:39 +02:00
|
|
|
|
2021-11-01 18:25:46 +01:00
|
|
|
Item {
|
2021-09-10 11:36:47 +02:00
|
|
|
id: root
|
2021-11-01 18:25:46 +01:00
|
|
|
anchors.fill: parent
|
|
|
|
property bool loops: Wallpaper.loops
|
2021-12-11 17:05:41 +01:00
|
|
|
property bool isPlaying: Wallpaper.isPlaying
|
2022-05-06 14:52:23 +02:00
|
|
|
property string fillMode: Wallpaper.fillMode
|
|
|
|
onFillModeChanged: {
|
|
|
|
// Convert Web based video modes to the limited Qt fillModes
|
2023-02-02 15:25:26 +01:00
|
|
|
if (fillMode === "cover" || fillMode === "stretch" || fillMode === "contain") {
|
|
|
|
return vo.fillMode = VideoOutput.Stretch;
|
2022-05-06 14:52:23 +02:00
|
|
|
}
|
|
|
|
if (fillMode === "fill") {
|
2023-02-02 15:25:26 +01:00
|
|
|
return vo.fillMode = VideoOutput.PreserveAspectFit;
|
2022-05-06 14:52:23 +02:00
|
|
|
}
|
|
|
|
if (fillMode === "scale_down") {
|
2023-02-02 15:25:26 +01:00
|
|
|
return vo.fillMode = VideoOutput.PreserveAspectCrop;
|
2022-05-06 14:52:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-11 17:05:41 +01:00
|
|
|
onIsPlayingChanged: isPlaying ? mediaPlayer.play() : mediaPlayer.pause()
|
2021-11-11 18:08:24 +01:00
|
|
|
property bool isWindows: Qt.platform.os === "windows"
|
2023-01-22 16:28:41 +01:00
|
|
|
property bool ready: false
|
2021-11-01 18:25:46 +01:00
|
|
|
|
2022-04-04 18:06:43 +02:00
|
|
|
property string source: Wallpaper.projectSourceFileAbsolute
|
|
|
|
onSourceChanged: {
|
|
|
|
// Qt 6.3 workaround
|
2023-02-02 15:25:26 +01:00
|
|
|
mediaPlayer.stop();
|
|
|
|
mediaPlayer.source = Qt.resolvedUrl(root.source);
|
|
|
|
mediaPlayer.play();
|
2022-04-04 18:06:43 +02:00
|
|
|
}
|
|
|
|
|
2021-11-01 18:25:46 +01:00
|
|
|
MediaPlayer {
|
|
|
|
id: mediaPlayer
|
2023-02-02 15:25:26 +01:00
|
|
|
onPlaybackStateChanged: {
|
|
|
|
if (mediaPlayer.playbackState == MediaPlayer.PlayingState) {
|
|
|
|
root.ready = true;
|
|
|
|
}
|
|
|
|
}
|
2022-02-20 17:57:00 +01:00
|
|
|
loops: root.loops ? MediaPlayer.Infinite : 1
|
2021-11-01 18:25:46 +01:00
|
|
|
videoOutput: vo
|
|
|
|
audioOutput: ao
|
|
|
|
}
|
|
|
|
VideoOutput {
|
|
|
|
id: vo
|
|
|
|
anchors.fill: parent
|
2021-09-10 12:45:54 +02:00
|
|
|
}
|
2021-11-01 18:25:46 +01:00
|
|
|
|
|
|
|
AudioOutput {
|
|
|
|
id: ao
|
|
|
|
volume: Wallpaper.volume
|
2021-12-18 12:40:25 +01:00
|
|
|
muted: Wallpaper.muted
|
|
|
|
}
|
|
|
|
|
|
|
|
Connections {
|
|
|
|
function onFillModeChanged(fillMode) {
|
2022-05-06 14:52:23 +02:00
|
|
|
if (fillMode === "stretch") {
|
2023-02-02 15:25:26 +01:00
|
|
|
vo.fillMode = VideoOutput.Stretch;
|
|
|
|
return;
|
2021-12-18 12:40:25 +01:00
|
|
|
}
|
2022-05-06 14:52:23 +02:00
|
|
|
if (fillMode === "fill") {
|
2023-02-02 15:25:26 +01:00
|
|
|
vo.fillMode = VideoOutput.PreserveAspectFit;
|
|
|
|
return;
|
2021-12-18 12:40:25 +01:00
|
|
|
}
|
2023-02-02 15:25:26 +01:00
|
|
|
if (fillMode === "contain" || fillMode === "cover" || fillMode === "scale-down") {
|
|
|
|
vo.fillMode = VideoOutput.PreserveAspectCrop;
|
2021-12-18 12:40:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onCurrentTimeChanged(currentTime) {
|
2023-02-02 15:25:26 +01:00
|
|
|
mediaPlayer.position = currentTime * mediaPlayer.duration;
|
2021-12-18 12:40:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
target: Wallpaper
|
2021-07-15 12:07:39 +02:00
|
|
|
}
|
|
|
|
}
|