Created
December 22, 2011 11:10
-
-
Save mataspetrikas/1509934 to your computer and use it in GitHub Desktop.
control next and previous tracks in the soundcloud custom player
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That's what I needed, thank you!