goldfire / howler.js

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

Creating multiple Howl objects on the same file will fire only once #1317

Open butlimous opened 4 years ago

butlimous commented 4 years ago

Hi

I don't know if this is by design or it is a bug but I feel it does not make sense currently.

If I create a new sound object using the following code:

const addSound = () => {
  const obj = new Howl({ src: 'sound.mp3' });
  obj.on('load', () => {
      console.log('load success');
  });
  obj.on('loaderror', () => {
      throw new Error('load fail')
      console.log('load fail');
  });
}
addSound();
addSound();

The first function call would fire the success event but the second one does nothing. It's just stuck without any kind of response.

I know that it does not make sense to create multiple objects on the same file but I wasn't aware of the problem because no event fired and so no error to catch and I spent some good time figuring out what is going on. So I feel this should trigger the loaderror event if it's something wrong to do or load if it's ok. Thanks!

tonmoycsedu commented 4 years ago

facing the same problem. any solution?

var crickets = []
for(i=0;i<4;i++){
    crickets.push(new Howl({
    src: ["{{ url_for('static', filename='sounds/single_cricket.mp3')}}"],
    volume:0.5
    }))
}
$("#scatter_button").on("click",function(){
  for(i=0;i<crickets.length;i++){
    cricket = crickets[i]
    cricket.play() 
        x = Math.random() * 2 - 1; 
        y = Math.random() * 2 - 1; 
        // console.log(x,y)
        cricket.pos(x,y,-0.5)   
  }     
})

I am trying to create multiple Cricket sound from a single Cricket sound source., and then positioning them randomly on the 3D sound plane. But, I can hear only one sound.

butlimous commented 4 years ago

You should be able to just directly play the file again when needed even if it's already playing. You should not load it again.