Hi George,
I’ve got this working!
It’s not time-synced, but the code checks every 100ms if a (or multiple) video is buffering. If so, the non-buffering videos are paused. If none of the videos is buffering anymore, all the videos start playing again.
I’m not a script-guru so probably this can be scripted more efficiently. Please let me know if this can/ should be done differently. Hopefully this script will help anyone in the future.
I’ve got this on the ‘show’-script:
// ======================================================
// 4 different videos of bandmembers who are playing a song together
const Videoplayer_Drum = symbol.nodes.Videoplayer_Drum;
const Videoplayer_Sous = symbol.nodes.Videoplayer_Sous;
const Videoplayer_Left = symbol.nodes.Videoplayer_Left;
const Videoplayer_Right = symbol.nodes.Videoplayer_Right;
// ======================================================
// videoStates: saves the current state of the videos
// --------- States ----------
// -1 = not played yet
// 0 = buffering
// 1 = playing
// 2 = paused
// ------ Array layout ------
// videoStates[0] = Trom Video
// videoStates[1] = Sous Video
// videoStates[2] = Left Video
// videoStates[3] = Right video
// ---------- Notes ---------
// Default all videos are set to -1 (because they are not playing yet)
// ======================================================
let videoStates = [-1, -1, -1, -1];
let videoPlayers = [Videoplayer_Drum, Videoplayer_Sous, Videoplayer_Left, Videoplayer_Right];
// Determine video states
Videoplayer_Drum.on("video:buffering", () => { videoStates[0] = 0; });
Videoplayer_Drum.on("video:playing", () => { videoStates[0] = 1; });
Videoplayer_Drum.on("video:paused", () => { videoStates[0] = 2; });
Videoplayer_Sous.on("video:buffering", () => { videoStates[1] = 0; });
Videoplayer_Sous.on("video:playing", () => { videoStates[1] = 1; });
Videoplayer_Sous.on("video:paused", () => { videoStates[1] = 2; });
Videoplayer_Left.on("video:buffering", () => { videoStates[2] = 0; });
Videoplayer_Left.on("video:playing", () => { videoStates[2] = 1; });
Videoplayer_Left.on("video:paused", () => { videoStates[2] = 2; });
Videoplayer_Right.on("video:buffering", () => { videoStates[3] = 0; });
Videoplayer_Right.on("video:playing", () => { videoStates[3] = 1; });
Videoplayer_Right.on("video:paused", () => { videoStates[3] = 2; });
// Check every 100ms if a video is buffering
Z.every(100, function() {
// Check the array for playstate 0 (= buffering)
if(videoStates.indexOf(0) > -1) {
// At least one video is buffering: pause all videos
pausePlayingVideo(videoStates);
}
else {
// No video is buffering anymore: play all videos
playAllVideos(videoStates);
}
});
function pausePlayingVideo(videoStates) {
// Pause videos that currently are playing because there is a buffering video
console.log("==============");
console.log("At least one video is buffering");
// Loop through all videoStates
for(let i=0;i<videoStates.length;i++) {
// If a video is playing...
if(videoStates[i] === 1) {
//...pause it
videoPlayers[i].nodes.control.pause();
console.log("Video #" + i + " was playing and has been paused");
}
}
}
function playAllVideos(videoStates) {
var videosToStart = [];
console.log("===============");
console.log("No videos buffering anymore; start the videos");
// Loop through all videoStates
for(let i=0;i<videoStates.length;i++) {
// If a video is paused...
if(videoStates[i] === 2) {
// ...push it to array
videosToStart.push[i];
}
}
// To prevent auto-starting videos when all videos are paused (which they are when the Zappar-image is not-seen),
// check if 3 or less videos are paused (which always is true when a (or multiple) video is buffering)
if(videosToStart.length <= (videoPlayers.length-1)) {
// Loop throught all videos to start...
for(let i=0;i<videosToStart.length;i++) {
// ...and start them
videoPlayers[videosToStart[i]].nodes.control.start();
console.log("Video #" + i + " was paused and is playing now");
}
}
}