Jan
22
NetStream “onComplete” (FMS2)
Filed Under AS3, Flash & Flex
Normally I do this in finnish but this time I’m making an exeption.
So let’s get down to business. I’ve been working this whole day on flv-player (streaming from FMS2). It was all going pertty smoothly until I had to find a way to determine wheter the flv was still playing or reached the end (or completed). At first it seemed like there is no efficient handler to detect this. At least I didn’t find an answer from Google
.
Well the thing is NetStatusEvent.NET_STATUS’ code property does not have a value “NetStream.Play.Complete”. “NetStream.Play.Stop” is the closest match but it seems like it is triggered a second or a few before the flv actually ends. Second drawback is that you also get that value when user stops the playback. So that is no good.
Then I tried what the onPlayStatus handler has to offer. And guess what… when the playback is completed onPlayStatus’ code property has a value of “NetStream.Play.Complete”. How come I’ve never heard about this “onPlayStatus”… until now ofcourse.
So heres the code:
ns = new NetStream(myNetConnection); ns.client = this; <span id="more-181"></span> function onPlayStatus(o:Object):void { if (o.code == "NetStream.Play.Complete") { //play next stream //or do something else } }
Was it really that simple?
Read more here: Progressive stream – onComplete
Comments
8 comments to “NetStream “onComplete” (FMS2)”
Leave a comment

this code is not simple. it doesn’t explain anything.
Sorry Kurt. I thought this it’s pretty straightforward. But I’ll be happy to explain it more or post example code if you can tell me which part of the post needs more explaining.
Kurt, the key thing is that the client of the netstream instance is set to “this”, which means that it should then call the onPlayStatus function.
But, I’m trying it now and it still doesn’t seem to work for me, which is bloody annoying! Can’t see what I’m doing wrong…
The onPlayStatus-handler is invoked only if you are streaming the media from streaming server (FMS).
If you are using “progressive stream” instead ( myNetConnection.connect(null); ) onPlayStaus handler is never invoked.
that would be it then…
so there is no effective way to detect the end of an flv using progressive stream.
Not really. I’m currently wokring on class that helps us with this problem. I’ll post it later today.
Use the duration metadata to capture the end of a movie.
And that is just what I’m doing. Check this post:
Progressive stream – onComplete