Skip to content

Instantly share code, notes, and snippets.

@mataspetrikas
Created February 9, 2012 10:34
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/1779157 to your computer and use it in GitHub Desktop.
Save mataspetrikas/1779157 to your computer and use it in GitHub Desktop.
Create a SoundCloud widget from the id passed in the url
// You will need jQuery to be available on your page
// the widget will be written into HTML element with id="player" or some other DOM element that $playerContainer will point to
// the url format should be http://example.com/mytracks?track_id=3223234 or http://example.com/mytracks?track_url=http://soundcloud.com/matas/hobnotropic
$(function(){
var params = location.search,
trackId = (params.match(/track_id=(\d+)/)||[])[1],
trackUrl = (params.match(/track_url=(.+?)(&|$)/)||[])[1],
$playerContainer = $('#player');
if (trackId) {
trackUrl = 'http://api.soundcloud.com/tracks/' + trackId;
}
if (trackUrl) {
$.getJSON('http://soundcloud.com/oembed?format=js&url=' + trackUrl + '&iframe=true&auto_play=true&callback=?', function(response){
$playerContainer.html(response.html);
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment