Created
September 23, 2015 20:14
-
-
Save rafaell-lycan/9ed45009b92cb0aff4f4 to your computer and use it in GitHub Desktop.
A easy way to play songs using SoundCloud API
This file contains hidden or 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
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