Hi Eric.

There are three ways that I know of to detect the end of an FLV. WARNING. I
haven't tested this code, or looked it over for best practices, etc.

1) The simplest way is to use the FLVPlayback component and use the complete
event. (The following assumes an FLVPlayback component is on stage and
instantiated as "myVid", and haven't changed anything else. Without
autoplay, for example, you'd have to add a line to play the vid, etc. You
can also create an instance if it's in your library if that's better.):

**
import fl.video.*;

myVid.source = "<video name here>.flv";

myVid.addEventListener(VideoEvent.COMPLETE, vidEnd);
function vidEnd(evt:VideoEvent):void {
    trace("FLV has ended");
}
**

2) The second method is pretty much the same, but doesn't rely on the
FLVPlayback component. Instead, it uses the VideoPlayer class.

**
import fl.video.*;

var vidPlayer:VideoPlayer = new VideoPlayer();
addChild(vidPlayer);

vidPlayer.play("<video name here>.flv");

vidPlayer.addEventListener(VideoEvent.COMPLETE, vidEnd);
function vidEnd(evt:VideoEvent):void {
    trace("FLV has ended");
}
**

This reduces file size because you aren't using the component, but it
doesn't have a controller, or all the capabilities of the component (such as
seeking to cue points). You also have to add code if you're streaming the
video, because the component takes care of that for you. I haven't done that
yet, so you'll have to look that up in the docs, sorry. I haven't had a need
to save on file size so significantly that I skip the component. However,
using this method does allow you to do things 100% with code, so you don't
need the component in the library to begin with.


3) If you need to know the end is nigh, you'll need to look for the video's
metadata. As far as this being "reliable" goes, this method requires that
the metadata be in the FLV. Although different encoders add different ranges
of features, most do add 'duration' metadata. You can also probably inject
it using one of the third party metadata injectors, after the video has been
encoded.

To look for the metadata, you'd write an object that is assigned to the
NetStream. Here's a simple example.

**
var vidConnection:NetConnection = new NetConnection();
vidConnection.connect(null);
var vidStream:NetStream = new NetStream(vidConnection);

var vidDuration:Number;
var vidClient:Object = new Object();
vidClient.onMetaData = function (md:Object):void {
    vidDuration = md.duration;
}
vidStream.client = vidClient;

var myVideo:Video = new Video();
myVideo.x = myVideo.y = 100;
myVideo.attachNetStream(vidStream);

addChild(myVideo);

vidStream.play("<video name here>.flv");

**

>From there you can do something like this (though more efficient?):

**
this.addEventListener(Event.ENTER_FRAME, checkVid);
function checkVid(evt:Event):void {
    var timeDiff = (vidDuration - vidStream.time)
    if (timeDiff < 3 && timeDiff > 0) {
        trace("The video will end in less than 3 seconds");
    }
}
**

--Rich Shupe

On 4/20/07 4:07 PM, "eric e. dolecki" <[EMAIL PROTECTED]> wrote:
> is there a reliable way with AS3 to detect the end of a FLV?



_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to