如何在 soundcloud javascript api 中暂停流式传输 [英] How to pause streaming in soundcloud javascript api
问题描述
我想允许播放和暂停声音文件.该文档显示了如何播放流文件:
I would like to allow a sound file to play and pause. The documentation shows how to play a streaming file:
$("#stream").live("click", function(){
SC.stream("/tracks/{'track-id'}", function(sound){
sound.play();
};
它使用声音管理器进行流式传输并使用它的一些对象和方法......比如 .pause()!
It uses Sound Manager to stream and uses some of it's objects and methods... like .pause()!
所以这是我认为应该工作的代码:
So here's the code i think should work:
var is_playing="false";
$("#stream").live("click", function(){
SC.stream("/tracks/{'track-id'}", function(sound){
if (is_playing==="true")
{
sound.pause();
is_playing = "false";
console.log(is_playing);
}
else if (is_playing === "false")
{
sound.play();
is_playing = "true";
console.log(is_playing);
}
});
但是,它会继续播放曲目而不会暂停.有任何想法吗?谢谢.
However, it continues to play the track without pausing. Any ideas? Thanks.
推荐答案
SC.stream("/tracks/13680213", function(sound) {
SC.sound = sound;
});
这意味着您不会在 SC.stream 构造函数中编写事件侦听器,然后您可以随意访问以下(以及更多):
This means you aren't writing event listeners inside your SC.stream constructor then you can access the following (and more) at will:
SC.sound.play();SC.sound.pause();SC.sound.stop();SC.sound.pause();SC.sound.playState;
这篇关于如何在 soundcloud javascript api 中暂停流式传输的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!