Add more graceful handling of suspended AudioContext to media player example

This commit is contained in:
Vanilagy
2025-08-10 19:26:58 +02:00
parent 56ae97f994
commit 12df436e15
+9 -1
View File
@@ -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;