Skip to content

Commit 122219e

Browse files
committed
fix: videos not updating when day/night and order changes
Also when the order changes now it keeps playing the current video, if the current video is moved, the next one will be the one in the updated list
1 parent c6063d2 commit 122219e

3 files changed

Lines changed: 219 additions & 141 deletions

File tree

package/contents/ui/VideoPlayer.qml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import QtQuick
22
import QtMultimedia
33
import Qt5Compat.GraphicalEffects
4+
import "code/utils.js" as Utils
5+
import "code/enum.js" as Enum
46

57
Item {
68
id: root
9+
property var playerSource: Utils.createVideo("")
710
property real volume: 1.0
811
property int actualDuration: player.duration / playbackRate
912
property int fillBlurRadius: 32

package/contents/ui/code/utils.js

Lines changed: 58 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,38 +19,73 @@ function parseCompat(cfgStr) {
1919
return videos;
2020
}
2121

22+
const Video = {
23+
filename: "",
24+
enabled: true,
25+
duration: 0,
26+
customDuration: 0,
27+
playbackRate: 0.0,
28+
alternativePlaybackRate: 0.0,
29+
loop: false,
30+
dayNightCycleAssignment: 0,
31+
};
32+
33+
/**
34+
* Create a new Video object with the given filename
35+
* @param {string} filename Video filename
36+
* @returns {Video} Video object with the given filename and default properties
37+
*/
2238
function createVideo(filename) {
23-
return {
24-
"filename": filename ?? "",
25-
"enabled": true,
26-
"duration": 0,
27-
"customDuration": 0,
28-
"playbackRate": 0.0,
29-
"alternativePlaybackRate": 0.0,
30-
"loop": false,
31-
"dayNightCycleAssignment": 0,
32-
};
39+
let video = Object.create(Video);
40+
video.filename = filename;
41+
return video;
42+
}
43+
/**
44+
* Get videos based on day/night cycle and enabled status
45+
* @param {boolean} dayNightCycleEnabled Whether day/night cycle is enabled
46+
* @param {boolean} isDay Whether it is day cycle
47+
* @param {string} videoUrls Video URLs configuration string
48+
* @returns {Array.<Video>} List of videos matching the criteria
49+
*/
50+
function getVideos(dayNightCycleEnabled, isDay, videoUrls) {
51+
console.log("getVideos()");
52+
if (dayNightCycleEnabled) {
53+
return parseCompat(videoUrls).filter(video => {
54+
const isDayCycle = video.dayNightCycleAssignment !== Enum.DayNightCycleAssignment.Night;
55+
const isNightCycle = video.dayNightCycleAssignment !== Enum.DayNightCycleAssignment.Day;
56+
return video.enabled && ((isDay && isDayCycle) || (!isDay && isNightCycle));
57+
});
58+
}
59+
60+
return parseCompat(videoUrls).filter(video => video.enabled);
3361
}
3462

3563
/**
36-
*
37-
* @param {String} filename File path
38-
* @param {Array} videosConfig Videos config
39-
* @returns {Object} Video properties
64+
* Find video index by filename
65+
* @param {string} filename Video filename to search for
66+
* @returns {int} Matching index, or -1 when not found
4067
*/
41-
function getVideoByFile(filename, videosConfig) {
42-
const video = videosConfig.find((video) => video.filename === filename);
43-
return video ?? createVideo("");
68+
function getVideoIndex(filename, videosConfig) {
69+
return videosConfig.findIndex(video => video.filename === filename);
4470
}
4571

4672
/**
47-
*
48-
* @param {int} index Video index
49-
* @param {Array} videosConfig Videos config
50-
* @returns {Object} Video properties
73+
* Get index of the last played video or -1 if not last video exists
74+
* if day/night cycle is enabled returns the last video for that cycle
75+
* @param {boolean} dayNightCycleEnabled Whether Day/night cycle is enabled
76+
* @param {boolean} isDay Whether is day cycle
77+
* @param {KConfigPropertyMap} configuration Wallpaper (WallpaperItem) configuration
78+
* @param {Array.<Video>} videosConfig List of videos with their properties
79+
* @returns {int} Video index or -1 if not found
5180
*/
52-
function getVideoByIndex(index, videosConfig) {
53-
return videosConfig.length > 0 ? videosConfig[index] : createVideo("");
81+
function getLastVideoIndex(dayNightCycleEnabled, isDay, configuration, videosConfig) {
82+
let lastVideo = "";
83+
if (dayNightCycleEnabled) {
84+
lastVideo = configuration[isDay ? "LastVideoDay" : "LastVideoNight"];
85+
} else {
86+
lastVideo = main.configuration.LastVideo;
87+
}
88+
return lastVideo === "" ? -1 : getVideoIndex(lastVideo, videosConfig);
5489
}
5590

5691
function dumpProps(obj) {
@@ -71,7 +106,6 @@ function shuffleArray(array) {
71106
array[i] = array[j];
72107
array[j] = temp;
73108
}
74-
return array;
75109
}
76110

77111
// https://stackoverflow.com/questions/28507619/how-to-create-delay-function-in-qml

0 commit comments

Comments
 (0)