1 Reply Latest reply on May 11, 2012 9:43 AM by Ned Murphy

    playing multiple flvs - array - listener

    ekora

      I have a custom built flv player, and I'm trying to play a few videos, one after another.  I'm using CS5, AS2...  here is what I have, but it's mostly hacked together based off of other people's code...

       

      //Create Net Connection object

      var nc:NetConnection = new NetConnection();

       

      //Tells Flash we're not using Flash Media Server

      nc.connect(null);

       

      //Create a Net Stream object

      var ns:NetStream = new NetStream(nc);

       

      //Attach Net Stream to embedded video object

      video.attachVideo(ns);

       

      //Create a video array to play multiple videos

      var GFYplaylist:Array = new Array();

      GFYplaylist[0] = "BAN15.f4v";

      GFYplaylist[1] = "STW15.f4v";

      //GFYplaylist[2] = "part3.flv";

      var currentlyPlaying:Number = 0;

       

      //Listener for array or playlist

      //import mx.video.*;  this first line is one that I don't understand - I temporarly have it commented out

      var listenerObject:Object = new Object();

      listenerObject.complete = function(eventObject:Object):Void {

          currentlyPlaying++;

          if (GFYplaylist.length > currentlyPlaying) {  // Resets counter if reaches end of array

              currentlyPlaying = 0;

          }

          ns.play(GFYplaylist[currentlyPlaying]);

      };

      ns.addEventListener("complete", listenerObject);

       

      //link player to FLV - this is what I had before the array

      ns.play("BAN15.f4v");

       

      Any thoughts? 

       

      Thanks in advance

        • 1. Re: playing multiple flvs - array - listener
          Ned Murphy Adobe Community Professional & MVP

          Here's a different approach using onStatus... due to translating it to your variables, there might be some naming issues, but overall, it should work if you can catch/fix any if there are.

           

          //Create Net Connection object

          var nc:NetConnection = new NetConnection();

           

          //Tells Flash we're not using Flash Media Server

          nc.connect(null);

           

          //Create a Net Stream object

          var ns:NetStream = new NetStream(nc);

           

          //Attach Net Stream to embedded video object

          video.attachVideo(ns);

           

          //Create a video array to play multiple videos

          var GFYplaylist:Array = new Array();

          GFYplaylist[0] = "BAN15.f4v";

          GFYplaylist[1] = "STW15.f4v";

          //GFYplaylist[2] = "part3.flv";

          var currentlyPlaying:Number = 0;

           

                   ns.onStatus = function(infoObject:Object) {
                       for (var prop in infoObject) {
                            if(infoObject[prop] == "NetStream.Play.Stop"){
                                video.attachVideo(ns);
                                ns.play(GFYplaylist[currentlyPlaying]);
                                ncount += 1;
                                if(currentlyPlaying== GFYplaylist.length){
                                     currentlyPlaying = 0; // to start over from the first
                                }
                           }
                      }
                 }

           

                 // kick things off

                 video.attachVideo(ns);
                 ns.play(GFYplaylist[currentlyPlaying]);
                 currentlyPlaying += 1;

          1 person found this helpful