• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

New Here ,
Aug 30, 2012 Aug 30, 2012

Copy link to clipboard

Copied

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!

Views

84.8K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Sep 02, 2012 Sep 02, 2012

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);

           

...

Votes

Translate

Translate
Community Expert ,
Aug 30, 2012 Aug 30, 2012

Copy link to clipboard

Copied

use:

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

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

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

}

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 30, 2012 Aug 30, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 31, 2012 Aug 31, 2012

Copy link to clipboard

Copied

Any suggestions? Still in a little rut here.

-m

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 31, 2012 Aug 31, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 31, 2012 Aug 31, 2012

Copy link to clipboard

Copied

Hi again! The video's total duration is 16.282 seconds. However when it ends on the first run it needs to loop back to frame 318 (or whatever the quivalent that is in seconds). After it loops back to frame 318 it should play to the end again ( at 16.282 seconds) and then loop back to 318 ad infinitum.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 31, 2012 Aug 31, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 31, 2012 Aug 31, 2012

Copy link to clipboard

Copied

I tried the ns.seek script using seconds instead of the frame #, the project is still freezing on the last frame of the video. I took a screenshot to give a visual of my timeline / actionscript window. Maybe it will be of some assistance. If need be I can post a .swf.

Screen Shot 2012-08-31 at 1.39.33 PM.png

Here is the code once again:

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(10.18);

}

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 31, 2012 Aug 31, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 31, 2012 Aug 31, 2012

Copy link to clipboard

Copied

A little greek to me. I vaguley understand that the trace(meta.duration) is giving me the exact time length in my log when the video stops though. What line of code would I need to insert?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 31, 2012 Aug 31, 2012

Copy link to clipboard

Copied

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);

}

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 31, 2012 Aug 31, 2012

Copy link to clipboard

Copied

So, I implemented the track code as posted above. Still freezes at the final frame of the video. My output log doesn't post any new meta information besides the time length of the FLV video. Please advise if those two lines of code need to be adjusted/changed in anyway.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 01, 2012 Sep 01, 2012

Copy link to clipboard

Copied

there's a problem with your flv.

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

and change your seek to 3 or 4.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 01, 2012 Sep 01, 2012

Copy link to clipboard

Copied

Okay, I downloaded the water.flv, i had no problems playing the video in the FLV video player (so no problems with the FLV itself). I then moved water.flv into my project directory. Upon moving the water video into the project directory I changed the actionscript lines "ns.seek(4);"  and the  "ns.play(filename);" as you suggested. The same issue happens, the video plays and freezes on the last frame. Here is my code again for reference:

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

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

trace(obj.code);

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

trace("seek");

ns.seek(4);

}

}

I also decided to run a debug on the FLV video in flash, using the debug movie command and I received this bit of output:

Attempting to launch and connect to Player using URL /Users/mitchp*****/Desktop/ART/Art (DO NOT DELETE!)/Digital work/Views/View I/L2.swf

[SWF] Users:mitchpatrick:Desktop:ART:Art (DO NOT DELETE!):Digital work:Views:View I:L2.swf - 1842 bytes after decompression

*** Security Sandbox Violation ***

Connection to All.flv halted - not permitted from file:///Users/mitchp*****/Desktop/ART/Art (DO NOT DELETE!)/Digital work/Views/View I/L2.swf

SecurityError: Error #2148: SWF file file:///Users/mitchp*****/Desktop/ART/Art (DO NOT DELETE!)/Digital work/Views/View I/L2.swf cannot access local resource All.flv. Only local-with-filesystem and trusted local SWF files may access local resources.

          at flash.net::NetStream/play()

          at L2_fla::MainTimeline/frame1()[L2_fla.MainTimeline::frame1:25]

From reading this, and from what I can understand, it seems like it's having an issue with  file system / access permissions. I think this debug log is pointing to the possible culprit, and hopefully a solution can be made!

Thanks for sticking with me. Let me know if I can corroborate any more details.

-m

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 01, 2012 Sep 01, 2012

Copy link to clipboard

Copied

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);

}

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 01, 2012 Sep 01, 2012

Copy link to clipboard

Copied

For the coded you provided above the trace output is 7.347. No the video continues to freeze on the last frame, eventhough it's accessing it from a URL. This is strange.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 01, 2012 Sep 01, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 01, 2012 Sep 01, 2012

Copy link to clipboard

Copied

Flash CS 5 (11.0.2.489) I am publishing it as a .swf to be embedded in an html file for a website.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 02, 2012 Sep 02, 2012

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 02, 2012 Sep 02, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 02, 2012 Sep 02, 2012

Copy link to clipboard

Copied

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;

        }

};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 02, 2012 Sep 02, 2012

Copy link to clipboard

Copied

Okay this did the trick! Just one detail that makes all the differenence. Fortunately there is no 1 second pause in the loop which is perfect, however there is a glitch, and I don't know if this is just the nature of the program or it's exsisting in some form of as3 syntax. I've provided a link for reference:

http://mitchpatrick.com/INT.swf

I determined the exact time it needs to hit for it to be a perfect palindrome loop, I programmed it to loop back to (frame 319) in seconds that is 10.6106, so in theory it should be looping seamlessly. However it's glitching, and I've toyed around with the timecode in the "ns.seek" line, but it seems nearly impossible due to the fact that I can get so damn infinitesimal with those numbers. Here is the code for further reference:

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(10.6106);

              break;

        }

};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 02, 2012 Sep 02, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 02, 2012 Sep 02, 2012

Copy link to clipboard

Copied

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);

ns.addEventListener(Event.ENTER_FRAME,);  <-----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 netStatusF(e:NetStatusEvent):void {

        switch (e.info.code) {

              case "NetStream.Play.Stop":

              ns.seek(10.6106);

              break;

        }

};

Hmmm, curious about where the"loop" and ns.time syntax should be placed.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 02, 2012 Sep 02, 2012

Copy link to clipboard

Copied

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);

};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines