5

I'm using flash.net.NetStream and flash.media.Video to play a .flv, here is some code:

var stream:NetStream = new NetStream(connection);

//next line is to avoid an error message
stream.client = {onMetaData: function(obj:Object):void {}}

var video:Video = new Video();
video.attachNetStream(stream);
stream.play("url.to/video");

addChild(video);

That plays the video, but how I can know WHEN the video has played from the beginning to the end? How to know if the video was played ALL it's length?

PS: Sorry for my bad English.

4 Answers 4

14

Bartek answer is the most accurate but I've found that the code I need is "NetStream.Play.Stop"

The code "NetStream.Play.Complete" doesn't exist.

stream.addEventListener(NetStatusEvent.NET_STATUS, statusChanged);

function statusChanged(stats:NetStatusEvent) {
    if (stats.info.code == 'NetStream.Play.Stop') {
         trace('the video has ended');
    }
}

This works since you can't STOP the stream, only pause it (and resume it), so the only way to this status arise is to end the video playback reaching the end (and that's what I need)

PS: Sorry for my bad English.

1

The code I need was:

        public function statusChanged(stats:NetStatusEvent):void 
        {
            trace(stats.info.code);
            if (stats.info.code == 'NetStream.Buffer.Empty') 
            {
                trace('the video has ended');
            }
        }

(the only change I had to make was Changing Play.Stop to Buffer.Empty)

1
  • 1
    The buffer could become empty for many other reasons besides completing the video, though... Jun 12, 2014 at 15:26
0

I believe you'll want to add another function to your stream.client object, called 'onPlayStatus'

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/NetStream.html#event:onPlayStatus

So create the function somewhere else in your code perhaps and then reference it like so:

function myFunction(obj:Object):void
{
    //do something here
}
stream.client = {onPlayStatus: myFunction}
1
  • Or I have done something wrong or I don't know why, but the function is never called. Jul 12, 2011 at 14:12
0

Just add event listener for NET_STATUS:

stream.addEventListener(NetStatusEvent.NET_STATUS, statusChanged);

function statusChanged(stats:NetStatusEvent) {
    if (stats.info.code == 'NetStream.Play.Complete') {
         // do some stuff
    }
}
2
  • There is no such code "NetStream.Play.Complete" for NetStatusEvent. Not in the help files, and not in the running code, I trace EVERY event and the only I see at the end is "NetStream.Play.Stop". Jul 12, 2011 at 14:05
  • 2
    @unkiwii If you look for the 'NetStream.play.stop' event. When that event is fired you could check that NetStream.time is equal to the total running time of you're movie. Then you know the movie has played to a completion.
    – Bakapii
    Jul 12, 2011 at 14:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.