1

我编写了一个回调函数来使用 html5 视频控件和画布捕获正在运行的视频的快照。

我使用for循环进行迭代并调用相同的回调函数进行突发捕获。

如果我alert('')在回调中添加,在显示警报消息时重新渲染背景中的视频,则连拍快照可以很好地拍摄差异照片(正在运行的视频的帧/图像)。但是当我删除 时alert(''),视频不会在后台运行,并且爆裂的图像是相同的而不是不同的。

编码

for (var i = 0; i < burstcount; i++) {
        var wcam = Webcam;
            wcam.burst_snap(function (dataurl, id) {
                var arrayindex = passedName + "_" + id;
                imgid = imgid + i;
                alert(dataurl);
                burstcapturedata[arrayindex] = dataurl;
            }, i);
            var j = 0;
            while (j < 10000000000) {
                j++;
            }
    }
    DisplayBurstedImages();

}

4

3 回答 3

1

是的,实际上。警报保持代码的下一次执行。
如果您的代码与警报一起使用,则意味着您需要延迟。
尝试setTimeout或将代码放在加载所有内容的正确位置。

于 2015-04-22T13:15:24.763 回答
0

您的代码需要看起来像这样:

 var wcam = Webcam;
 var cnt = 0;
 wcam.burst_snap(function(dataurl, id) {
   var arrayindex = passedName + "_" + id;  //you do not have an array if this is the key
   imgid = imgid + cnt;  //no clue what this is for
   cnt++;
   burstcapturedata[arrayindex] = dataurl;
   if (cnt===burstcount) {
     DisplayBurstedImages();
   }
 }, 100);  //no clue what that value is supposed to be
于 2015-04-22T14:01:01.797 回答
0

我想它需要时间来绑定视频。您可以使用 setTimeout 函数进行延迟。

var delay =100;

setTimeout(function () {/*your function*/ }, delay);

delay = delay + 300;
于 2015-04-22T13:31:48.473 回答