15 Replies Latest reply on Aug 16, 2010 12:54 PM by kglad

    Reset Flash After Video

    QADesign

      Hello:

       

      I have animation in Scene1 and I have button that launches the user to a video in Scene 2. In Scene2 I have the following actionscript to play the video:

       

      var nc:NetConnection = new NetConnection();

      nc.connect (null);


      var ns:NetStream = new NetStream(nc);


      theVideo.attachVideo (ns);


      ns.play("homepage.f4v");

       

       

      The video plays fine, but how do I get the Flash to reset back to Scene1, Frame 1 when it's finished?

       

      Any thoughts?

       

      Thanks!

       

      -Q

        • 1. Re: Reset Flash After Video
          kglad Adobe Community Professional & MVP

          use a loop to repeatedly check ns.time.  when ns.time is equal to your f4v's duration (you can use the onMetaData function to find the duration), use a goto method to return to frame 1.

          • 2. Re: Reset Flash After Video
            QADesign Level 1

            Okay, so that fixed the issue I was having, but then I added some controls to my video player, and now I'm back to square one. Here's my actionscript:

             

             

            // video connection - and loop back to beginning - Boom

            var duration:Number = 0;

            var nc:NetConnection = new NetConnection();

            nc.connect(null);

            var ns:NetStream = new NetStream(nc);

            theVideo.attachVideo(ns);

            ns.play("homepage.flv");


            ns.onMetaData = function(evt:Object):Void {

              duration = evt.duration;

            };

            ns.onStatus = function(evt:Object):Void {

              if (this.time > 0 && this.time >= duration) {

                trace("Video complete")

             

            gotoAndPlay("Scene 1", 1);


             

                delete this.onStatus;

              }

            }

            // Controls

            rewindButton.onRelease = function()  {

            ns.seek(0);

            }


            playButton.onRelease = function()  {

            ns.pause();

            }

            //loadbar + scrub

            var videoInterval = setInterval(videoStatus,100);

            var amountLoaded:Number;


            var duration:Number;


            ns["onMetaData"] = function(obj) {

            duration = obj.duration;

            }


            function videoStatus() {

            amountLoaded = ns.bytesLoaded / ns.bytesTotal;

            loader.loadbar._width = amountLoaded * 333.95;

            loader.scrub._x = ns.time / duration * 332;


            }


            var scrubInterval;


            loader.scrub.onPress = function() {

            clearInterval(videoInterval);

            scrubInterval = setInterval(scrubit,10);

            this.startDrag(false,2,this._y,331,this._y);

            }


            loader.scrub.onRelease = loader.scrub.onReleaseOutside = function() {

            clearInterval(scrubInterval);

            videoInterval = setInterval(videoStatus,100);

            this.stopDrag();

            }


            function scrubit() {

            ns.seek(Math.floor((loader.scrub._x/331)*duration));

            }

            Any thoughts? Thanks!!!!!

            • 3. Re: Reset Flash After Video
              kglad Adobe Community Professional & MVP

              what's the problem?  is your onStatus method failing to trigger with some event that you need to detect?

              • 4. Re: Reset Flash After Video
                QADesign Level 1

                I have no idea. I been staring at it for the past 2 hours though...haha! Once the video ends, it doesn't loop back the beginning of the animation. Your initial response worked, but I went and screwed something up after adding the controls. The video plays perfectly and the controls work; it just doesn't go back to Scene 1, frame 1.

                • 5. Re: Reset Flash After Video
                  kglad Adobe Community Professional & MVP

                  use the trace() function to debug.  first, test if the onStatus is being called.  if it is, you'll know your goto() is the problem.  if it's not, the onStatus is the problem:

                   

                   

                  oh wait.  you already have a trace("Video complete").  do you see that when the video ends?

                  • 6. Re: Reset Flash After Video
                    QADesign Level 1

                    As a matter of fact, I'm not seeing the trace. I saw it before.

                    • 7. Re: Reset Flash After Video
                      kglad Adobe Community Professional & MVP

                      do you press any buttons to cause the problem.  ie, if you don't click anything do your see your trace() output?

                      • 8. Re: Reset Flash After Video
                        QADesign Level 1

                        Nope. Nothing. It just stays on the video clip.

                        • 9. Re: Reset Flash After Video
                          kglad Adobe Community Professional & MVP

                          i copied your code, changed the name of the flv and saw no problem with the video playing and trace() output appearing when the video ended.

                           

                          i can't see any reason it would work differently for you.

                          • 10. Re: Reset Flash After Video
                            QADesign Level 1

                            Thanks for bearing with me on this. I discovered that the output message displays when the video path is locally vs. from our streaming server. Also, the video only loops with the video file I have on my desktop, which is an .f4v. It won't work with an .flv locally or remotely. I let the video play out without scrubbing to the end and it just sits idle at the end.

                            • 11. Re: Reset Flash After Video
                              kglad Adobe Community Professional & MVP

                              check for a cross-domain issue if your video is not local.  specifically, is the video's duration being returned?  if yes, use an enterframe or setInterval loop instead of an onStatus method to check for the video's end.

                              1 person found this helpful
                              • 12. Re: Reset Flash After Video
                                QADesign Level 1

                                Thanks! Not sure how to do that w/out guidance. There is no output to streaming video. Only when pulling the .f4v locally will it output a message and loop back to the beginning. I would assume this means there is a cross-domain issue.

                                 

                                How would I alter my current code to do what you suggest? It's worth a try.

                                 

                                Thanks!

                                • 13. Re: Reset Flash After Video
                                  kglad Adobe Community Professional & MVP

                                  when you stream a non-local video is you onMetaData executing and are you able to retrieve the video's duration?

                                  • 14. Re: Reset Flash After Video
                                    QADesign Level 1

                                    Yes, the code above is the code that I am using when streaming non-local video. I don't know if it is retrieving videos duration. I assume it's not, since it's not looping or following the command gotoAndPlay. The video goes to a black screen and stays idle.

                                     

                                    With the current code I have listed above, how would you suggest I change it?

                                     

                                    Thanks,

                                    Quincy

                                    • 15. Re: Reset Flash After Video
                                      kglad Adobe Community Professional & MVP

                                      the error could be an onMetadata or an onStatus (or both) failure.  use the trace function or a textfield to see which.