1

I'm playing audio using the HTML audio player, and I've noticed that Safari is very slow to load and play the audio (about 5.5 seconds vs. .5 seconds for Chrome). Is there a way I can speed this up?

I've seen discussion (like here and here) about AudioContext as a possible solution, but I'm not clear on how AudioContext works--what would be the code to implement it? I want to keep the html audio tag, bc of its features.

[EDIT: Actually, having seen the way that safari changes the look of the audio player on different devices, I'm ok just playing the audio through javascript (audio.play()...). But it's still slow on safari either way.]

(I'm using angular, but I don't think that makes a difference for this purpose)

relevant code:

html:

 <audio controls id="audioId" (loadeddata)="onCanPlayFunction()" >
    <source src="{{coolAudio}}" type="audio/mpeg">
    Your browser does not support the audio player.
  </audio>

typescript:

playAudio() {
   this.coolAudio = 'audioFile.m4a'
}

onCanPlayFunction() {
  let audioElement = <HTMLVideoElement>document.getElementById('audioId');
  audioElement.play()
}
SeanRtS
  • 1,005
  • 1
  • 13
  • 31

0 Answers0