views:

156

answers:

2

When I play a video in Flash, fist, it starts buffering and then, when the buffer is full, it plays. While the buffer is filling, the associated Video object automatically displays 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.

A: 

Well, a very good tutorial is mentioned at http://www.gotoandlearn.com in the end. May be this can help you..

Muhammad Irfan
A: 

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.
        }
    }
 }
daidai