• 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.9K

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
New Here ,
Sep 03, 2012 Sep 03, 2012

Copy link to clipboard

Copied

Hi Kgald, I made the adjustments to the code, but for some reason it's reverting back to the problem I had to begin with as the video is freezing on the last frame. Here is the code 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);

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>16.2){ 

ns.seek(10.6);

};

}

No syntax errors were given, I also tried tweaking the ns.time and ns.seek numbers but to no avail, the video still freezes upon entering the last 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
Mentor ,
Sep 03, 2012 Sep 03, 2012

Copy link to clipboard

Copied

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

NetStream is not really for video on the main timeline.

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 03, 2012 Sep 03, 2012

Copy link to clipboard

Copied

Hey Adn,

The previous method before using this netstream approach was importing the FLV and extending all the frames of it in the time-line and using the "gotoAndPlay" function, this didn't work because the loop wasnt seamless, there was an annoying 1 second pause before it looped back to the frame I wanted. (see my first post)

The as3 code I'm using now is just calling up the .flv video from the folder the .FLA project file is located in, it's pure code at this point. See post 7 for a screenshot of my project area.

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 03, 2012 Sep 03, 2012

Copy link to clipboard

Copied

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.

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 03, 2012 Sep 03, 2012

Copy link to clipboard

Copied

Kgald - The frames are not extended, please refer to post 7 with my screenshot. In my project there is only one layer with a frame containing the action-script 3 we've been working with the entire time. Concerning the "16.2". I changed it to 16 but to no avail, the video still freezes on the last frame, here is the code:

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,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>16){

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
Community Expert ,
Sep 03, 2012 Sep 03, 2012

Copy link to clipboard

Copied

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

};

}

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 04, 2012 Sep 04, 2012

Copy link to clipboard

Copied

I was given this under the output tab 16.282. The FLV still freezes at the end, here's my current code 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);

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

};

}

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 04, 2012 Sep 04, 2012

Copy link to clipboard

Copied

you're not using the code i suggested.

use:

the.addEventListener(Event.ENTER_FRAME,f);

NOT

ns.addEventListener(...)

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 04, 2012 Sep 04, 2012

Copy link to clipboard

Copied

Upon testing the movie the screen goes completely white and I get a syntax error on that line -

"the.addEventListener(Event.ENTER_FRAME,f);"

"Scene 1, Layer 'actions', Frame 1, Line 6 1120: Access of undefined property the."

Here's my code:

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

addChild(video);

var nc:NetConnection = new NetConnection();

nc.connect(null);

var ns:NetStream=new NetStream(nc);

the.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>16){ 

ns.seek(10);

};

}

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
Mentor ,
Sep 04, 2012 Sep 04, 2012

Copy link to clipboard

Copied

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

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 04, 2012 Sep 04, 2012

Copy link to clipboard

Copied

that should be

this.addEventListener(...

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 04, 2012 Sep 04, 2012

Copy link to clipboard

Copied

Okay, some good news, I received the proper trace output :

16.282

14.014

14.047

14.08

14.114

14.147

14.181

14.247

14.247

14.314

14.314

14.348

14.381

14.414

14.448

14.514

14.514

14.547

14.58

14.647

14.647

14.681

14.747

14.747

14.814

14.814

14.848

14.881

14.914

14.948

14.981

15.015

15.048

15.081

15.115

15.148

15.182

15.248

15.248

15.282

15.315

15.349

15.382

15.415

15.449

15.515

15.515

15.548

15.581

15.615

15.648

15.715

15.715

15.748

15.782

15.815

15.849

15.915

15.915

15.949

15.982

16.016

16.049

16.082

16.116

16.149

16.183

16.249

16.249

14.047

14.08

14.08

14.147

14.147

Here is my current set of codes, it's looping once again, but still glitching upon hitting the last frame.

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

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.24){

ns.seek(10.61);

};

}

I tried tweaking the >16.24) and the (10.61), but no difference was made in fixing the glitch to get a seamless loop.

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 04, 2012 Sep 04, 2012

Copy link to clipboard

Copied

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?

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 05, 2012 Sep 05, 2012

Copy link to clipboard

Copied

The video has the same situation as exhibited in post 21, it gets to the last frame, loops, but it cannot exactly land on the correct time position so the loop can be smooth. There doesn't seem to be a delay/pause upon the rewind position.

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 05, 2012 Sep 05, 2012

Copy link to clipboard

Copied

you must have a keyframe at that seek location.  seek goes to the closest keyframe.  when you encode your video you can assign a keyframe.

or, you can use the flvplayback component (instead of using netstream) to play your video.  that class has a seek method that allows you to do seek to the closest 10,000th second.

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 05, 2012 Sep 05, 2012

Copy link to clipboard

Copied

You're damn right! I re-encoded my FLV with key frames at every frame, and now it's smooth as butter when I do a test movie within my Flash project. The only issue now is my publishing - when I publish my project as a .SWF in the same directory as my FLV it plays and freezes on the last-frame when I load it in a webbrowser (which will be it's final viewing format), its like the .swf isn't containing/reading the AS3 code in it. Anyway, I'm quite happy this is actually working now. Here's my code and publishing settings for reference:

AS3 code:

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

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.24){

ns.seek(10.61);

};

}

My .swf publishing settings are as follow:

Player: Flash Flayer 10

Script: ActionScript 3.0

JPEG quality 100

Audio Stream/Event: both disabled

Compress movie: off

Include hidden layers: off

Include XMP metadata: off

Export SWC: off

trace and debug: all are off

Local playback security: Access local files only (if i use the network option the .swf is blank when I load it in a webbrowser)

Hardware Acceleration: Level 2 -GPU

Script time limit: 15 seconds

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 05, 2012 Sep 05, 2012

Copy link to clipboard

Copied

what's your url?

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 05, 2012 Sep 05, 2012

Copy link to clipboard

Copied

www.mitchpatrick.com

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 06, 2012 Sep 06, 2012

Copy link to clipboard

Copied

what's that url have to do with this thread?  (but that is a nice looking html page.)

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 06, 2012 Sep 06, 2012

Copy link to clipboard

Copied

I thought you wanted me to share the URL I intend to host the .SWF you've been helping me with.  Could you be a little bit more specific, for my own sake.

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 06, 2012 Sep 06, 2012

Copy link to clipboard

Copied

you said, "..it's smooth as butter when I do a test movie within my Flash project. The only issue now is my publishing - when I publish my project as a .SWF in the same directory as my FLV it plays and freezes on the last-frame when I load it in a webbrowser..."

i wanted to see what you were testing in your browser.  so, upload your swf and embedding html to your server and post a link to the embedding html so i can view it in my browser.

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 06, 2012 Sep 06, 2012

Copy link to clipboard

Copied

Sure, I just made a html file and inserted my swf in it. It plays all the way through and stops at the last frame, but for some strange reason several seconds later it will play through the loop, pause at the last frame for a while and play the loop again, you will have to wait a moment to see it happen:

http://mitchpatrick.com/art/Int_Medium.html

And again, if I test the movie within the Flash program itself, it runs fine.

*PS: For some reason it's also a little sluggish on the first load. Basically it's boiling down to this - the .SWF file plays fine in the adobe flash player, but does not play correctly in an HTML file within Safari or Google Chrome.

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 12, 2012 Sep 12, 2012

Copy link to clipboard

Copied

Hmmm, is there no solution available to get this loop running correctly in a web-browser? The as3 code/FLV is working just fine, with no glitches, in the stand-alone flash player. 

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 12, 2012 Sep 12, 2012

Copy link to clipboard

Copied

no kidding. your bitrate is 10,000!  that's a bit much. 

who encoded that flv?  why don't you try a more reasonable bitrate like 400 or so.

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 12, 2012 Sep 12, 2012

Copy link to clipboard

Copied

Oh, I thought you left me in the dark. I encoded it, sorry I was pandering toward quality. I'll re-encode with a lower bit-rate for the web version. I'll update you with my results soon.

Thank you.

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