Don Zola
Don Zola

Reputation: 140

With HTML5 SoundCloud player widget how do you programmatically skip to a different track without causing second unwanted track from playing?

I am using the HTML5 Soundcloud widget API to skip to another song on the sound finish event.

http://jsbin.com/axuzoj/4/edit

Unfortunately there appears to be a race condition bug in the finish event. The Soundcloud player ends up playing two songs simultaneously: the next song in the list and the song that was skipped to in the finish event handler.

var widget = null;
$(function() {
    var iframe = document.querySelector('#soundcloud_player iframe');
    widget = SC.Widget(iframe);        
    widget.bind(SC.Widget.Events.READY, function() {
        widget.bind(SC.Widget.Events.FINISH, function() {                
            widget.skip(3);
        });
    });
});

Is this a known bug?

Is there a better way to skip to a different track after a sound finishes?

Is there a way to turn off continuous play?

Adding a short wait before skipping in the finish event handler, gets around the problem. But doesn't seem like a good method.

window.setTimeout(function() { widget.skip(3); }, 300);

Another work around is to skip to a song just before the previous song finishes, using PLAY_PROGRESS event instead of on FINISH event.

widget.bind(SC.Widget.Events.READY, function() {
    widget.bind(SC.Widget.Events.PLAY_PROGRESS, function(obj) {
        if (obj.relativePosition > 0.999) {
            widget.pause();
            widget.skip(3);
        }
    });
});

Upvotes: 2

Views: 1083

Answers (1)

akovalev
akovalev

Reputation: 156

Yes, there was a race-condition bug which is fixed now.

Upvotes: 2

Related Questions