Created
November 18, 2010 10:21
-
-
Save mataspetrikas/704837 to your computer and use it in GitHub Desktop.
Polling for track positon with SoundCloud JS api
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
var positionInterval; | |
var startPolling = function(player) { | |
positionInterval = setInterval(function() { | |
var trackPosition = player.api_getTrackPosition(); | |
// do something with the trackPosition | |
}, 500); | |
}; | |
var stopPolling = function() { | |
clearInterval(positionInterval); | |
positionInterval = null; | |
}; | |
soundcloud.addEventListener('onMediaStart', function(player, data) { | |
startPolling(player); | |
}); | |
soundcloud.addEventListener('onMediaEnd', function(player, data) { | |
stopPolling(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment