【问题标题】:How to play song using SoundCloud API如何使用 SoundCloud API 播放歌曲
【发布时间】:2014-08-12 08:03:34
【问题描述】:

我正在尝试制作与 SoundCloud 一起使用的音乐播放器。所以我有播放、下一个、上一个等按钮。我做了这样的功能:

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

所以当按钮是播放器时它会播放歌曲:

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

但它不起作用。任何想法? 这是demo

【问题讨论】:

    标签: javascript jquery api soundcloud


    【解决方案1】:

    1º - 将 JS 文件放在头部。使用 JSfiddle 上的“外部资源”。

    2º - 将 var sound = [...] 放在 SC.steam 之前。

    是吗。

    演示: http://jsfiddle.net/don/zcN7G/3/

    【讨论】:

    • 非常感谢。你能解释一下声音变量的作用吗?我只是不明白。但它的工作和感谢。
    • 你正在使用sound.play()播放音乐,你需要把可变的声音来决定播放什么。
    【解决方案2】:

    根据上面的@lago,让我提供一个完整的短代码,这样你就可以自己做实验了;-)

    <!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 指南here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-07
      • 1970-01-01
      • 1970-01-01
      • 2013-03-21
      • 1970-01-01
      • 2016-08-24
      • 2013-09-01
      • 1970-01-01
      相关资源
      最近更新 更多