From 12df436e1598634d1b431da85b546a6f256ed81e Mon Sep 17 00:00:00 2001 From: Vanilagy <1696106+Vanilagy@users.noreply.github.com> Date: Sun, 10 Aug 2025 19:26:58 +0200 Subject: [PATCH] Add more graceful handling of suspended AudioContext to media player example --- examples/media-player/media-player.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/examples/media-player/media-player.ts b/examples/media-player/media-player.ts index 212b9b8..a7a79a6 100644 --- a/examples/media-player/media-player.ts +++ b/examples/media-player/media-player.ts @@ -166,7 +166,11 @@ const initMediaPlayer = async (file: File) => { fileLoaded = true; await startVideoIterator(); - await play(); + + if (audioContext.state === 'running') { + // Start playback automatically if the audio context permits + await play(); + } playerContainer.style.display = ''; @@ -330,6 +334,10 @@ const getPlaybackTime = () => { }; const play = async () => { + if (audioContext!.state === 'suspended') { + await audioContext!.resume(); + } + if (getPlaybackTime() === totalDuration) { // If we're at the end, let's snap back to the start playbackTimeAtStart = 0;