Skip to content

Instantly share code, notes, and snippets.

@rafaell-lycan
Created September 23, 2015 20:14
Show Gist options
  • Save rafaell-lycan/9ed45009b92cb0aff4f4 to your computer and use it in GitHub Desktop.
Save rafaell-lycan/9ed45009b92cb0aff4f4 to your computer and use it in GitHub Desktop.
A easy way to play songs using SoundCloud API
function Player () {
var API_URL = 'https://api.soundcloud.com/tracks/',
TOKEN = '10b1e7bf6b21e1a2a2971196b918833a';
var _player = document.createElement('audio');
var init = function (song) {
if(!song) return;
_player.src = API_URL + song + '/stream?client_id=' + TOKEN;
_player.play();
};
var play = function () {
if(_player.paused){
return _player.play();
}
return _player.pause();
};
return {
init : init,
play : play
}
}
var player = new Player();
player.init(43227597);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment