Skip to main content
Participating Frequently
August 30, 2012
Answered

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

  • August 30, 2012
  • 1 reply
  • 88805 views

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!

This topic has been closed for replies.
Correct answer kglad

There are no buttons, the video I'm trying to loop will have no interactive attributes. So the final output will just be a video (.swf) to be viewed.


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;

        }

};

1 reply

kglad
Community Expert
Community Expert
August 30, 2012

use:

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

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

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

}

}

Participating Frequently
August 30, 2012

should I implement this code after mine? Or does it need to be inserted in a specific line(s)

Thanks!

Update: I inserted the code as follows:

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{

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

ns.seek(318);

}

}

Unfortunately the video still stops and pauses in the last frame of the video. I didn't receive any compile errors though, definitely a step in the right direction.

-m

Participating Frequently
August 31, 2012

Any suggestions? Still in a little rut here.

-m