7 Replies Latest reply on Jun 8, 2006 7:36 PM by Newsgroup_User

    2 videos...1 set of controls

    ManitobaMan
      I'm sort of a new user to Flash and what I'm looking to do is run 2 seperate videos at the same time with both videos being controlled by one set of buttons. So for instance, when I hit the play button it would start both videos playing at the same time and then if I hit the stop button both videos would stop at the same point. I figure that this could be done using ActionScript but everything I've tried hasn't worked at all. Any ideas?
        • 1. Re: 2 videos...1 set of controls
          Level 7
          ManitobaMan,

          Check that out. I grew up in Manitoba! Just outside of Winnipeg, in
          Beausejour. Small world.

          > I'm sort of a new user to Flash and what I'm looking
          > to do is run 2 seperate videos at the same time with
          > both videos being controlled by one set of buttons.

          Sure thing.

          > So for instance, when I hit the play button it would
          > start both videos playing at the same time and then if I
          > hit the stop button both videos would stop at the same
          > point.

          You betcha. Can do.

          > I figure that this could be done using ActionScript but
          > everything I've tried hasn't worked at all. Any ideas?

          There are a number of ways to play video in Flash, so let's start by
          determing what method you're going to employ. For example, are you using
          the FLVPlayback Component, one of the older Media Components, or maybe just
          a Video object?


          David
          stiller (at) quip (dot) net
          Dev essays: http://www.quip.net/blog/
          "Luck is the residue of good design."


          • 2. Re: 2 videos...1 set of controls
            ManitobaMan Level 1
            Hi David,

            I know Beausejour, I've been there a few times, nice place. I'm born and raised in Winnipeg myself.

            Anyways, thanks for helping me out with this. I was using the FLVPlayback Component to try to make things work but really whatever will work best because I've got the video in .flv format and in .wmv format as well. I did notice that when I played both videos at once, one video was choppy and the audio was cutting in and out. I don't know if that's because my PC isn't good enough for that or that having 2 FLVPlayback Components is too draining on the software. That's sort of a side issue though. I'm mainly concerned with just figuring out how to get 2 videos going with one set of controls.
            • 3. Re: 2 videos...1 set of controls
              Level 7
              ManitobaMan,

              > I know Beausejour, I've been there a few times,
              > nice place.

              It's a small place, for sure. Been over 20 years since I lived
              there, but I do have fond memories.

              > I'm born and raised in Winnipeg myself.

              That was always The Big City to me.

              > Anyways, thanks for helping me out with this.

              Sure thing.

              > I was using the FLVPlayback Component to try to
              > make things work but really whatever will work best
              > because I've got the video in .flv format and in .wmv
              > format as well.

              If you want to play an external video file, you'll have to use the FLV
              version. Flash imports quite a few different video file formats for
              internal playback, but that means the weight of the SWF itself will be
              affected by the embedded video. Personally, I prefer a tiny SWF that
              progressively downloads an FLV ... quicker experience overall for the user.

              Nothing wrong with the FLVPlayback Component, but keep a few things in
              mind: a) this particular Component requires Flash Player 8, which may or
              may not bother you; b) this Component stands on its own (which is the point
              of Components, of course) -- that is, its buttons are already "wired up," so
              while it *may* be possible to re-wire them for two different videos, my
              hunch is that it's easier to develop your own buttons altogether.

              > I did notice that when I played both videos at once, one
              > video was choppy and the audio was cutting in and out.
              > I don't know if that's because my PC isn't good enough
              > for that or that having 2 FLVPlayback Components is
              > too draining on the software.

              Ehh, could be either. A lot depends on the size of your videos, too, as
              well as framerate, bitrate, and so on. Generally speaking, the larger of
              any facet, the harder your computer must work to display the video.

              > I'm mainly concerned with just figuring out how to get 2
              > videos going with one set of controls.

              Here's a general, all purpose approach to Components and all objects in
              Flash: just about everything in ActionScript can be referred to as an
              object. Objects are defined by their namesake classes. For example, movie
              clips are defined by the MovieClip class; dynamic and input text fields are
              defined by the TextField class; FLVPlayback instances are defined by the
              FLVPlayback class, and so on. This also applies to non-visual objects like
              strings, dates, arrays -- the whole kaboodle.

              Classes are essentially an Owner's Manual for the object in question.
              Things the object can do are called methods; things the object reacts to are
              called events; characteristics the object has are called properties. You'll
              see one or more of these categories in practically every class entry.

              See this article for additional information along these lines ...

              http://www.quip.net/blog/2006/flash/actionscript-20/ojects-building-blocks

              ... now, for better or worse, not all classes are organized the same way in
              the documentation. FLVPlayback is one of those. The class entry for this
              object is located in the Components Language Reference and doesn't list
              methods, events, and properties on one convenient page.

              Search the documentation on the phrase "Method summary for the
              FLVPlayback class" and you'll find the methods page. Among these methods --
              remember, these are things the object can *do* -- are FLVPlayback.play(),
              FLVPlayback.pause(), and more.

              All you really need to do is drag two instance of the FLVPlayback
              Component to the Stage, set the contentPath parameter of each instance to an
              external FLV and give each instance an instance name via the Property
              inspector. Once each has a unique name, you simple "call each by name," so
              to speak, and tell it what to do.

              You could create a button of your own -- just an ordinary button symbol
              (which happens to be defined by the Button class) -- and wire up the button
              to invoke the FLVPlayback.play() method of each instance ...

              myButton.onRelease = function() {
              myVideo1.play();
              myVideo2.play();
              }

              It's that simple. Of course, both of those FLVPlayback instances will
              have their own play/pause buttons, which may get confusing. For this
              reason, I would recommend you simply use a Video object as described in this
              article here ...

              http://www.quip.net/blog/2006/flash/how-to-load-external-video

              Video objects (defined by the Video class) are fed by a combination of
              NetConnetion and NetStream class instances. It's a bit more involved than
              using the FLVPlayback class, but you'll see that it ultimately comes down to
              naming your instance and invoking the relevant method (or event, or
              property) of the object.

              I realize this may seem intimidating if you haven't done much
              programming, but read through the above articles (not very long, apiece) and
              see what you can accomplish. If you have additional questions, bring 'em
              here and I'll be happy to continue helping you.


              David
              stiller (at) quip (dot) net
              Dev essays: http://www.quip.net/blog/
              "Luck is the residue of good design."


              • 4. Re: 2 videos...1 set of controls
                ManitobaMan Level 1
                Thanks David, with your guidance I was able to figure out what I wanted to do and turns out it wasn't as hard as I was making it.
                • 5. Re: 2 videos...1 set of controls
                  Level 7
                  ManitobaMan,

                  > Thanks David, with your guidance I was able to figure
                  > out what I wanted to do and turns out it wasn't as hard
                  > as I was making it.

                  Glad to hear it!


                  David
                  stiller (at) quip (dot) net
                  Dev essays: http://www.quip.net/blog/
                  "Luck is the residue of good design."


                  • 6. Re: 2 videos...1 set of controls
                    ManitobaMan Level 1
                    Hi David,

                    I've got my 2 videos all setup under one control. What I ended up doing was using 2 seperate MediaDisplays and 1 MediaController which controls both videos. There is one final thing that I am wondering about. Is there a way to bind the two videos so that the playback of one is dependent on the playback of the other. What I'm referring to is that I noticed when I preview the end product sometimes one video takes longer to load than the other or one video will cut out momentarily while the other video keeps playing resulting in the two videos getting out of sync with each other. One video would be 2 or 3 seconds behind the other. When I use the slider and drag to a different spot in the video the 2 videos get back into sync with each other but I would like to avoid this situation altogether.

                    Is there a way to prevent this under my current setup? So for example, if video A stalls or takes longer to load then can video B pause along with it until Video A starts back up again?

                    Thanks
                    • 7. Re: 2 videos...1 set of controls
                      Level 7
                      ManitobaMan,

                      > I've got my 2 videos all setup under one control. ...

                      :)

                      > I noticed when I preview the end product sometimes
                      > one video takes longer to load than the other or one
                      > video will cut out momentarily while the other video
                      > keeps playing resulting in the two videos getting out
                      > of sync with each other.

                      I can imagine that; especially if the videos are external FLV files.

                      > When I use the slider and drag to a different spot in
                      > the video the 2 videos get back into sync with each
                      > other but I would like to avoid this situation altogether.

                      I agree -- if it can be done, avoidance would be ideal. The effect of
                      dragging the slider makes sense, actually, and already suggests to me an
                      approach toward a solution.

                      > Is there a way to prevent this under my current setup?

                      There may be. I haven't personally tried your endeavor, but in theory,
                      you should be able to repeatedly compare the Media.playheadTime property of
                      each MediaDisplay instance. If they're equal -- that is, if both videos are
                      now at 15 seconds, 16, 17, etc. -- then let them be. If they're not equal,
                      then invoke the Media.play() method on both and supply the lower of the two
                      Media.playheadTime values as the parameter for each.

                      I'm not sure if you've had the chance to read that "Objects: Your
                      ActionScript Building Blocks" article -- or maybe you already "get" how
                      objects work -- but keep in mind: your MediaDisplay Components are nothing
                      more than instances of the Media class. This means you have all the
                      properties, methods, and events of the Media class at your disposal when
                      referring to either video. Make sure each has an instance name, and refer
                      to whatever class member you need to accomplish your task.

                      > So for example, if video A stalls or takes longer to
                      > load then can video B pause along with it until Video
                      > A starts back up again?

                      You may be able to use the Media.change event as a trigger for pausing
                      one or the other instance via the Media.pause() method. If not, use
                      MovieClip.onEnterFrame on the main timeline or any MovieClip instance to
                      perform a loop. Inside that loop, check for the Media.playheadTime property
                      of both clips ...

                      // the global "this" property always refers
                      // to the timeline or object to which it is scoped
                      this.onEnterFrame = function() {
                      // if the clips' Media.playheadTime properties don't match ...
                      if (videoA.playheadTime != videoB.playheadTime) {
                      // ... check which one is lower
                      if (videoA.playheadTime < videoB.playheadTime) {
                      videoB.play(videoA.playheadTime);
                      } else {
                      videoA.play(videoB.playheadTime);
                      }
                      }
                      }

                      Again, I'm just thinking out loud, tossing about concepts. Let me know
                      if these make sense to you.


                      David
                      stiller (at) quip (dot) net
                      Dev essays: http://www.quip.net/blog/
                      "Luck is the residue of good design."