如何在 soundcloud javascript api 中暂停流媒体

2023-12-26

我想允许声音文件播放和暂停。该文档显示了如何播放流媒体文件:

    $("#stream").live("click", function(){      
          SC.stream("/tracks/{'track-id'}", function(sound){
             sound.play();
          };

它使用声音管理器进行流式传输并使用它的一些对象和方法...例如.pause()!

所以这是我认为应该有效的代码:

    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);
                }

            });

但是,它会继续播放曲目而不会暂停。有任何想法吗? 谢谢。


var is_playing = false;
soundManager.setup({
    url: '/swf/soundmanager2.swf',
    preferFlash: false,
    onready: function() {
        var mySound = soundManager.createSound({
            id: 'aSound',
            url: 'sonidos/sonido1.mp3' ,
            autoplay: false
        });

        $("#stream").live("click", function(){    
            if (is_playing==false){
                    mySound.play();
                    is_playing = true;
                }else if (is_playing== true) {
                    mySound.stop();
                    is_playing = false;
             }
        });
    },
    /*    ontimeout: function() {
    // Hrmm, SM2 could not start. Missing SWF? Flash blocked? Show an error, etc.?
    }*/
});
</script>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 soundcloud javascript api 中暂停流媒体 的相关文章