Created
February 9, 2012 10:34
-
-
Save mataspetrikas/1779157 to your computer and use it in GitHub Desktop.
Create a SoundCloud widget from the id passed in the url
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
// 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