1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-11-09 20:42:47 +01:00
ScreenPlay/ScreenPlayWallpaper/qml/MultimediaView.qml

80 lines
2.2 KiB
QML
Raw Normal View History

2021-10-08 10:14:11 +02:00
import QtQuick
2021-07-15 12:07:39 +02:00
import QtMultimedia
import ScreenPlayWallpaper
2021-07-15 12:07:39 +02:00
Item {
2021-09-10 11:36:47 +02:00
id: root
anchors.fill: parent
property bool loops: Wallpaper.loops
property bool isPlaying: Wallpaper.isPlaying
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;
}
if (fillMode === "fill") {
2023-02-02 15:25:26 +01:00
return vo.fillMode = VideoOutput.PreserveAspectFit;
}
if (fillMode === "scale_down") {
2023-02-02 15:25:26 +01:00
return vo.fillMode = VideoOutput.PreserveAspectCrop;
}
}
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
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();
}
MediaPlayer {
id: mediaPlayer
2023-02-02 15:25:26 +01:00
onPlaybackStateChanged: {
if (mediaPlayer.playbackState == MediaPlayer.PlayingState) {
root.ready = true;
}
}
loops: root.loops ? MediaPlayer.Infinite : 1
videoOutput: vo
audioOutput: ao
}
VideoOutput {
id: vo
anchors.fill: parent
2021-09-10 12:45:54 +02:00
}
AudioOutput {
id: ao
volume: Wallpaper.volume
muted: Wallpaper.muted
}
Connections {
function onFillModeChanged(fillMode) {
if (fillMode === "stretch") {
2023-02-02 15:25:26 +01:00
vo.fillMode = VideoOutput.Stretch;
return;
}
if (fillMode === "fill") {
2023-02-02 15:25:26 +01:00
vo.fillMode = VideoOutput.PreserveAspectFit;
return;
}
2023-02-02 15:25:26 +01:00
if (fillMode === "contain" || fillMode === "cover" || fillMode === "scale-down") {
vo.fillMode = VideoOutput.PreserveAspectCrop;
}
}
function onCurrentTimeChanged(currentTime) {
2023-02-02 15:25:26 +01:00
mediaPlayer.position = currentTime * mediaPlayer.duration;
}
target: Wallpaper
2021-07-15 12:07:39 +02:00
}
}