视频第一帧的AS3通知

时间:2010-04-19 21:14:27

标签: flash actionscript-3 netstream

当我在Flash中播放视频时,首先,它开始缓冲,然后,当缓冲区已满时,它会播放。缓冲区正在填充时,关联的Video对象会自动显示第一个视频帧。

当此框架可用时,是否有办法接收通知?因为我想隐藏视频组件,直到有图像显示。

目前我处理缓冲区完整的NetStreamEvent,因此它会在开始播放时显示。但是现在我需要一个更大的缓冲区(10s),所以等待10s向用户显示内容并不好。

1 个答案:

答案 0 :(得分:0)

你应该听“NetStream.Play.Start”;

package {
    import flash.display.Sprite;
    import flash.events.*;
    import flash.media.Video;
    import flash.net.NetConnection;
    import flash.net.NetStream;

    public class VideoExample extends Sprite {
        private var videoURL:String = "someVideo.flv";
        private var connection:NetConnection;
        private var stream:NetStream;
        private var video:Video;

        public function VideoExample() {
            connection = new NetConnection();
            connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
            connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
            connection.connect(null);
        }

        private function netStatusHandler(event:NetStatusEvent):void {

          trace("event.info.code "+event.info.code);

           switch (event.info.code) {
                case "NetConnection.Connect.Success":
                    connectStream();
                    break;

                case "NetStream.Play.Start":
                addChild(video);
                break;

                case "NetStream.Play.StreamNotFound":
                    trace("Unable to locate video: " + videoURL);
                    break;
            }
        }

        private function connectStream():void {
            var stream:NetStream = new NetStream(connection);
            stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
            stream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
            video = new Video();
            video.attachNetStream(stream);
            stream.play(videoURL);

        }

        private function securityErrorHandler(event:SecurityErrorEvent):void {
            trace("securityErrorHandler: " + event);
        }

        private function asyncErrorHandler(event:AsyncErrorEvent):void {
            // ignore AsyncErrorEvent events.
        }
    }
 }