视频缓冲的方式取决于浏览器实现,因此可能因浏览器而异。
各种浏览器可以使用不同的因素来决定保留还是放弃部分缓冲区。旧的细分,磁盘空间,内存和性能是典型的因素。
真正知道的唯一方法是“查看”浏览器具有或正在加载的内容。
为此,我制作了一个缓冲区查看器,显示缓冲区中的哪个部分。观众将显示当前和整个缓冲区的所有部分:
ONLINE BUFFER VIEWER
例如 - 在Chrome中我打了几秒钟,然后我跳过约30秒,你可以看到,它开始加载另一部分从那个位置开始。 (缓冲区也似乎与关键帧有界,因此可以解码该缓冲区中的n帧,这意味着缓冲区可以在实际位置之前开始加载数据)。
![Example](https://i.stack.imgur.com/oc2Pz.png)
我提供的演示视频约1分钟长 - 然而,这是不是足够长的时间做正确的测试。免费提供包含更长视频的视频链接(或者如果您希望我用此更新演示,请分享)。
主函数将迭代视频元素上的buffered
对象。它会将所有存在的部分渲染到视频下方的画布上,并以红色显示。
您可以在此查看器上单击(位不拖动)将视频移动到不同的位置。
/// buffer viewer loop (updates about every 2nd frame)
function loop() {
var b = vid.buffered, /// get buffer object
i = b.length, /// counter for loop
w = canvas.width, /// cache canvas width and height
h = canvas.height,
vl = vid.duration, /// total video duration in seconds
x1, x2; /// buffer segment mark positions
/// clear canvas with black
ctx.fillStyle = '#000';
ctx.fillRect(0, 0, w, h);
/// red color for loaded buffer(s)
ctx.fillStyle = '#d00';
/// iterate through buffers
while (i--) {
x1 = b.start(i)/vl * w;
x2 = b.end(i)/vl * w;
ctx.fillRect(x1, 0, x2 - x1, h);
}
/// draw info
ctx.fillStyle = '#fff';
ctx.textBaseline = 'top';
ctx.textAlign = 'left';
ctx.fillText(vid.currentTime.toFixed(1), 4, 4);
ctx.textAlign = 'right';
ctx.fillText(vl.toFixed(1), w - 4, 4);
/// draw cursor for position
x1 = vid.currentTime/vl * w;
ctx.beginPath();
ctx.arc(x1, h * 0.5, 7, 0, 2 * Math.PI);
ctx.fill();
setTimeout(loop, 29);
}
来源
2013-09-04 22:26:56
K3N
当你暂停视频并运行buffered.end(索引)时,它返回1并停止工作。这是一种常见的行为吗?找不到相关问题。 –