12 Replies Latest reply on Oct 3, 2006 1:52 PM by Rothrock

    Video Player, multiple movies

    Mister Peanut Level 1
      Hello, I have made a video player that plays flv videos. I would like to attach more videos to the player with a series of buttons. I'm pretty sure this is not the right way to do it. Can anyone help me with how to name and attach other videos into my theVideo instance? Here is what I'm using, which works great for 1 video, but not my ns2 video


      var nc:NetConnection = new NetConnection();
      nc.connect(null);

      var ns:NetStream=new NetStream(nc);
      var ns2:NetStream=new NetStream(nc);

      theVideo.attachVideo(ns);

      ns.play("Corrina.flv");
      ns2_btn.onRelease = function(){
      ns.play("Charlene.flv", 0);
      }
        • 1. Re: Video Player, multiple movies
          Mister Peanut Level 1
          Please, any help....
          • 2. Re: Video Player, multiple movies
            Rothrock Level 5
            So what progress have you made yourself in the last three hours?

            Remember everyone here is a volunteer and sometimes you may need to wait a bit. If you don't get answers in a day perhaps a bump with what YOU have learned, tried, search is a good idea.

            That being said, you are very close. For a basic kind of video player you will need only one NetStream – you only have one video object, theVideo, right? So why would you need more than one NetStream.

            Check out the help files for the NetStream class. There you will find the one extra thing I thing you need: NetStream.close(). That allows you to close out/stop a stream. So you can then use the same stream with another video.

            Also your second ns.play seems to have the wrong number of arguments. NetStream.play() only takes one and it is the path to the file. So I think that section should be written something like this:

            ns2_btn.onRelease=function(){
            ns.close();
            ns.play("Charlene.flv");
            }

            There are quite a few ways this could be expanded and made more robust, but lets get it working first and get the basics down.
            • 3. Re: Video Player, multiple movies
              Mister Peanut Level 1
              I apologize for the rush. If I do learn something after I post a question, I do immediately post what I've learned. I am under a big deadline as well, and really need to find something to set me straight. Part of the reason I am posting so many times is that I have realised that the website I have made will not work because of buggy scene problems, and am desperately trying to restructure the website by loading everything into single video players. Basically, everything I've done with the scenes has to be scrapped and redone. Again, I am sorry if I seem pushy, and appreciate the help more than anything. I am trying to do research, constantly looking through archives, the help menu, and flashmove.com.

              Okay, I will try to figure this out, sincerely. I will look at the NetStream.close and get back to you if I figure it out.

              Thanks for giving me something to go off of. I have been getting most of this code from gotoandlearn.com tutorials (they are fantastic), but it was missing anything on loading more than one into a video object. I tried to compromise with what I know(which is very little), but it only half worked.

              Cheers,

              P
              • 4. Re: Video Player, multiple movies
                Mister Peanut Level 1
                Okay, I have looked at the netStream files, and as an example they list the following code:

                close_btn.onRelease = function(){
                stream_ns.close();
                };

                this is all good, except that I don't want the video to be closed by a separate button, I want it to close when another movie button is pressed. It seems like this should be very straightforward. I put in the following actionscript:

                ns2_btn.onRelease = function(){
                ns.close();
                ns.play("Charlene.flv");
                }

                This makes sense to me. Seems like it should work.

                I even played around with an Event Listener, but I probably had it wrong. I wanted to put an event listener in to listen for the video's completion, then have the video close. No dice. It seems to me that the code you gave me should close out the video and pave the way for a new one.

                All I can think of is that it needs some sort of on complete function that will allow it to go to the next movie...

                I also tried putting an close(); after my ns.play("Corrina.flv");
                but this doesn't do anything. at the end of my Corrina video, the video is frozen. The close does not unload the video. This, I think is my problem.

                The fact that my ns3_btn does absolutely nothing leads me to believe that I have more than one mistake in the code.

                I will keep trying...
                • 5. Re: Video Player, multiple movies
                  Rothrock Level 5
                  I'm not sure I'm following you. I thought you wanted to have a button (or movieclip with button behavior) that when clicked would stop the current playing video and start another one.

                  The code I gave you and that you have shown (for ns2_btn) should work. I just opened up a video player I had been working on and added a button with that very code (okay my movie was called MarDala.flv and I called the movie clip myClip) and it worked.

                  Try it with just the ns.close(); Does it stop the video? If it doesn't then you probably have a scope problem. Meaning that the ns (an instance of the NetStream class) is not defined on the same timeline as the ns2_btn onRelease handler.

                  You can also design code for an onComplete handler to take the user to the next video in the list if they watch all the way through. But we really should get just a basic button working first.
                  • 6. Re: Video Player, multiple movies
                    Mister Peanut Level 1
                    Hello,

                    I have tried putting ns.close(); after my first bit of code. the video corrina does not even play. clicking on the ns2 button, plays my second video, "Charlene", which continues to the end where it freezes on the last frame. This is what I have:

                    var nc:NetConnection = new NetConnection();
                    nc.connect(null);
                    var ns:NetStream=new NetStream(nc);
                    theVideo.attachVideo(ns);
                    ns.play("Corrina.flv");
                    ns.close();

                    ns2_btn.onRelease = function(){
                    ns.close();
                    ns.play("Charlene.flv");
                    }
                    ns3_btn.onRelease = function(){
                    ns.close();
                    ns.play("Gabriel.flv");
                    }


                    ns3 does not work at all.

                    This is my intent: I have a scrolling menu bar with buttons on it. When the user presses any button in the menu, the corresponding video will play in theVideo. I wand the viewer to be able to load any movie into theVideo at any time.

                    Does onComplete work for FLV videos? This may just work.
                    • 7. Re: Video Player, multiple movies
                      Rothrock Level 5
                      Are you understanding what ns.close does at all? Let's read your code line by line.

                      Create a new NetConnection and call it nc. (might want to get rid of the var.)

                      Tell the new nc that it is going to be used for progressive download and not with an actual streaming server.

                      Create a new Netstream and call it ns. It will be associated with the nc netconnection. (also get rid of the var here)

                      Attach the ns video stream to the instance of a video object called theVideo.

                      Tell the NetStream called ns to find the file located at Corrina.flv and start playing it back through the ns connected to theVideo.

                      Now this is the part that makes me think you aren't understanding. Immediately after you tell it to find the file Corrina.flv you immediately tell Flash: take the ns Netstream and close it, stop the playback, and set the playhead to playtime of zero. OF COURSE it doesn't even play. That is what you are telling it to do!

                      The good news is that your second button works, Which is correct. The third button should work – it has exactly the same code as the other one. Unless there is no Gabriel.flv. Try switching the names of the files in the play statements in ns2_btn. What happens then?

                      First line you attach an onRelease event handler function to a button.

                      You tell the netstream object called ns to close whatever (if anything) that it is playing. (You might think Flash does this automagically when you switch sources, but it doesn't.)

                      You tell ns that it is now going to find the file "Charlene.flv" and play that.

                      All good.

                      So I really see two needs here, the buttons and autoplay when you get to the end of any given video. The two things aren't incompatible.

                      Again, check the help files. You will notice in the NetStream class documentation there is no onComplete event. That is part of the MediaDisplay components. For the the NS class the only thing that really looks like an event is called NetStream.onStatus.

                      There you will find some code to define a handler and get the object it returns. You will be looking for the one called stop.

                      One thing you may want to do is set aside your current project and start with a simple file that has just one frame, one brand new video object, and a few copies of the same "button" (I prefer to use movieclips). Just to make sure there aren't other things that are interfering with this working.

                      Make sure all you FLVs are in the correct folder – the same folder as the swf for testing and the same folder as the html for web.
                      • 8. Re: Video Player, multiple movies
                        Mister Peanut Level 1
                        > Are you understanding what ns.close does at all? Let's read your code line by line.

                        No, not really. I know that it closes the connection, but I'm not sure how to control it so that it closes the video on after the video has finished playing. There is a property that says onStatus.Play.Stop, but again, I don't know what to do with it. This is what I tried

                        onStatus.Play.Stop = function(){
                        ns.close();
                        }

                        which does nothing after the video completes.

                        Okay, some good news. The Gabriel.flv is not working for some reason. Another video, Jay.flv does work. So at least I know the buttons are working. Yes, Gabriel.flv is in the same folder as everything else, there are no type-o's, or anything strange. In fact, it plays fine in another swf file. I will try to replace the file, but for the time being, I'll use others.

                        So the buttons work, only there are errors when I get rid of the vars. So the only thing I am trying to accomplish is to have the video disappear when it finishes playing. That's all.

                        This is a brand new video player. I used a tutorial to create the video player, and it has a scrubber bar, buffer bas, status bur, etc. It has good functionality, and everything works fine. The tutorial did not show how to attach more than one movie, though from other buttons. It is not a part of my project yet. I am using copies of the same button. There is nothing external to mess it up.

                        Thanks again for all of your insight. I appreciate all of the help.

                        I will continue searching for solutions...

                        P
                        • 9. Re: Video Player, multiple movies
                          Rothrock Level 5
                          At the bottom of the NetStream.onStatus entry there should be some code. You'll need to change stream_ns (their name for the instance of a NetStream) to your "ns".

                          The onStatus event happens for those several things they list – buffer being full, playing, and of course stop. Whenever the event happens it will return and object to the event handler function that you have defined. Notice the part of the sample code where it says:

                          stream_ns.onStatus=function(infoObject)

                          For our purposes right now, we are are only interested in when

                          ns.onStatus = function(infoObject) {
                          if(infoObject=="NetStream.Play.Stop"){
                          ns.close();
                          //whatever code to make the next one play
                          }
                          }

                          Oh on the var issue. I was thinking the problem might somehow be that the objects you were creating were specific to some timeline (what var does) and that you weren't being able to get them from some other scope.

                          Also I never use "strict typing" but if you do you need to use the var keyword.

                          Occasionally i think I've had the mysterious "it works in one swf, but not another FLV" problem. Usually a restart sets it right. Good luck!

                          • 10. Re: Video Player, multiple movies
                            Mister Peanut Level 1
                            Okay - Great news!

                            The following code works. I had tried yours, but no dice. It was closer than I'd ever get otherwise, though. I found this snippet online, but, of course, it doesn't make sense to me. For example, I don't know what .code means, or where it comes from, but without it, nothing works.

                            ns.onStatus = function(infoObject) {
                            if(infoObject.code=="NetStream.Play.Stop"){
                            ns.close();
                            theVideo.clear();
                            }
                            };


                            Can you shed any light on ".code"?

                            I haven't seen this anywhere else, but it works now.

                            Cheers for all the help you've given!!
                            • 11. Re: Video Player, multiple movies
                              Mister Peanut Level 1
                              Thanks, Rothrock,

                              without your help, I would've been stuck on this for days.

                              P
                              • 12. Re: Video Player, multiple movies
                                Rothrock Level 5
                                Whoops my bad. I had forgotten exactly how it was written. The infoObject IS an object. That means it is sort of a container that can have many properties, variables, etc. inside of it. So you can't compare it in the way you say compare a simple string or number.

                                So the .code is looking inside the object for a property/variable named code. Just like:

                                myClip._x

                                Looks inside myClip (a clip, sure, but also an object – everything in Flash is an object) for the property called _x.

                                If you ever need to see all the things inside an object you can use code like this:

                                for (var prop in infoObject) {
                                trace("\t"+prop+":\t"+infoObject[prop]);
                                }

                                Of course you would replace infoObject (in both spots) with the name of whatever object – movieclip, array, etc. – that you wanted.