I was just starting to learn javascript, and as a first attempt, I would like to create a custom audio player that uses the soundcloud api as a source for music.
So far this is what I created:
<!DOCTYPE html> <html> <head> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script src="http://connect.soundcloud.com/sdk.js"></script> <script> window.onload = function() { SC.initialize({ client_id: '10e27db0dacd00954d7160b4c092a6e2' //Demo ID }); SC.stream("/tracks/75868018", function(sound){ $("audio-test").attr("src", sound.uri); }); }; </script> </head> <body> <audio id="audio-test" controls></audio> </body> </html>
Ok, got it. The problem was that .stream () is designed to deliver a pre-packaged player deployed by the .play () function.
If you use SC.get()instead, you really get access to the properties of the track and can insert it into the sound tag. See my code: http://jsfiddle.net/LpzpK/6/
SC.get()
- : 401, "". , .
, , API soundcloud URI, . sound.uri.
sound.uri
<audio> - , src URI . , ID
<audio>
src
SC.stream("/tracks/293", function(sound){ $("[audio_id]").attr("src", sound.uri); });
[audio_id] , . , - / , , , . , !
[audio_id]