Skip to content

Instantly share code, notes, and snippets.

@mataspetrikas
Created December 22, 2011 11:10
Show Gist options
  • Save mataspetrikas/1509934 to your computer and use it in GitHub Desktop.
Save mataspetrikas/1509934 to your computer and use it in GitHub Desktop.
control next and previous tracks in the soundcloud custom player
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();
});
@baptistebriel
Copy link

That's what I needed, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment