开发者

AS3 notification for video first frame

开发者 https://www.devze.com 2022-12-27 16:26 出处:网络
When I play a video in Flash, first, it starts buffering and then, when the buffer is full, it plays. While the buffer is filling, the associated Video object automatically di开发者_开发问答splays the

When I play a video in Flash, first, it starts buffering and then, when the buffer is full, it plays. While the buffer is filling, the associated Video object automatically di开发者_开发问答splays the fist video frame.

Is there a way to receive a notification when this frame is available ? Because I want to hide the video component until there is an image to be displayed.

Currently I handle the buffer full NetStreamEvent, so it displays when it starts playing. But now I need a larger buffer (10s), so waiting 10s to display something to the user is not good.


you should listen for the "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.
        }
    }
 }
0

精彩评论

暂无评论...
验证码 换一张
取 消