mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-10-02 21:33:52 +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;
|
fileLoaded = true;
|
||||||
|
|
||||||
await startVideoIterator();
|
await startVideoIterator();
|
||||||
await play();
|
|
||||||
|
if (audioContext.state === 'running') {
|
||||||
|
// Start playback automatically if the audio context permits
|
||||||
|
await play();
|
||||||
|
}
|
||||||
|
|
||||||
playerContainer.style.display = '';
|
playerContainer.style.display = '';
|
||||||
|
|
||||||
@@ -330,6 +334,10 @@ const getPlaybackTime = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const play = async () => {
|
const play = async () => {
|
||||||
|
if (audioContext!.state === 'suspended') {
|
||||||
|
await audioContext!.resume();
|
||||||
|
}
|
||||||
|
|
||||||
if (getPlaybackTime() === totalDuration) {
|
if (getPlaybackTime() === totalDuration) {
|
||||||
// If we're at the end, let's snap back to the start
|
// If we're at the end, let's snap back to the start
|
||||||
playbackTimeAtStart = 0;
|
playbackTimeAtStart = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user