Soundcloud API 中的错误:无法读取 null 的 属性 'substr'
Error in the Soundcloud API: Cannot read property 'substr' of null
我正在尝试使用 Soundcloud API(本地)编写 Widget。
这是我的代码:
<!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>
我从 运行 得到的错误是:
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
我已将 soundcloud 的最小化 api 代码输入到 js 美化器中,以便我可以跟踪错误。这是代码:https://jsfiddle.net/0anL7jfs/
我做错了什么吗?看来问题出在 SC.Widget() 函数...
您需要更改一些内容:
Define src
within your iframe with the player widget api url and properties:
<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&auto_play=false&hide_related=true&show_comments=true&show_user=true&show_reposts=false&visual=true">
</iframe>
Bind your events with widget.bind
:
<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>
示例:
http://jsfiddle.net/dqz1jmzo/ ( JQuery 版本 )
我正在尝试使用 Soundcloud API(本地)编写 Widget。
这是我的代码:
<!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>
我从 运行 得到的错误是:
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
我已将 soundcloud 的最小化 api 代码输入到 js 美化器中,以便我可以跟踪错误。这是代码:https://jsfiddle.net/0anL7jfs/
我做错了什么吗?看来问题出在 SC.Widget() 函数...
您需要更改一些内容:
Define
src
within your iframe with the player widget api url and properties:
<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&auto_play=false&hide_related=true&show_comments=true&show_user=true&show_reposts=false&visual=true">
</iframe>
Bind your events with
widget.bind
:
<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>
示例:
http://jsfiddle.net/dqz1jmzo/ ( JQuery 版本 )