1 2 Previous Next 68 Replies Latest reply: Sep 14, 2012 1:55 PM by mitwyatt85 RSS

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

    mitwyatt85 Community Member

      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!

        • 1. Re: Getting a FLV to loop back toward a specific frame using Netstream (as3)
          kglad MVP

          use:

           

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

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

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

          }

          }

          • 2. Re: Getting a FLV to loop back toward a specific frame using Netstream (as3)
            mitwyatt85 Community Member

            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

            • 3. Re: Getting a FLV to loop back toward a specific frame using Netstream (as3)
              mitwyatt85 Community Member

              Any suggestions? Still in a little rut here.

               

              -m

              • 4. Re: Getting a FLV to loop back toward a specific frame using Netstream (as3)
                kglad MVP

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

                • 5. Re: Getting a FLV to loop back toward a specific frame using Netstream (as3)
                  mitwyatt85 Community Member

                  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.

                  • 6. Re: Getting a FLV to loop back toward a specific frame using Netstream (as3)
                    kglad MVP

                    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.

                    • 7. Re: Getting a FLV to loop back toward a specific frame using Netstream (as3)
                      mitwyatt85 Community Member

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

                      }

                      }

                      • 8. Re: Getting a FLV to loop back toward a specific frame using Netstream (as3)
                        kglad MVP

                        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.

                        • 9. Re: Getting a FLV to loop back toward a specific frame using Netstream (as3)
                          mitwyatt85 Community Member

                          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?

                          • 10. Re: Getting a FLV to loop back toward a specific frame using Netstream (as3)
                            kglad MVP

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

                            }

                            }

                            • 11. Re: Getting a FLV to loop back toward a specific frame using Netstream (as3)
                              mitwyatt85 Community Member

                              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.

                              • 12. Re: Getting a FLV to loop back toward a specific frame using Netstream (as3)
                                kglad MVP

                                there's a problem with your flv.

                                 

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

                                 

                                and change your seek to 3 or 4.

                                • 13. Re: Getting a FLV to loop back toward a specific frame using Netstream (as3)
                                  mitwyatt85 Community Member

                                  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

                                  • 14. Re: Getting a FLV to loop back toward a specific frame using Netstream (as3)
                                    kglad MVP

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

                                    }

                                    }

                                    • 15. Re: Getting a FLV to loop back toward a specific frame using Netstream (as3)
                                      mitwyatt85 Community Member

                                      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.

                                      • 16. Re: Getting a FLV to loop back toward a specific frame using Netstream (as3)
                                        kglad MVP

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

                                        • 17. Re: Getting a FLV to loop back toward a specific frame using Netstream (as3)
                                          mitwyatt85 Community Member

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

                                          • 18. Re: Getting a FLV to loop back toward a specific frame using Netstream (as3)
                                            kglad MVP

                                            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?

                                            • 19. Re: Getting a FLV to loop back toward a specific frame using Netstream (as3)
                                              mitwyatt85 Community Member

                                              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.

                                              • 20. Re: Getting a FLV to loop back toward a specific frame using Netstream (as3)
                                                kglad MVP

                                                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;

                                                        }

                                                };

                                                • 21. Re: Getting a FLV to loop back toward a specific frame using Netstream (as3)
                                                  mitwyatt85 Community Member

                                                  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;

                                                   

                                                   

                                                          }

                                                   

                                                   

                                                  };

                                                  • 22. Re: Getting a FLV to loop back toward a specific frame using Netstream (as3)
                                                    kglad MVP

                                                    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.

                                                    • 23. Re: Getting a FLV to loop back toward a specific frame using Netstream (as3)
                                                      mitwyatt85 Community Member

                                                      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.

                                                      • 24. Re: Getting a FLV to loop back toward a specific frame using Netstream (as3)
                                                        kglad MVP

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

                                                        };

                                                         

                                                        • 25. Re: Getting a FLV to loop back toward a specific frame using Netstream (as3)
                                                          mitwyatt85 Community Member

                                                          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.

                                                          • 26. Re: Getting a FLV to loop back toward a specific frame using Netstream (as3)
                                                            adninjastrator Community Member

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

                                                            NetStream is not really for video on the main timeline.

                                                            • 27. Re: Getting a FLV to loop back toward a specific frame using Netstream (as3)
                                                              mitwyatt85 Community Member

                                                              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.

                                                              • 28. Re: Getting a FLV to loop back toward a specific frame using Netstream (as3)
                                                                kglad MVP

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

                                                                • 29. Re: Getting a FLV to loop back toward a specific frame using Netstream (as3)
                                                                  kglad MVP

                                                                  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.

                                                                  • 30. Re: Getting a FLV to loop back toward a specific frame using Netstream (as3)
                                                                    mitwyatt85 Community Member

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

                                                                    };

                                                                    }

                                                                    • 31. Re: Getting a FLV to loop back toward a specific frame using Netstream (as3)
                                                                      kglad MVP

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

                                                                      };

                                                                      }

                                                                      • 32. Re: Getting a FLV to loop back toward a specific frame using Netstream (as3)
                                                                        mitwyatt85 Community Member

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

                                                                        };

                                                                        }

                                                                        • 33. Re: Getting a FLV to loop back toward a specific frame using Netstream (as3)
                                                                          kglad MVP

                                                                          you're not using the code i suggested.

                                                                           

                                                                          use:

                                                                           

                                                                          the.addEventListener(Event.ENTER_FRAME,f);

                                                                           

                                                                          NOT

                                                                           

                                                                          ns.addEventListener(...)

                                                                          • 34. Re: Getting a FLV to loop back toward a specific frame using Netstream (as3)
                                                                            mitwyatt85 Community Member

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

                                                                            };

                                                                            }

                                                                            • 35. Re: Getting a FLV to loop back toward a specific frame using Netstream (as3)
                                                                              adninjastrator Community Member

                                                                              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

                                                                              • 36. Re: Getting a FLV to loop back toward a specific frame using Netstream (as3)
                                                                                kglad MVP

                                                                                that should be

                                                                                 

                                                                                this.addEventListener(...

                                                                                • 37. Re: Getting a FLV to loop back toward a specific frame using Netstream (as3)
                                                                                  mitwyatt85 Community Member

                                                                                  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.

                                                                                  • 38. Re: Getting a FLV to loop back toward a specific frame using Netstream (as3)
                                                                                    kglad MVP

                                                                                    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?

                                                                                    • 39. Re: Getting a FLV to loop back toward a specific frame using Netstream (as3)
                                                                                      mitwyatt85 Community Member

                                                                                      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.

                                                                                      1 2 Previous Next