Search code examples
actionscript-3netstream

How do I know, when the player stops playing?


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


        private function connectStream():void
        {
            stream= new NetStream(connection);
            stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
            stream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
            stream.client = this;
            stream.bufferTime = 30;
            video = new Video(600,313);
            video.attachNetStream(stream);
            stream.play(vName); 
            addChild(video);
        }


    }
    private function netStatusHandler(event:NetStatusEvent):void
    {

        trace(event.info.code);

    }

If the video ended playing its not tracing "NetStream.Play.Stop" info code. Why?


Solution

  • You need to look at http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/NetStream.html#event:onPlayStatus

    From Adobe:

    Establishes a listener to respond when a NetStream object has completely played a stream. The associated event object provides information in addition to what's returned by the netStatus event. You can use this property to trigger actions in your code when a NetStream object has switched from one stream to another stream in a playlist (as indicated by the information object NetStream.Play.Switch) or when a NetStream object has played to the end (as indicated by the information object NetStream.Play.Complete).