I am making a music player, by SoundCloud API and SoundManager 2. There is a list of songs that when each one is clicked, that starts playing. But the problem if one song is playing, and I choose another song, the old one does not stop, it keeps playing. So both songs play at the same time. even pressing the same song couple if times, cause the same song plays couple of times. How can I stop the previous song and play the current one?
DEMO http://jsfiddle.net/danials/anU2h/
My code to stream a song by SoundCloud:
SC.stream("/tracks/" + id, function (sound) {
sound.play({
whileplaying: function () {
$(".seekLoad").css('width', ((sound.position / sound.duration) * 100) + '%');
$(".secPlayed").text(converter(sound.position));
},
});
});
To prove that songs are playing all together, I made a seek bad with an element that shows the seconds of current playing song. when a two songs are playing at the same time, the seek bar loaded value and time value keep blinking to show the values of both songs. Just to show the overlap.
Any idea to play one song at the time, and stop whatever was playing?