【问题标题】:stream soundcloud track with JavaScript doesn't work使用 JavaScript 流式传输 soundcloud 轨道不起作用
【发布时间】:2015-04-07 21:49:26
【问题描述】:

你们会在这方面帮助我吗? : 我想从我的 soundcloud 曲目中制作一个列表,并在我使用 JavaScript 单击它时播放任何曲目,但它不适用于我:(

html文件

<script src="//connect.soundcloud.com/sdk.js"></script> 
<body>
    <ol id="track-list"></ol> 
</body>

js文件:

function PlayIt(ID){
    SC.stream("/tracks"+ID, function(sound){
     soundManager.stopAll();
     sound.play();
    });

}



SC.initialize({
      client_id: "YOUR_CLIENT_ID",
      redirect_uri: "http://example.com/callback.html",
  });

/**
Once that's done you are all set and ready to call the SoundCloud API. 
**/



/**
Call to the SoundCloud API. 
Retrieves list of tracks, and displays a list with links to the tracks showing 'tracktitle' and 'track duration'
**/

  var userId = 39090345; // user_id of Prutsonic

  SC.get("/tracks", {
      user_id: userId,
      limit: 100
  }, function (tracks) {

      var tmp = '';

      for (var i = 0; i < tracks.length; i++) {
        var TrackId=tracks[i].id;
          tmp = '<a href="#" onclick="PlayIt('+TrackId +')">' + tracks[i].title + ' - ' + tracks[i].duration + '</a>';

          $("<li/>").html(tmp).appendTo("#track-list");
      }

  });

您也可以在这里查看: http://jsfiddle.net/26pHX/96/

*这不是我的代码,但我努力让它变得更好

【问题讨论】:

    标签: javascript audio stream soundcloud


    【解决方案1】:

    看来您的代码中需要一个客户端 ID。您还需要一个重定向网址。我不确定这必然会发生什么,但我现在会尝试为其提供一个随机页面,因为他们的示例页面似乎没有什么特别之处。

    【讨论】:

      【解决方案2】:

      我发现这部分是问题:

      onclick="PlayIt('+TrackId +')

      相反,我使用 document.createElement('a') 制作了标签,然后我使用 (element).setAttribute('the_attribute','the_value'); 设置了它的属性。 一切正常。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-08-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多