Skip navigation
Currently Being Moderated

Getting a FLV to loop back toward a specific frame using Netstream (as3)

Aug 30, 2012 9:15 AM

Tags: #help #as3 #flv #netstream #loop

To preface this my knowledge of AS3 is quite novice. As the thread titled reads, I'm trying to get an FLV to play through it's entireity and then loop back towards a specific frame and keep replaying from the point endlessly. After a lot of digging I found a video tutorial using AS3 that worked! Here's my situation now though, I cannot find the right code to insert to make the video loop back to the frame that I want. The FLV just stops and doesnt rewind at the end of the video. Here is my code so far:

 

var video:Video = new Video(1980, 1020);
addChild(video);


var nc:NetConnection = new NetConnection();
nc.connect(null);


var ns:NetStream = new NetStream(nc);


var meta:Object = new Object ();
meta.onMetaData = function (meta: Object)
{
          trace(meta.duration);
}


ns.client = meta;


video.attachNetStream(ns);


ns.play("All.flv");

 

 

Ultimately, the video needs to play all the way through only on the first load and then loop back to frame 319 and play toward the end and loop back again to frame 319 infinitely. I think I'm almost there, I just need some assistance with getting my code working appropriately. I done this before using "gotoAndPlay()" but the loop isnt seamless thus it yields a one second pause before looping back. I'm hoping using a Netstream function that this will be resolved. I would appreciate any help!

 
Replies 1 2 Previous Next
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 30, 2012 9:23 AM   in reply to mitwyatt85

    use:

     

    meta.onPlayStatus = function(obj:Object):void{

    if(obj.code=="NetStream.Play.Complete"){

    ns.seek(time closest to your seek frame);

    }

    }

     
    |
    Mark as:
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 31, 2012 9:51 AM   in reply to mitwyatt85

    does your video have a duration > 318 seconds?  ie, that trace out is > 318?

     
    |
    Mark as:
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 31, 2012 10:19 AM   in reply to mitwyatt85

    again,

     

    ns.seek(time closest to your seek frame);

     

    you need to find the time (in seconds) that closest to whatever frame you want.  experiment if you don't want to use a cuepoint.

     

    p.s.  please mark helpful/correct responses.

     
    |
    Mark as:
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 31, 2012 12:43 PM   in reply to mitwyatt85

    use the trace function to confirm that seek method is executing.  if it is, then the end of your video is the closest keyframe to that location in your video.

     
    |
    Mark as:
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 31, 2012 9:31 PM   in reply to mitwyatt85

    what's the trace output from:

     

     

    var video:Video = new Video(1980, 1020);

    addChild(video);

     

     

    var nc:NetConnection = new NetConnection();

    nc.connect(null);

     

     

    var ns:NetStream = new NetStream(nc);

     

     

    var meta:Object = new Object ();

    meta.onMetaData = function (meta: Object)

    {

              trace(meta.duration);

    }

     

     

    ns.client = meta;

     

     

    video.attachNetStream(ns);

     

     

    ns.play("All.flv");

    meta.onPlayStatus = function(obj:Object):void{

    trace(obj.code);

    if(obj.code=="NetStream.Play.Complete"){

    trace("seek");

    ns.seek(10.18);

    }

    }

     
    |
    Mark as:
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 1, 2012 7:28 AM   in reply to mitwyatt85

    there's a problem with your flv.

     

    try:  http://www.helpexamples.com/flash/video/water.flv

     

    and change your seek to 3 or 4.

     
    |
    Mark as:
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 1, 2012 9:45 AM   in reply to kglad

    what's the trace output using the following and does water.flv continually loop?:

     

     

     

     

    var video:Video = new Video(1980, 1020);

    addChild(video);

     

     

    var nc:NetConnection = new NetConnection();

    nc.connect(null);

     

     

    var ns:NetStream = new NetStream(nc);

     

     

    var meta:Object = new Object ();

    meta.onMetaData = function (meta: Object)

    {

              trace(meta.duration);

    }

     

     

    ns.client = meta;

     

     

    video.attachNetStream(ns);

     

     

    ns.play("http://www.helpexamples.com/flash/video/water.flv");

    meta.onPlayStatus = function(obj:Object):void{

    trace(obj.code);

    if(obj.code=="NetStream.Play.Complete"){

    trace("seek");

    ns.seek(2);

    }

    }

     
    |
    Mark as:
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 1, 2012 11:06 AM   in reply to mitwyatt85

    what flash cs version are you using and what fp are you publishing for?

     
    |
    Mark as:
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 2, 2012 9:38 AM   in reply to mitwyatt85

    interesting.

     

    the onPlayStatus fails in cs versions prior to cs6.  that used to work, i am sure.

     

    in any case, there's a work around.  is there any way your flv can stop playing other than when it completes play?  ie, is there a stop button or a button to switch play to another flv?

     
    |
    Mark as:
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 2, 2012 10:13 AM   in reply to mitwyatt85

    then you can use:

     

    var video:Video=new Video(1980,1020);

    addChild(video);

    var nc:NetConnection = new NetConnection();

    nc.connect(null);

    var ns:NetStream=new NetStream(nc);

    ns.addEventListener(NetStatusEvent.NET_STATUS, netStatusF);

    ns.client = this;

     

    video.attachNetStream(ns);

    ns.play("All.flv");

     

    function onMetaData(obj:Object):void{

        trace(obj.duration);

    }

     

    function netStatusF(e:NetStatusEvent):void {

            switch (e.info.code) {

                  case "NetStream.Play.Stop":

                  ns.seek(2);

                  break;

            }

    };

     
    |
    Mark as:
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 2, 2012 3:06 PM   in reply to mitwyatt85

    if you want to make a seamless loop, use an enterframe loop to repeatedly check ns.time.  when that reaches the end (or just prior to the end, executed that seek() method.

     

    remove the netStatus listener if you use that.

     
    |
    Mark as:
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 2, 2012 7:16 PM   in reply to mitwyatt85

    use:

     

     

    mitwyatt85 wrote:

     

    Okay let me try and get this checked through you before I attempt to implement what you've recommend for a seamless loot at the aformentioned time in the previous post:

     

    var video:Video=new Video(1980,1020);

    addChild(video);

    var nc:NetConnection = new NetConnection();

    nc.connect(null);

    var ns:NetStream=new NetStream(nc);

    ns.addEventListener(

    var video:Video=new Video(1980,1020);

    addChild(video);

    var nc:NetConnection = new NetConnection();

    nc.connect(null);

    var ns:NetStream=new NetStream(nc);

    this.addEventListener(Event.ENTER_FRAME,f);  <-----not too sure about the rest of the syntax here

    ns.client = this;

    video.attachNetStream(ns);

    ns.play("All.flv");

    function onMetaData(obj:Object):void{

     

     

        trace(obj.duration);

     

     

    }

    function f(e:Event):void {

    if(ns.time>16){  // tweak both these numbers to get close to what you want.

    ns.seek(10.6);

    };

     

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 3, 2012 8:58 AM   in reply to mitwyatt85

    Loop back to a frame? Is the video embedded into the timeline?

    NetStream is not really for video on the main timeline.

     
    |
    Mark as:
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 3, 2012 11:31 AM   in reply to mitwyatt85

    don't use 16.2.  that may not be reached.  use 16, for example.

     
    |
    Mark as:
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 3, 2012 11:33 AM   in reply to mitwyatt85

    what do you mean by "you extended the frames of the timeline"???  don't do that.  this is a one frame app.

     

    remove those main timeline frames so that code does NOT re-executed.  and go back to the original code because re-executing that code may be the entire problem.

     
    |
    Mark as:
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 3, 2012 10:44 PM   in reply to mitwyatt85

    what's the trace output (don't include the repeat values at the end):

     

     

    980,1020);

    addChild(video);

    var nc:NetConnection = new NetConnection();

    nc.connect(null);

    var ns:NetStream=new NetStream(nc);

    ns.addEventListener(Event.ENTER_FRAME,f);

    ns.client = this;

    video.attachNetStream(ns);

    ns.play("All.flv");

    function onMetaData(obj:Object):void{

     

     

    trace(obj.duration);

     

     

    }

    function f(e:Event):void {

    if(ns.time>14){

    trace(ns.time);

    }

    if(ns.time>16){

    ns.seek(10.6);

    };

    }

     
    |
    Mark as:
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 4, 2012 7:09 AM   in reply to mitwyatt85

    you're not using the code i suggested.

     

    use:

     

    the.addEventListener(Event.ENTER_FRAME,f);

     

    NOT

     

    ns.addEventListener(...)

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 4, 2012 9:03 AM   in reply to mitwyatt85

    Since this thread seems to be dragging on with no resolution, I'll throw in my two cents worth.

    It's very easy to loop a NetStream video... at least in AS2.. perhaps you can use/adapt this working code:

    /* Video player created by CI Digital Media for educational purposes */
    stop();
    var nc:NetConnection = new NetConnection();
    nc.connect(null);

    var ns:NetStream = new NetStream(nc);
    video_screen.attachVideo(ns);
    /* Name of your video, with correct path, goes here */
    ns.play("loop_vid.flv");

    ns.onStatus = function(info) {
      if(info.code == "NetStream.Play.Stop") {
      trace("Video complete")
        ns.seek(20);
      }
    }

    See in action here:

    http://www.cidigitalmedia.com/tutorials/loop_vid/loop_vid.html

    Of course there are multiple other things you could also do at the end of the video, for example:

    ns.onStatus = function(info) {

      if(info.code == "NetStream.Play.Stop") {

      trace("Video complete")

        ns.seek(60);

    //  ns.play();

      ns.pause();

    //  gotoAndStop("end");

      getURL("http://www.cidigitalmedia.com/video.html", "_blank");

      }

    }

    You could seek and then pause the video at a certain place.

    You could jump to another part of the main time and display/play something else after video is over,

    or you could open another Web page upon completion of the video.

    All very useful stuff... NetStream is a very versatile and powerful way to work with video.

    Again, examples above are AS2.

    Best wishes,

    Adninjastrator

     
    |
    Mark as:
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 4, 2012 9:55 AM   in reply to mitwyatt85

    that should be

     

    this.addEventListener(...

     
    |
    Mark as:
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 4, 2012 11:19 PM   in reply to mitwyatt85

    that's about the best you can do. 

     

    you could increase your frame rate but you really need to analyse the "glitch".  is there a delay between the end and the rewind?  is there a failure of the end and the rewind position to exactly match?

     
    |
    Mark as:
1 2 Previous Next
Actions

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points