johndyer/mediaelement — Issue #338: MediaElement.js keep dispatching progress event from previous loaded media
Author: dadaxr
Created: 2011-12-21 10:48:11+00:00
State: open

I use mediaelement.js API for playing mp3 files. I have a song list and when I select one, I execute the following code :

media_element.setSrc(media_url);
media_element.load();
media_element.play();

Everything is working fine : I have a listener which is getting back the progress value :

media.addEventListener('progress', function(e){
var progress = player_get_progress(e,media);
console.log(progress); //trace 0,01 ... 0,02, ... 0,56 ... 1 !
});

I use this progress value for setting a html div's width (which is representing the buffering progress)

However when I click on another song, and that the first one has not finished to load, the second song start to load and I'm getting two progress values :

Example :

Song 1 => Click => progress : 0,1; 0,2; 0;3 Song 2 => Click ( and song 1 is not totally loaded ) => progress : 0,4; 0,1 ; 0,5 ; 0,2; 0,6; 0,3 ... etc

The same happen with many song parallely loaded . I tried to do a media.stop() before loading a new song but this is crashing the actionscript script...

bellow the code I tried to :

function play_media(media_url)
{
if(!media_element.paused)
{
media_element.pause();
//media_element.stop(); //crashing line
}
media_element.setSrc(media_url);
media_element.load();
media_element.play();
}

If you want to know what this function do :

player_get_progress(e,media);

I copy/paste the code from the mediaelement-and-player.js file , function : setProgressRail This function is beside setting the progress bar width from the built-in html media player

So ... Am I doing something wrong or is there a bug with the actionscript code that does not stop the loading of the song when a new one is loaded ???

hope you could help :)