A Flash Developer Resource Site

Results 1 to 19 of 19

Thread: [RESOLVED] use of cue points in video playback to detect video end

  1. #1
    Senior Member
    Join Date
    Jan 2007
    Location
    Barcelona
    Posts
    389

    resolved [RESOLVED] use of cue points in video playback to detect video end

    Hi,

    I'm trying to make my video unload by themselves upon ending and have just pasted this example code in them, but, one of them works fine and the other one stops before reaching the end.

    // The code I used

    Code:
    var listenerObject:Object = new Object();
    listenerObject.complete = function(eventObject:Object):Void {
       unloadMovie(TheArea);
    };
    my_FLVplybk.addEventListener("complete", listenerObject);
    Is there a more reliable way to know when the video has really ended playing? I've heard and read a little about cue points, but I don't think I would know how to apply them... I would like to use or create these cue points in embedded flvs. I don't know if it makes any difference. I can't understand so well how you create one from the property inspector if that could be a solution to my need.

    thanks

    http://webs.ono.com/jpdurba is where I have the videos, under the hobbies section.

  2. #2
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  3. #3
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi Cap,

    Which one works fine, the bowling clip is only 5 - 10 seconds long, as far as I can tell, the other one does not have the listener code inside of it and therefore will not unload itself upon ending.

    You could put a small setInterval at the end inside the .complete code to hold it for a few seconds before it unloads.

    I personally prefer to use NetConnection with flash video, I think you have more control over it.

    Cue points as far as I know are really used for telling the movie at certain points to do something, text maybe, show an advert ect ect.

    http://help.adobe.com/en_US/AS2LCR/F...=00000422.html

  4. #4
    Senior Member
    Join Date
    Jan 2007
    Location
    Barcelona
    Posts
    389
    The first one, the bowling clip... or that's what it seems to me...

    the second one is just a little short. I'm just trying to figure out the solution about adding the setInterval method.

  5. #5
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    You could just find a longer clip from the internet seeing as it is only a few seconds long

  6. #6
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    You could just find a longer clip from the internet seeing as it is only a few seconds long.

    Interval with other code
    PHP Code:
    var listenerObject = new Object();
    listenerObject.complete = function (eventObject:Object)
    {
        
    DoHold setInterval(HoldVideo5000);// 5 seconds
    };
    my_FLVplybk.addEventListener("complete"listenerObject);
    function 
    HoldVideo()
    {
        
    clearInterval(DoHold);
        
    unloadMovie(TheArea);
        
    trace("Unloaded");

    Last edited by fruitbeard; 01-14-2014 at 11:47 AM.

  7. #7
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    I agree with Fruitbeard
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  8. #8
    Senior Member
    Join Date
    Jan 2007
    Location
    Barcelona
    Posts
    389
    I do too. I'll just add more frames to the clip. I don't think it will mean much weight.

    The interval function did not work, Fruit. Could it be something in the clip itself?

  9. #9
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    The interval does work as I know its tested and working, it probably is something in the clip.

    Again you will need to attach any fla's so we can analyse them for you.
    Adding extra frames to the clip won't stop the video ending with the listener.

  10. #10
    Senior Member
    Join Date
    Jan 2007
    Location
    Barcelona
    Posts
    389
    this way, it does, but that is not the total time of the clip... it's missing some frames.

    Code:
    var listener:Object = new Object();
    listener.complete = function(evt:Object):Void {
      trace("Video complete");
      trace(evt.state);
      trace(evt.playheadTime);
      if(evt.playheadTime == 46.741){
    	   DoHold = setInterval(HoldVideo, 5000);
      }
    }
    my_FLVplybk.addEventListener("complete", listener);

  11. #11
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi

    Is playheadTime == 46.741 the total time of the video?

    .comlpete means when finished anyway

  12. #12
    Senior Member
    Join Date
    Jan 2007
    Location
    Barcelona
    Posts
    389
    I suppose not. That's the trace, but the video should go on for a bit longer

  13. #13
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi Cap,

    You could do a little testing with something like so
    PHP Code:
    flvPlayback.onEnterFrame = function()
    {
        
    trace(flvPlayback.playheadTime " / " flvPlayback.totalTime);
        
        if (
    flvPlayback.playheadTime >= flvPlayback.totalTime)
        {
            
    trace("Now");
        }
    }; 

  14. #14
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    What about storing the totalTime number in a variable, then calculating the timer's interval to be that number, divided by 1 second or something?
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  15. #15
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi Cap.

    Here's a scrappy way I put togeter of displaying the times in text and doing other things, but it should help figure out your times and things.
    PHP Code:
    var listenerObject = new Object();
    listenerObject.playing = function(eventObject:Object)
    {
        
    onEnterFrame = function ()
        {
            
    TotalTime Math.floor(my_FLVplybk.totalTime);
            
    PlayedTime Math.floor(my_FLVplybk.playheadTime);
            
    // *** Playing time
            
    var PlayingMinutes Math.floor(PlayedTime 60);
            var 
    PlayingSeconds Math.floor(PlayedTime 60);
            
    // *** total time
            
    var TotalMinutes Math.floor(TotalTime 60);
            var 
    TotalSeconds Math.floor(TotalTime 60);
            
    // *** display the time in textfield
            
    PlayTime = (PlayingMinutes 10 "0" "") + PlayingMinutes ":" + (PlayingSeconds 10 "0" "") + PlayingSeconds;
            
    FullTime = (TotalMinutes 10 "0" "") + TotalMinutes ":" + (TotalSeconds 10 "0" "") + TotalSeconds;
            
    NowPlaying.text PlayTime "/" FullTime;
            
    // *** traces
            
    trace(PlayedTime " / " TotalTime);
            
    // *** when commplete
            
    if (PlayedTime >= TotalTime)
            {
                
    trace("Now");
                
    my_FLVPlybk.removeEventListener("playing",listenerObject);
                
    delete onEnterFrame;
                
    DoHold setInterval(HoldVideo2000);
                
    // 2 seconds
            
    }
        };

    };

    my_FLVplybk.addEventListener("playing",listenerObject);

    function 
    HoldVideo()
    {
        
    clearInterval(DoHold);
        
    my_FLVplybk._alpha 50;
        
    unloadMovie(TheArea);
        
    trace("Unloaded");
        
    NowPlaying.text "";


  16. #16
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi Cap,

    Hers how to do it without the ugly onEnterFrame being used
    PHP Code:
    var PlayListener = new Object();
    PlayListener.playheadUpdate = function(eventObject:Object)
    {
        
    TotalTime Math.floor(my_FLVplybk.totalTime);
        
    PlayedTime Math.floor(my_FLVplybk.playheadTime);
        
    // *** Playing time
        
    var PlayingMinutes Math.floor(PlayedTime 60);
        var 
    PlayingSeconds Math.floor(PlayedTime 60);
        
    // *** total time
        
    var TotalMinutes Math.floor(TotalTime 60);
        var 
    TotalSeconds Math.floor(TotalTime 60);
        
    // *** display the time in textfield
        
    PlayTime = (PlayingMinutes 10 "0" "") + PlayingMinutes ":" + (PlayingSeconds 10 "0" "") + PlayingSeconds;
        
    FullTime = (TotalMinutes 10 "0" "") + TotalMinutes ":" + (TotalSeconds 10 "0" "") + TotalSeconds;
        
    NowPlaying.text PlayTime "/" FullTime;
        
    // *** traces
        
    trace(PlayedTime " / " TotalTime);
    };

    my_FLVplybk.addEventListener("playheadUpdate",PlayListener);

    var 
    CompleteListener = new Object();
    CompleteListener.complete = function(eventObject:Object)
    {
        
    trace("Now");
        
    my_FLVPlybk.removeEventListener("playheadUpdate",PlayListener);
        
    DoHold setInterval(HoldVideo2000);// 2 seconds
        
    NowPlaying.text "";
    };

    my_FLVplybk.addEventListener("complete",CompleteListener);

    function 
    HoldVideo()
    {
        
    my_FLVPlybk.removeEventListener("complete",CompleteListener);
        
    clearInterval(DoHold);
        
    my_FLVplybk._alpha 50;
        
    unloadMovie(TheArea);
        
    trace("Unloaded");


  17. #17
    Senior Member
    Join Date
    Jan 2007
    Location
    Barcelona
    Posts
    389
    hi, FruitBeard,

    I hadn't been in the forum for a couple of days and hadn't noticed these last posts. Thanks, I will look at them.

  18. #18
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Check out thislol.JPG i said in my mind "I MUST post this" hahaha LOL
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  19. #19
    Senior Member
    Join Date
    Nov 2001
    Posts
    1,145
    Use NetConnection for videos in AS2 (tons of tutorials). The NetStream has a stop event. When the video gets to the end, it stops and fires the event. So, as long as the user didn't hit the stop button (your code), the video ended.

    Don't use cue points for anything. You can check the video's play time if you need to: nsVideoNetStream.time

    Code:
    nsVideoNetStream.onStatus = function(infoObject:Object):Void {
      if (infoObject.code == "NetStream.Play.Stop"){
        if(user hasnt stopped the video){
           video has ended
        }
      }
    }

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