如何检测视频何时缓冲? [英] How to detect when video is buffering?
问题描述
我今天的问题是关于 Flash AS3 视频缓冲.(流式或渐进式)我希望能够检测到视频何时被缓冲,这样我就可以显示某种动画,让用户知道再等一会儿.
my question today deals with Flash AS3 video buffering. (Streaming or Progressive) I want to be able to detect when the video is being buffered, so I can display some sort of animation letting the user know to wait just a little longer.
目前我的视频将启动,按住第 1 帧 3-4 秒然后播放.有点给人一种视频暂停或损坏的印象:(
Currently my video will start up, hold on frame 1 for 3-4 secs then play. Kinda giving the impression that the video is paused or broken :(
感谢 iandisme,我相信我现在正朝着正确的方向前进.来自 livedocs 的 NetStatusEvent.在我看来,工作的关键状态是 "NetStream.Buffer.Empty"
所以我在那里添加了一些代码,看看这是否会触发我的动画或跟踪语句.还没有运气,但是当缓冲区已满时,它会触发我的代码:/也许我的视频总是介于 Buffer.Empty
和 Buffer.Full
之间,这就是为什么它不会'当我为 Buffer.Empty
测试用例时触发任何代码?
Thanks to iandisme I believe I'm faced in the right direction now. NetStatusEvent from livedocs. It seems to me that the key status to be working in is "NetStream.Buffer.Empty"
so I added some code in there to see if this would trigger my animation or a trace statement. No luck yet, however when the Buffer is full it will trigger my code :/ Maybe my video is always somewhere between Buffer.Empty
and Buffer.Full
that's why it won't trigger any code when I test case for Buffer.Empty
?
public function netStatusHandler(event:NetStatusEvent):void
{
// handles net status events
switch (event.info.code)
{
case "NetStream.Buffer.Empty":
trace("☼☼☼ Buffering!"); //<- never traces
addChild(bufferLoop); //<- doesn't execute
break;
case "NetStream.Buffer.Full":
trace("☼☼☼ FULL!"); //<- trace works here
removeChild(bufferLoop); //<- so does any other code
break;
case "NetStream.Buffer.Flush":
trace("☼☼☼ FLUSH!");
//Not sure if this is important
break
}
}
推荐答案
您是否使用自定义滚动播放器?我知道 FLVPlayback 类有一个 缓冲事件 内置.
Are you using a custom-rolled player? I know the FLVPlayback class has a buffering event built-in.
如果您不使用 FLVPlayback,则 NetStream 对象会触发 netStatusEvent,其中包含 信息对象 每次开始或停止缓冲.您应该能够捕获该事件并使用它播放/隐藏您的动画.
If you're not using FLVPlayback, the NetStream object fires a netStatusEvent that includes an info object every time it starts or stops buffering. You should be able to capture that event and play/hide your animation with that.
这篇关于如何检测视频何时缓冲?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!