Sound Cloud javascript API Stop()方法不工作
Sound Cloud javascript API Stop() method not working
我正在尝试切换启动和停止声音云流与以下代码。play()方法与条件逻辑一样工作。但是stop()方法不是。有人能解释一下我哪里做错了吗?
SC.initialize({
client_id: 'MY_CLIENT_ID'
});
if (streamingBool) {
SC.stream("/tracks/" + myTrackId, function (sound1) {
sound1.stop();
});
streamingBool = false;
} else {
SC.stream("/tracks/" + myTrackId, function (sound) {
sound.play();
});
streamingBool = true;
}
这段代码有两个问题
- SC。流异步执行回调函数
- 变量作用域,即您正在尝试停止当前播放的声音以外的声音
一个可行的实现是:
SC.initialize({
client_id: 'MY_CLIENT_ID'
});
var playing = false;
// Play a track
play = function(myTrackId){
if(playing){
SC.sound.stop();
}
SC.stream("/tracks/" + myTrackId, function(sound){
// Store the sound object inside the SC object which belongs
// to the global scope so that it can be accessed out of the
// scope of this callback
SC.sound = sound;
SC.sound.play();
playing = true;
});
}
// Stop the currently playing track
stop = function(){
if(playing){
SC.sound.stop();
}
}
相关文章:
- Javascript form.submit()方法是如何工作的
- JavaScript中的这个call()-方法是如何工作的
- Jquery ajax方法请求体为null,但poster工作正常
- 我该如何阻止单击方法多次工作
- jQuery方法未按预期工作-toggleClass
- 如何让应用程序帮助程序方法在发送的请求为 JS 格式时工作
- jQuery on() 方法只能通过 childSelector 间接工作
- 如何制作Javascript's减少对数组数组的方法工作
- 如何使我自己的javascript Math方法工作
- * 方法工作正常,但不能使用 jQuery ajax
- Javascript调用同一对象内的对象方法工作不正常
- 当项目停止在.NET中运行时,有没有办法阻止web方法工作
- is('checked')筛选方法工作不正常
- 在操作DOM时无法使对象方法工作
- ie9 getAttribute方法工作
- 如何使一个方法工作- Javascript
- Javascript变量到php变量转换方法工作.但我无法比较php变量
- 为什么'我的start()和stop()方法工作吗
- 从数据库加载值的Onchange Ajax方法工作正常,但如何将文本区域值与另一个文本框值相乘
- JavaScript RegExp测试方法工作不稳定,我的意思是第一次执行和第二次执行的结果不同