jqueryajaxsoundmanager2

soundManager loaded from ajax plays previously selected song


I have a page where different music albums are showed, and I'm initalizing a soundManager in it. When an album is clicked, a view is loaded in ajax with some mp3 links in it. This works fine and the music plays. (I've based my script on: http://www.schillmania.com/projects/soundmanager2/demo/mp3-player-button/basic.html )

When another album is clicked, I'm calling

soundManager.stopAll();

to stop any currently playing track. This stops the track currently playing, but when I click on a track in a newly opened "album view", the previously selected track, plays on top of the newly clicked one.

I've tried using soundManager.unload(); and soundManager.destruct(); without success...

Any ideas?


Solution

  • Instead of:

    var basicMP3Player = null;
    
    soundManager.onready(function() {
      // soundManager.createSound() etc. may now be called
      basicMP3Player = new BasicMP3Player();
    });
    

    I used:

    if ( typeof basicMP3Player !== "undefined" && basicMP3Player) {
        basicMP3Player.destruct();
    } 
    else {
        var basicMP3Player = null;
    }
    
    soundManager.onready(function() {
      // soundManager.createSound() etc. may now be called
      basicMP3Player = new BasicMP3Player();
    });
    

    The problem is that now when I load another "album view", the config isn't loaded properly and the "playNext" or "autoPlay" attributes aren't working...