Skip to content

Instantly share code, notes, and snippets.

@mataspetrikas
Created November 18, 2010 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mataspetrikas/704837 to your computer and use it in GitHub Desktop.
Save mataspetrikas/704837 to your computer and use it in GitHub Desktop.
Polling for track positon with SoundCloud JS api
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