间歇性错误:什么会导致视频在loadstart和durationchange之间停止加载?

时间:2013-05-30 20:39:49

标签: javascript video intermittent

我遇到了间歇性错误令人沮丧的情况。功能正常时,PHP指定一个视频和3个要显示的图片。页面加载后视频开始播放800ms,视频结束后立即显示图片,此时用户按下一个键(对应于图片的位置),按键触发一个测量反应时间的功能,存储他们选择的图片,并加载下一页,然后所有这一切再次发生新视频和新图片。

一切都很好......有时候。

在其他时候,我得到一个空白的屏幕,我期待看到视频。有时它会立即发生,有时会在多达15或20次成功加载之后发生,或者介于两者之间。我正在运行Chrome 27.0.1453.93,并使用Chrome的内置JavaScript控制台跟踪错误。即使视频无法加载,也没有javascript错误(使用DOCTYPE HTML PUBLIC“ - // W3C // DTD HTML 4.01 // EN”>)。

为了确定故障的位置,我添加了一堆事件监听器,并使用匿名函数将一些输出传递给js控制台日志文件,以查看视频事件的哪些阶段正在发生或未发生。至少在这里是一种可靠的模式:每次视频加载失败时,loadstart都会发生,但是持续时间变化却没有。我只是无法弄清楚阻止它继续的问题是什么!

我期待这里的回答,无论是答案还是其他人都证实了这些经历,所以我不觉得这么疯狂!我将在这里包含两个最相关的javascript函数,但我不确定他们会做多少好事。

<script>

    function playVid(newSource){

           console.log("playVid worked");
           setTimeout(function(){//tells it to wait for some amount of time (below) before doing the next part
               console.log("setTimeout was called");
               document.getElementById("StimClip").innerHTML="<video id='video1'> <source src='" + newSource + "' type='video/mp4'>Something went wrong.  Sorry 'bout that!</video>"; //replace blank.jpg with the appropriate video
               console.log("the inner html was set");
               myAddListener();
               console.log("myAddListener was called");
               var  myVid=document.getElementById("StimClip"); //create a new variable to identify the video
               console.log("the myVid variable was created");
               video1.play(); //play the video

        } //


           ,800); //finishes the setTimeout call by specifying how many msec to wait before executing.


        }

function myAddListener(){
        console.log("myAddListener worked");
        var myVideo = document.getElementsByTagName('video')[0];         
        myVideo.addEventListener('waiting', function(){console.log("I'm WAITING...!")}, false);
        myVideo.addEventListener('suspend', function(){console.log("Nice suspenders.")}, false);
        myVideo.addEventListener('abort', function(){console.log("video was aborted")}, false);
        myVideo.addEventListener('error', function(){console.log("there was an error")}, false);
        myVideo.addEventListener('loadstart', function(){console.log("load start worked")}, false);
        myVideo.addEventListener('durationchange', function(){console.log("the duration changed")}, false);
        myVideo.addEventListener('loadedmetadata', function(){console.log("metadata was loaded")}, false);
        myVideo.addEventListener('loadeddata', function(){console.log("data was loaded")}, false);
        myVideo.addEventListener('progress', function(){console.log("progress...? ")}, false);
        myVideo.addEventListener('canplay', function(){console.log("video can play")}, false);
        myVideo.addEventListener('canplaythrough', function(){console.log("can play through worked")}, false);
        myVideo.addEventListener('playing', function(){console.log("the video started playing")}, false);
        myVideo.addEventListener('ended', ShowPics, false); 
    }
</script>

1 个答案:

答案 0 :(得分:1)

哦,天哪。我很高兴没有人浪费时间试图回答这个问题。万一你想知道,导致视频在loadstart和durationchange之间停止加载的事情是该视频不存在! (我的一个视频的文件名中有一个拼写错误,而且因为视频的顺序是随机的,所以当它试图加载同一个视频时,我无法告诉它总是失败。)

固定。

相关问题