public
Last active

control next and previous tracks in the soundcloud custom player

  • Download Gist
gistfile1.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
function getNextTrack(node) {
var $player = $(node).closest('.sc-player'),
$nextItem = $('.sc-trackslist li.active', $player).next('li');
// try to find the next track in other player
if(!$nextItem.length){
$nextItem = $player.nextAll('div.sc-player:first').find('.sc-trackslist li:first');
}
return $nextItem;
};
 
function getPrevTrack(node) {
var $player = $(node).closest('.sc-player'),
$prevItem = $('.sc-trackslist li.active', $player).prev('li');
// try to find the next track in other player
if(!$prevItem.length){
$prevItem = $player.prevAll('div.sc-player:first').find('.sc-trackslist li:last');
}
return $prevItem;
};
 
 
$(document).bind('onPlayerTrackFinish', function(event) {
var $nextItem = getNextTrack(event.target);
// init the next track but don't play :)
$nextItem.click().click();
});

That's what I needed, thank you!

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.