From 51640f1672174c3067e6a7d48c8d0fafba8bd50c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Wed, 6 Jul 2022 21:09:58 +0200 Subject: [PATCH] synchronize seeks --- src/Player.svelte | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/Player.svelte b/src/Player.svelte index f636549..dd748bc 100644 --- a/src/Player.svelte +++ b/src/Player.svelte @@ -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"); + } + }, }, }); }