dcsimg
A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: detecting end of .flv

  1. #1
    Junior Member
    Join Date
    Aug 2004
    Location
    Cincinnati, OH
    Posts
    4

    detecting end of .flv

    Hello everyone,

    I've been figuring out the use of FLV's in Flash and I've come across a few problems. Let me also say that my actionscript is not stellar, as are all my flash skills as I haven't picked it up in a while.

    With the FLV, I've read that it doesn't make a lot of sense to preload the flv so I've pretty much given up on that, even though apparently I'm still getting sync problems.

    The main thing I need help with is detecting the end of my FLV to tell it to do something when finished. My FLV is in one frame and the following code on the same frame that I found on MM forums is NOT working:

    var myListener = new Object();
    myListener.complete = function(eventObject){
    trace("media is finished");
    };
    instance_name.addEventListener("complete", myListener);


    if any one has any ideas or can help me out I would greatly appreciate. the sooner you can get back to me, the better! THANKS!!

    Kevin

  2. #2
    Media Services
    Join Date
    Jul 2004
    Posts
    252
    ...you can just check your buffer and on buffer empty you can trigger any action.

    check this out

    or use that:

    Code:
    myVideo.onStatus = function(info) {
     if (info.code == "NetStream.Buffer.Empty") {
      //when video is finished do this
      myVideo.seek(0);
      myVideo.pause();
     }
    };

  3. #3
    Junior Member
    Join Date
    Aug 2004
    Location
    Cincinnati, OH
    Posts
    4
    Thanks for the response!

    I tried the code out and it's still not working for me. Here's what I got:
    code:

    stop();
    var connection_nc:NetConnection = new NetConnection();
    connection_nc.connect(null);
    var stream_ns:NetStream = new NetStream(connection_nc);
    my_video.attachVideo(stream_ns);
    my_video.setBufferTime(20);
    stream_ns.play("hops_fcp2.flv");
    my_video.onStatus = function(info) {
    if (info.code == "NetStream.Buffer.Empty") {
    //when video is finished do this
    gotoAndPlay(253);
    }
    }

    Do I need to define root in the gotoAndPlay or something???

    I tried another way with the time and it's working except after it goes in loops 8 frames and won't budge, so I'd like to get this way to work, since it seems a lot simpler. Any help???

    I appreciate it, after this project, I'm doing mad catch up on actionscript. I thank you ahead of time!

    Kevin

  4. #4
    Media Services
    Join Date
    Jul 2004
    Posts
    252
    Yes, if your script is inside MC you need to point it to desired timeline keyframe outside.
    Try _root or _parent depands on what you want to trigger.

  5. #5
    Junior Member
    Join Date
    Aug 2004
    Location
    Cincinnati, OH
    Posts
    4
    ok, i tested this out in a new file by

    1) creating a new video (embedded video 1) in my library
    2)putting that on the first layer
    3)typing this code into the second layer:

    stop();
    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("hops_fcp2.flv");

    my_video.onStatus = function(info) {
    if (info.code == "NetStream.Buffer.Empty") {
    //when video is finished do this
    trace("done");
    }
    };


    and it traces nothing. I'm so confused

  6. #6
    Senior Member
    Join Date
    Jan 2001
    Location
    London
    Posts
    361
    I think there's a bug with the NetStream.Buffer.Empty onStatus event.
    In my tests it doesn't seem to happen yet NetStream.Buffer.Full does occur.

    As for the end event, kevin the code in your first post should work if you export your FLV from the library in flash (ie. import it first). Assuming you are using the Media component.

    Dene

  7. #7
    Junior Member
    Join Date
    Aug 2004
    Location
    Cincinnati, OH
    Posts
    4
    Thank you all very much for responding. I appreciate the help immensely. I finally figured out what was going on and if you bear with me I'll try to explain.

    I emailed the person who wrote the below code:


    var myListener = new Object();
    myListener.complete = function(eventObject){
    trace("media is finished");
    };
    instance_name.addEventListener("complete", myListener);

    who ended up sending back a fla with flv that had this code working. so upon attaching my flv to his file, I noticed that it wasn't the code, but my video!! strange. it appears when i rendered out of FCP, media cleaner, or quicktime, this code would not work and it couldn't detect when the video was complete. But when I copied the video in quicktime to a new quicktime file and exported that out as flv, it would work.

    I'm guessing that's what you meant Dene by exporting out of Flash as an FLV would be another workaround to this problem???

    I don't know if this is known bug, or why in the world it was doing this, but it took me a while to figure it out. I liked this code a lot because it's short, simple, and doesn't need to rely on the buffer.

    So I don't know if any one has had problems like this, but just a heads up if anyone runs into problems later on down the road.

    this was a headache.

    again, thanks for the replies. and i'm sure i'll be sticking around these boards! time to tighten up on the actionscript skillz!!
    Last edited by kevinbayer; 08-12-2004 at 10:20 PM.

  8. #8
    Junior Member
    Join Date
    Jul 2006
    Posts
    5
    Quote Originally Posted by Dene
    I think there's a bug with the NetStream.Buffer.Empty onStatus event.
    In my tests it doesn't seem to happen yet NetStream.Buffer.Full does occur.
    Dene, do you know of a good way to work around the NetStream.Buffer.Empty bug?

  9. #9
    Senior Member
    Join Date
    Jan 2001
    Location
    London
    Posts
    361
    The NetStream.Buffer.Empty onStatus event bug has been fixed in Flash 8.
    Try running the NetSream.onStatus code example from Flash help docs. You should see the NetStream.Buffer.Empty event traced to the output window.

    Dene

  10. #10
    Junior Member
    Join Date
    Jul 2006
    Posts
    5
    Thanks, Dene! I've been stuck on MX 2004 forever, but now I definitely will upgrade to 8. Or should I wait for 9? Have you tested it yet?

    Thanks again!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center