Why does Soundmanager 2 not fire onload event in f

2019-05-10 12:15发布

问题:

I am using Soundmanager 2 to play an mp3 audio stream. Somehow the onload event will not be fired in Firefox. In Safari and Chrom it worked well. When i set autoplay to true the stream will be played even in firefox, its just the onload events witch is not working.

soundManager.setup({
    url: '/static/soundmanager2/swf',
    flashVersion: 9,
    preferFlash: false,
    useHTML5Audio: true,
    onready: function() {
        var options = {
        id: 'channel-'+num,
        url: chan.url,
        stream: true,
        onload: function() { alert("loaded"); },
        volume: 50,
        autoPlay:true
        };
        this.SM = soundManager.createSound(options)
    }
});

回答1:

It's a problem with the documentation as it turns out. Remove the onload from the options and use the sound.load method.

Change your code to this:

var sound = soundManager.createSound(options);
sound.load( { 
  onload: function() { 
    alert('works'); 
  } 
});
this.SM = sound;