mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-27 02:43:48 +02:00
Add more graceful handling of suspended AudioContext to media player example
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user