9 Replies Latest reply on Jun 4, 2010 1:47 AM by eerkmans

    Problem with multi video player

    SynZeda

      I built a player that has menus and has several videos that you can watch.  It plays great locally and on a server.  My problem is that once you start to watch a few of the videos and try and go back to the menu sometimes the audio keeps on playing.  The player also slows down after a few clicks as well.  Does anyone have an idea on how to prevent this?  Do i need to build a pre-loader or maybe change the code around some way?  I am not really looking for someone to fix it for me.  Maybe just point me in the right direction as I am trying to learn action script 3.0 and flash so the more resources I can draw from to learn the better.  The link to the player is www.synergydigitalsolutions.com/drgoldman/drgoldman.html .  Any help or pointers would be great.  Thanks in advance.

        • 1. Re: Problem with multi video player
          eerkmans

          It looks like your videostreams keep running even when they're not visible.

           

          When the user clicks the 'back' arrow, you should stop all streams currently running. (I believe you can set the contentPath to "" with the standard video player). Then you should remove the video player from the stage using "removeChild(myVideoPlayer)".

           

          When the user clicks a new video you can add the player again using "addChild(myVideoPlayer)", and then setting the player to the right stream using "contentPath=myvideo.f4v".

           

          This way you'll never have more than 1 stream running at a time.

          • 2. Re: Problem with multi video player
            SynZeda Level 1

            Thank you very much for your help!

             

            Ok so correct me if im totally off base.  I could put these commands in the button function right? 

             

            This is the button i have to go to a video

             

            pageTwo.addEventListener(MouseEvent.CLICK,clickSection);

            function clickSection(evtObj:MouseEvent)

                 {

            gotoAndStop (evtObj.target.name);

            }

             

            So would i put the code of "addChild(myVideoPlayer)" and  "conetentPath=myvideo.flv" In that button function? Or does it make more sense to put it in the frame that it jumps to so it loads content and child when it hits the frame?

             

            Then for the back button i have.

             

            Back.addEventListener(MouseEvent.CLICK,clickBack);

            function clickBack(evtObj:MouseEvent) {

            firstVideo_mc.firstVideo.stop();

            gotoAndStop (evtObj.target.name);

            }

             

            Would i replace firstVideo_mc.firstVideo.stop() with "removeChild(myVideoPlayer)" ?

             

            If I am so far behind your thinking that you really dont want to waste the time helping me could you point me to a tutorial or something for this?  I really hope I'm on the right path. 

            • 3. Re: Problem with multi video player
              eerkmans Level 1

              You can find basic examples of 'addChild' and 'removeChild' on sites like actionscript.org.

               

              Your code seems to be timeline based, the menu buttons jump to different frames in the timeline. When you click 'back' the player stops and the main timeline goes back to the frame with the menu. Correct?

               

              The problem seems to be that the videostreams aren't properly terminated when the playhead jumps to a different frame in the timeline.

               

              Using 'addChild' and 'removeChild' to add the video player could still work, you might try the following:

               

              - remove one of the movieplayers from the stage but keep it in the library. In the library, open the movieplayers properties and check 'export for actionscript'. Give the movieplayer a name like "myMovie1".

               

              - then, in the same frame where you removed the movieplayer, create an empty keyframe, click it, and add the actionscript:

               

              currentMovie = new myMovie1();

              addChild(currentMovie);

               

              This should add the movieclip from the library instead of having it in the timeline.

               

              The next problem is how to remove the player when the user clicks 'back'. Click the frame in the timeline where the main menu is, and click on an empty keyframe. Add the following actionscript to that keyframe:

               

              if(currentMovie != null) removeChild(currentMovie);

               

              I'm not sure if this will work, because I can't look into your FLA file from here :-)

               

              The main thing to consider is that you should remove the entire movieplayer from the timeline before starting a new movieplayer.

               

               

               

              1 person found this helpful
              • 4. Re: Problem with multi video player
                SynZeda Level 1

                Thanks again. 

                 

                Yes your right about the structure of the .swf

                by movieplayer are you talking about the skin that i picked when i imported the video? I already have a entire layer with actions and labels on it.  Can i put that code there or does it need to be on the actual layer of the videos in the menu and/or solo video?  I'll give it a whirl.  Big help there man.

                • 5. Re: Problem with multi video player
                  eerkmans Level 1

                  I mean the entire movieclip on the stage that contains the video player

                   

                  I'm afraid it's kind of hard to give good advice without looking at the actual FLA and knowing how you put it together. Did you script it yourself or did you use a tutorial / example FLA? Did you import the video straight into the FLA or is it coming from a server? etc. etc.

                  • 6. Re: Problem with multi video player
                    candronn

                    whats the problem

                     

                    <a href="http://www.hikayesi.org/>seks hikayeleri</a> - <a href="http://www.hikayesi.org/>sex hikayeleri</a>

                    • 7. Re: Problem with multi video player
                      SynZeda Level 1

                      I build it myself.  I picked up a copy of adobe classroom in a book, watched

                      a few tutorials from lynda.com and poked around on forums to get as far as I

                      am now.  This it my first attempt at a multi video player.  I spend most of

                      my time in AE.

                       

                      I understand its hard to trouble shoot it with out looking at my files.

                      Thank you for all your help.  Ill go to your link and see what I can learn.

                      I wonder if there is a stopAndUnload or something so I don't have to rebuild

                      the whole thing useing the child method as I am not really charging for my

                      efforts with this player.  If not then ill just rebuild it using that child

                      function you pointed me to sir.  Thanks again.

                      • 8. Re: Problem with multi video player
                        SynZeda Level 1

                        Ok so i tried the

                         

                        on the home page(frame 1)

                         

                        if(currentMovie != null) removeChild(currentMovie)

                         

                         

                        currentMovie = new movieOne();

                        addChild(currentMovie);

                         

                         

                        frame thats labeled so a button can jump to it using obj name

                         

                        I started over as to not have any code that could mess up this.  I made 2 buttons that go from one frame to the other.  I imported to library a video.  It placed it on the stage anyway so i deleted it.  Renamed the fla in the library to movieOne.  Once i went to test if i could just go from no video, to video it came up with an error.  5 actually.

                        2 cases of....

                             1120: Access of undefined property currentMovie.  if(currentMovie != null) removeChild(currentMovie)

                        in frame 1 line 1  (the home frame)

                         

                        1 case of

                             1120: Access of undefined property currentMovie.  currentMovie = new movieOne();

                        in frame 20 line 1 (the labeled one)

                         

                        1 case of

                             1180: Call to a possibly undefined method movieOne.  currentMovie = new movieOne();

                        in frame 20 line 1

                         

                        and lastly

                             1120: Access of undefined property currentMovie. addChild(currentMovie);

                        in frame 20 line 2.

                         

                             So its my understanding that 1120 comes when var currentMovie:??????  is not there above  currentMovie = new movieOne();   I just have no idea what to put after  var currentMovie:  Also the 1180 is triggered from that because currentMovie is not defined correctly. Or am I totally off?  If i could impose a little more help from the community that would be wonderful.

                         

                        Thanks in advance.

                         

                        Ok I have also tried to place addChild(movieOne); on frame 20 and in the button back to frame 1.

                         

                        Open.addEventListener(MouseEvent.CLICK,clickSectionStop);

                        function clickSectionStop(evtObj:MouseEvent) {

                        removeChild(movieOne)

                        gotoAndStop (evtObj.target.name);

                        }

                         

                        that method returns

                        TypeError: Error #2007: Parameter child must be non-null.

                        at flash.display::DisplayObjectContainer/addChild()

                         

                        yep im lost.  Sorry for being so new at this.  Im just trying to learn.

                        • 9. Re: Problem with multi video player
                          eerkmans Level 1

                          It seems you have a problem with your variable not being declared, or not even existing when

                          you try to use it. You can fix this by using var, and if you're not sure what kind of var you're

                          declaring, you can omit the : or use :*;

                           

                          The problem may also have to do with the way your frames are organised. A var doesn't always

                          persist when you navigate through your frames.

                           

                          Maybe I can suggest the following (not knowing exactly how your FLA is organised, this

                          seems the most fail-safe option I can come up with).

                           

                          1

                           

                          create a layer in your app that exists across ALL frames (only one keyframe at frame 1).

                           

                          2

                           

                          put an empty movieclip in there, give it the instance name "movieholder_mc"

                           

                          3

                           

                          create another layer to hold all your actionscript code. For each frame that needs code,

                          create an empty keyframe that holds nothing else but code.

                           

                          4

                           

                          now, when you want to attach your movieplayer from the library, use:

                           

                          var myPlayer = new MovieOne();

                          movieholder_mc.addChild(myPlayer);

                           

                          5

                           

                          when you want to remove the player from any frame, try:

                           

                          var removeMe = movieholder_mc.getChildAt(0);

                          if(removeMe != null) {

                               // first stop all video streams that are playing in this movieplayer

                               // the function 'stopAllVideoStreams' has to exist in your videoplayer code

                               removeMe.stopAllVideoStreams();

                               // then remove the entire clip

                               movieholder_mc.removeChild(removeMe);

                          }

                           

                          We will use the empty clip to hold your movieplayer instances. You can always check if there is currently

                          a player by using functions like 'getChildAt'. If there is, you stop all streams and then remove it.

                           

                          You could also build a loop that just removes everything that is currently playing in the movieholder_mc.(just to make sure

                          you never have more than one movieplayer at a time).

                           

                          It might be a good idea to practice the above code in an empty FLA file using just a few

                          simple movieclips. If you can get that to work, try using it in your real project.

                           

                          Good luck!