Skip to content

Commit

Permalink
Merge pull request #6 from esdete2/4-fix-audio-loaded-event
Browse files Browse the repository at this point in the history
Fix: set preload attribute of audio to `metadata` to fix loading in safari
  • Loading branch information
esdete2 authored Jun 1, 2024
2 parents 485e4e3 + eff10bd commit 2099d6a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Mirt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,11 @@ const Mirt = ({
}

if (file && file.type.startsWith('audio')) {
const source = URL.createObjectURL(file);
setAudio(new Audio(source));
const audio = new Audio();
audio.preload = 'metadata';
audio.src = URL.createObjectURL(file);

setAudio(audio);
} else {
onError && onError(new Error('Invalid file type'));
}
Expand Down Expand Up @@ -185,7 +188,7 @@ const Mirt = ({
onAudioLoaded(audio);
}

audio.removeEventListener('canplaythrough', handleLoadedAudio);
audio.removeEventListener('loadedmetadata', handleLoadedAudio);
setInitialValues();
};

Expand Down

0 comments on commit 2099d6a

Please sign in to comment.