1

我在网站上搜索了可能为我解答这个问题的提示。这可能是 SoundCloud 特有的,或者这可能只是一个 JS 新手问题。我尽我所能搜索 StackOverflow,试图自己解决这个问题,但我很困惑。我敢肯定,对于比我更有经验的人来说,这是显而易见且容易的事情。

我正在尝试构建一个测试网页,该网页使用 SoundCloud 的 JS API 来播放曲目,而不使用他们的播放器 UI。我查看了他们的文档,找到了他们的示例(此处:http ://connect.soundcloud.com/examples/streaming.html ),并尝试使其与曲目和我的客户 ID 一起使用,但无济于事。

这是我的基本 HTML 页面,基于上面链接的示例:

<!DOCTYPE html>
<html>
<head>
    <title>Some Page</title>
</head>
<body>
    <script src="//connect.soundcloud.com/sdk.js"></script>
    <script>
      SC.initialize({
       client_id: "MY_CLIENT_ID"
     });

      $("#stream").live("click", function(){
        SC.stream("/tracks/47101735", {autoPlay: true});
      });
    </script>

    <input type="button" href="#" id="stream" value="Stream It Again, Sam" />
</body>
</html>

在浏览器的错误控制台中,当我加载此页面时,我收到错误:ReferenceError: Can't find variable: $。回想一下我对 JS 和 Web 编程的所有了解(几乎什么都没有),我认为 SoundCloud SDK 没有被加载。我尝试了很多方法来解析“sdk.js”文件的路径,例如将 http:// 绝对路径添加到其托管的 JS 文件或将其指向 SDK 的本地副本。似乎没有什么不同。

有人对我有提示或解决方案吗?更好地搜索我可能找不到的现有答案的语法?非常感谢。

4

1 回答 1

3

sdk.js 文件正在成功下载..

$ 代表 jquery 对象那里.. 所以,我们需要包括 jquery.js 以及..

<!DOCTYPE html>
<html>
<head>
    <title>Some Page</title>
    <script src="http://code.jquery.com/jquery-1.7.2.min.js" type="text/javascript">    </script>
</head>
<body>
<script src="//connect.soundcloud.com/sdk.js"></script>
<script>
  SC.initialize({
   client_id: "MY_CLIENT_ID"
 });

  $("#stream").live("click", function(){
    SC.stream("/tracks/47101735", {autoPlay: true});
  });
</script>

<input type="button" href="#" id="stream" value="Stream It Again, Sam" />

于 2012-07-19T02:36:53.707 回答