Skip to main content
July 11, 2006
Question

Question about NetStream.onPlayStatus

  • July 11, 2006
  • 9 replies
  • 1841 views
I have an external flv which I want to go back to the beginning once it is finished so the viewer can watch it again without having to reload the page. When I posted this question in the Actioscript forum someone suggested that I use NetStream.onPlayStatus (I'm using NetStream.pause and NetStream.seek for the other controls) but when I tried to use it I got an error saying "there is no property with the name'onPlayStatus'". I am using Flash MX 2004. Is this property only available in Flash Media Server. If so does anybody know another way of basically doing this:

netStream.onPlayStatus = function(reset) {
if (reset.code == "NetStream.Play.Complete") {
netStream.seek(0);
}
};
    This topic is closed to new replies. Start a new post to keep the conversation going.

    9 replies

    July 12, 2006
    I've never used the v7 encoder, so I can't say for sure on that one. Try adding the onMetaData method and see what traces out.

    So you know, running the .flv through FLVMDI won't hurt anything if the metadata is already in place, so if you're not sure (or if you get nothing when you trace out the metadata from the flv), go ahead and run it through FLVMDI.
    July 11, 2006
    It's sort of a bad practice to use the class name as the variable name (even with differently cased letters in the name), but I don't think that's the problem.

    Oh... I just reread your posts, and saw that you're using a progressive download, rather than FMS. I'm wondering if onPlayStatus method is only available when using FMS to play the stream. If you notice, it's not in the Flash 8 docs... just in the FMS docs.
    July 11, 2006
    Yeah I think that's the issue as well. Except if use .onStatus instead of .onPlayStatus I don't get an error message but it still doesn't work. I'm not sure that .onStatus and .onPlayStatus do the same thing. Is there a way of doing this in MX 2004 without the use of onPlayStatus?
    July 11, 2006
    I don't have a solution for the onPlaystatus method, but I do have an alternative.

    I like to use onMetaData for lots of different tasks, including firing off functions based on stream time. If your flv was injected with proper metadata, it will have the stream length (running time) in the metadata. Armed with that, you have what you need to detect the end of the stream (by comapring the netstream time to the stream length.

    So, how do I know if my flv has proper metadata? Well, if you encoded it with the Flash video encoder (the one that ships with Flash 8) or if you use Burak's FLVMDI (it's a free metadata injector), you can be sure the metadata is in there, and it's properly formed. If you use Sorenson Squeeze (bleh), the metadata won't be in there, so you'll need FLVMDI to inject it.
    July 11, 2006
    The netStream class has no onPlayStatus method, unless you define it yourself.

    I think what you're looking for is onStatus, and you can find notes for it's usage in the docs.
    July 11, 2006
    I don't know how to use it but there is something called NetStream.onPlayStatus. This is from the Flash Media Server LiveDocs:

    NetStream.onPlayStatus
    Availability

    * Flash Player 6.
    * Flash Media Server 2.

    Usage

    public onPlayStatus = function(infoObject:Object) {}

    Parameters

    infoObject An object containing an error or status message. For more information about this parameter, see NetStream information objects.
    Returns

    Nothing.
    Description

    Event handler; invoked when a NetStream object has completely played a stream. The information object gives extra information when a NetStream object has switched from one stream to another stream in a playlist (NetStream.Play.Switch) or when a NetStream object has played to the end (NetStream.Play.Complete). If you want to respond to this event handler, you must create a function to process the information object sent by the server. For more information, see Client-Side Information Objects.
    Example

    The following example displays data about the stream in the Output panel:

    var connection_nc:NetConnection = new NetConnection(); connection_nc.connect(null); var stream_ns:NetStream = new NetStream(connection_nc); my_video.attachVideo(stream_ns); stream_ns.play("video1"); stream_ns.onPlayStatus = function(infoObject:Object) {
    trace("NetStream.onPlayStatus called: ("+getTimer()+" ms)");
    for (var prop in infoObject) {
    trace("\t"+prop+":\t"+infoObject[prop]);
    }
    trace("");
    };




    I tried .onStatus but that didn't work.
    July 11, 2006
    Funny... I didn't know the method was introduced in FMS2 (I haven't looked at the docs much since 1.5). Learn something new every day I guess.

    You'll want to create a reference to the new netstream, rather than accessing the class directly. Like so:

    nc = new NetConnection();
    my_ns = new NetStream(nc);
    my_ns.onPlayStatus = function(info){
    trace(info.code);
    }