我正在尝试使用以下代码切换启动和停止Sound Cloud流。 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;
}
答案 0 :(得分:0)
此代码存在两个问题
工作实施将是:
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();
}
}