synchronize seeks

This commit is contained in:
Tomáš Mládek 2022-07-06 21:09:58 +02:00
parent 5725ace006
commit 51640f1672

View file

@ -30,6 +30,14 @@
}
}
function synchronize(what) {
if (what == "audio") {
audioPlayer.seekTo(videoPlayer.getCurrentTime(), true);
} else {
videoPlayer.seekTo(audioPlayer.getCurrentTime(), true);
}
}
async function init() {
const currentResult = await fetch("grid.php");
if (!currentResult.ok) {
@ -51,6 +59,12 @@
onReady: () => {
videoReady = true;
},
onStateChange: (ev) => {
// Paused
if (ev.data == 2) {
synchronize("audio");
}
},
},
});
@ -65,6 +79,12 @@
onReady: () => {
audioReady = true;
},
onStateChange: (ev) => {
// Paused
if (ev.data == 2) {
synchronize("video");
}
},
},
});
}