How to load and play an audio file simultaneously using Javascript

1.6k views Asked by At

Just like you can start playing a YouTube video as soon as some part of it has been loaded, I want to be able to play audio files. I'm using Howler.js.

var song = new Howl({
  src: mySrc,
  volume: myVol
});

The problem is whole audio file has to be loaded before it starts playing. This can be an issue for users with slow networks. How can I achieve a situation where the audio starts playing immediately some part of it is loaded, with or without Howler.js?

1

There are 1 answers

0
James Simpson On BEST ANSWER

Howler.js defaults to Web Audio API, which must download the full audio file over XHR before beginning playback. However, if you force HTML5 Audio it will begin playing as soon as it is able, even if the full file has downloaded:

var song = new Howl({
  src: mySrc,
  volume: myVol,
  html5: true
});