synchronize seeks

master
Tomáš Mládek 2022-07-06 21:09:58 +02:00
parent 5725ace006
commit 51640f1672
1 changed files with 20 additions and 0 deletions

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() { async function init() {
const currentResult = await fetch("grid.php"); const currentResult = await fetch("grid.php");
if (!currentResult.ok) { if (!currentResult.ok) {
@ -51,6 +59,12 @@
onReady: () => { onReady: () => {
videoReady = true; videoReady = true;
}, },
onStateChange: (ev) => {
// Paused
if (ev.data == 2) {
synchronize("audio");
}
},
}, },
}); });
@ -65,6 +79,12 @@
onReady: () => { onReady: () => {
audioReady = true; audioReady = true;
}, },
onStateChange: (ev) => {
// Paused
if (ev.data == 2) {
synchronize("video");
}
},
}, },
}); });
} }