goldfire / howler.js

Javascript audio library for the modern web.
https://howlerjs.com
MIT License
23.99k stars 2.23k forks source link

Can Howler handle lazy loading on mp3 audios? #1213

Open inglesuniversal opened 5 years ago

inglesuniversal commented 5 years ago

if I have an educational webpage (single webpage) with about 80 mp3 audios to be played throughout the lesson... How can I handle the loading or lazy loading of those files without affecting the payload at launch time or initial page load?

What I mean is not to preload all those file, but load them as they are needed or clicked by the user.

Best regards

skepticalmartyr commented 5 years ago

Hello There - It sounds like what you want is to not preload the audio. You can handle this when you create the howl by setting "preload" to false. Then when you are ready to load the sound, you just call load() on the howl before playing it. Simple example:

var myHowl = new Howl({
      src: "file.mp3",
      preload: false
});

//sometime later....

myHowl.load();
myHowl.play();
inglesuniversal commented 5 years ago

Worked as expected. Have an awesome week!

inglesuniversal commented 5 years ago

Now, if I have several play buttons on the same page... How do I stop the last play/pause if I press a different audio button? Do I have to assign an ID to every audio file or radio station?

goodyInt commented 5 years ago

thanks for the tip