Javascript Soundcloud API中出错:无法读取属性';substr';空的

Javascript Soundcloud API中出错:无法读取属性';substr';空的,javascript,soundcloud,Javascript,Soundcloud,我正在尝试使用SoundCloudAPI(本地)编写一个小部件 这是我的密码: <!DOCTYPE html> <html> <head> <title>Soundcloud musics</title> </head> <body> <h1>Soundcloud musics</h1> <iframe id="iframe" class="iframe" width

我正在尝试使用SoundCloudAPI(本地)编写一个小部件

这是我的密码:

<!DOCTYPE html>
<html>
<head>
<title>Soundcloud musics</title>
</head>
<body>
<h1>Soundcloud musics</h1>
<iframe id="iframe"
    class="iframe"
    width="100%"
    height="465"
    scrolling="no"
    frameborder="no">
</iframe>
<script src="api.js"></script>
<script>
    var player;
    player = SC.Widget(document.getElementById('iframe'));
    console.debug(player);
    player.load('https://soundcloud.com/somesong', null);
</script>
</body>
</html>
我已经将soundcloud的最小化api代码输入到js美化器中,以便跟踪错误。代码如下:


我做错什么了吗?问题似乎来自SC.Widget()函数…

您需要更改以下几项:

使用播放器小部件api url和属性在iframe中定义
src

示例


(JQuery版本)

我不知道你所说的本地
是什么意思;soundcloud api通过从他们的站点流式播放曲目来工作。@l'l我的意思是我是从我的计算机而不是从服务器执行此页面。我不知道它是否有用,所以我宁愿说出来。。但显然不是正确的方法。很抱歉,我想访问小部件触发的事件等。我不想只在我的页面上播放音乐。将Jquery添加到我的页面并不能解决任何问题,我仍然没有完全遵循您的意图;您指的是哪些事件。例如,歌曲结束时的事件。正如这里描述的:@I'L'I ok伙计,它很有效,非常感谢。但是代码中有一个错误,在ready事件的回调之外调用seekTo()和toggle()。我已经纠正了这一点,但是seekTo()方法仍然不起作用……太好了,很高兴代码起作用了。。。关于搜索-是的,我尝试了一些东西,但忘了删除它-谢谢你提醒我:)
Uncaught TypeError: Cannot read property 'substr' of null
E @ api.js:204
d @ api.js:328
n.exports.v @ api.js:326
(anonymous function) @ index.html:21
<iframe id="iframe"
     class="iframe"
     width="100%"
     height="465"
     scrolling="no"
     frameborder="no"
     src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/76067623&amp;auto_play=false&amp;hide_related=true&amp;show_comments=true&amp;show_user=true&amp;show_reposts=false&amp;visual=true">
</iframe>
<script type="text/javascript">
(function(){
    var iframeElement = document.getElementById('iframe');
    var widget = SC.Widget(iframeElement);
    widget.bind(SC.Widget.Events.READY, function () {
        console.log('Ready');
        widget.bind(SC.Widget.Events.PLAY, function () {
            widget.getCurrentSound(function (sound) {
                console.log(sound.title);
            });
        });
           widget.bind(SC.Widget.Events.FINISH, function () {
               console.log('Finished');
        });
    });
}());
</script>