Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/73.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 100%HTML5模式下的SoundManager卡在“开启”状态;停滞不前;_Javascript_Html_Soundcloud_Samsung Smart Tv_Soundmanager2 - Fatal编程技术网

Javascript 100%HTML5模式下的SoundManager卡在“开启”状态;停滞不前;

Javascript 100%HTML5模式下的SoundManager卡在“开启”状态;停滞不前;,javascript,html,soundcloud,samsung-smart-tv,soundmanager2,Javascript,Html,Soundcloud,Samsung Smart Tv,Soundmanager2,在我的智能电视应用程序中,我通过跨域请求使用SoundCloud API-$.getJSON()等。 该应用程序还在100%HTML5模式(无Flash)下使用SoundManager2API从SoundCloud检索的.stream\uURL加载曲目。当尝试播放加载的曲目时,问题开始出现。假设应用程序加载了10首曲目,其中一些无法播放。 我注意到日志上写着: 0040 sound0: play(): Loading - attempting to play... 0041 sound0:

在我的智能电视应用程序中,我通过跨域请求使用SoundCloud API-
$.getJSON()
等。
该应用程序还在100%HTML5模式(无Flash)下使用SoundManager2API从SoundCloud检索的
.stream\uURL
加载曲目。当尝试播放加载的曲目时,问题开始出现。假设应用程序加载了10首曲目,其中一些无法播放。
我注意到日志上写着:

0040  sound0: play(): Loading - attempting to play...
0041  sound0: abort
0042  sound0: waiting
0043  sound0: loadstart
0044  sound0: stalled 
它永远停留在那里。问题总是发生在同一首曲目上,而其他曲目可流式播放,显示日志:

0078  sound2: durationchange (191190)
0079  sound2: loadedmetadata
0080  sound2: stalled
0081  sound2: suspend
0082  sound2: loadeddata
0083  sound2: canplay
0084  sound2: onload()
0085  sound2: playing ♫
用于创建声音对象并播放该对象的代码:

        SoundObject = soundManager.createSound({    //  load the current track
            url: "https://api.soundcloud.com/tracks/" + TrackIDs[elements][index-1] + "/stream?client_id=f430822ab78177a5cfb94d572d9036a2",
            volume: 100,
            autoLoad:    true, 
            //autoPlay:      true,
            //stream:        true,
            whileplaying:function(){currentPosition=SoundObject.position;barWhilePlaying(elements, index, currentPosition);},                         
            onfinish:    function(){barOnFinish(elements, index);},                       
            onstop:      function(){barOnStop(elements, index);},
        });
        SoundObject.play();
(其中,
whileplay
onfinish
onstop
参数都调用一个函数,该函数可以更改html文档中的css和/或元素类。)

我的问题:

  • 有没有办法事先知道声音对象不会播放
  • 假设我在加载之前无法知道它将永远“加载开始”和“暂停”,那么有没有办法在加载之后知道呢?
    我问这个问题,因为有些曲目会在长时间后加载并播放
    我可以建议一个可能有用的解决方法

    var mySound = soundManager.createSound({..});  
    mySound.load();  
    setTimeout(function() {
        if (mySound.readyState == 1) {
            // this object is probably stalled
            }
    },5500);
    
    这是因为在html5中,与flash不同,readystate属性几乎瞬间从“0”(未初始化-尚未加载)跳到“3”(已加载),跳过“1”(已初始化-已开始加载),因为如果声音开始缓冲,它可以在html5中播放,因此readystate返回3…
    在html5上,在load()尝试之后,永久(或长时间)暂停的声音的readystate=1

    之后-您可以替换/删除/跳过不规则轨道或其他任何内容

    • 注意-5500毫秒应该足够长,您可以使用它,并查看平台的最佳超时时间
    希望这对你有帮助