Hi guys,
The following code play music on the playlist when click or touch. But the it won’t stop when the last song end. How do I make it stop.
HTML:[code]
- Song1
- Song2
var loadTracks = function(url) {
if (audio) audio.remove();
var index = 0;
audio = document.createElement('audio');
source.insertBefore(audio, source.childNodes[0]);
var tag = source.getElementsByTagName('audio'),
tags = source.getElementsByTagName('audio').length;
if ( tags > 1 ) {
source.removeChild(tag[1]);
}
audio.src = path + tracks[url].file;
audio.addEventListener('canplay', function(e) {
audio.play();
}, false);
audio.addEventListener('ended', function(e) {
audio.removeEventListener('canplay', arguments.callee, false);
if ((index + 1) < myLis.length) {
index++;
loadTracks(index);
} else {
return;
}
}, false);
};
[/code]