Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何通过SoundCloud API切换播放和暂停曲目_Javascript_Api_Soundcloud - Fatal编程技术网

Javascript 如何通过SoundCloud API切换播放和暂停曲目

Javascript 如何通过SoundCloud API切换播放和暂停曲目,javascript,api,soundcloud,Javascript,Api,Soundcloud,我正在尝试制作一个按钮来切换播放和暂停歌曲。我使用了sound.play()和sound.pause()方法,但只有play()起作用,而且从不停止 以下是我如何让它工作的: function player(){ var sound = SC.stream("/tracks/293", function(sound){ if(is_playing==="true") { sound.pause(); is_pla

我正在尝试制作一个按钮来切换播放和暂停歌曲。我使用了
sound.play()
sound.pause()
方法,但只有
play()
起作用,而且从不停止

以下是我如何让它工作的:

    function player(){
    var sound = SC.stream("/tracks/293", function(sound){
        if(is_playing==="true") { 
            sound.pause(); 
            is_playing = "false";
        } 
        else if (is_playing === "false") { 
            sound.play(); 
            is_playing = "true";
        }
    });
    }

下面是演示:

以下代码应该实例化,
播放
,如果有任何内容正在播放,也可以
暂停

var is_playing = false,
    sound;
function player(){
    if( sound ) {
        if(is_playing) {
            sound.pause();
            is_playing = false;
        } else {
            sound.play();
            is_playing = true;
        }
    } else {
        SC.stream("/tracks/293", function(obj){
            obj.play();
            sound = obj;
            is_playing = true;
        });
    }
}


我想知道是否有一个
简历
方法;也可以将其纳入守则。我做了一个快速测试,确实有一个
resume
方法可以从暂停处继续播放。

感谢您的帮助。它按照我想要的方式工作。也有一个切换方法,但不知何故它不起作用。无论如何,谢谢你!很高兴我能帮忙。