简体   繁体   中英

How to play song using SoundCloud API

I am trying to make a music player that works with SoundCloud. So I have buttons like play, next, prev. and I made functions like:

function playIt(){
 SC.stream("/tracks/293", function(sound){
   sound.play();
 });
}

So it plays song when the button is player:

<button onclick="playIt()">Play</button>

But it does not work. Any idea? Here is the demo

1º - Put the JS files in the head. Use the "External Resources" on JSfiddle.

2º - Put var sound = [...] before the SC.steam .

Is that.

Demo: http://jsfiddle.net/don/zcN7G/3/

According to @lago above, let me deliver a full short code, so you can do your own labs ;-)

<!DOCTYPE html>
<html>
<head>
<script src=http://connect.soundcloud.com/sdk.js></script>
<script>
SC.initialize({client_id:'your client_id goes here'});    
function p()
       {
       SC.stream
               (
              '/tracks/293',
               function(s)
                       {
                       s.play()
                       }
               )
       }
</script> 
</head>
<body>
<button onclick=p()>play</button>
</body>
</html>

API guide here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM