5 Replies Latest reply on Oct 23, 2006 4:14 PM by NSurveyor

    xml playlist

    raynestorm Level 1
      I need to create a simple video playlist in an xml file. I have this code that will play some video clips in a row and then loop to play them over. I need to call the actual video titles (videos.list[0] = "video/clip1.flv"; , videos.list[0] = "video/clip2.flv"; etc) from an xml file. Would someone show me how to change this code:
      videos.list = new Array();
      videos.list[0] = "video/clip1.flv";
      videos.list[1] = "video/clip2.flv";
      videos.list[2] = "video/clip3.flv";
      videos.list[3] = "video/clip4.flv";
      videos.list[4] = "";
      videos.list[5] = "";
      videos.list[6] = "";
      videos.loop = true;
      videos.length = 1;
      videos.loaded = false;

      so that videos.list = new Array(); is populated from an xml file and not hard-coded actionscript? Or does anyone know of a tutorial that shows how to create a simple xml playlist so the player just plays the clips called in the xml file full screen in a loop automatically.

      This is for progressive download.
      Thanks for any help.
      --rayne
        • 1. Re: xml playlist
          NSurveyor Level 2
          Set up your XML file like so:

          <videos>
          <v>video/clip1.flv</v>
          <v>video/clip2.flv</v>
          <v>video/clip3.flv</v>
          <!-- etc -->
          </videos>

          save that as videos.xml. Your actionscript would be:

          • 2. Re: xml playlist
            raynestorm Level 1
            Thanks so much for the help. So I have got:
            my_xml = new XML();
            my_xml.onLoad = function(s){
            if(!s){
            trace("Unable to load XML file");
            }else{
            videos.list = new Array();
            for(var i=0;i<this.firstChild.childNodes.length;i++){
            videos.list = this.firstChild.childNodes.firstChild.nodeValue;
            }
            // REST OF CODE
            // Set Videos Behavior

            // Create a videos object to hold a video
            // playlist and event handler functions...
            var videos:Object = new Object();

            // Set up to 7 video feeds in a single component
            // videos.list = new Array();
            // videos.list[0] = "vidoe/clip1.flv";
            // videos.list[1] = "";
            // videos.list[2] = "";
            // videos.list[3] = "";
            // videos.list[4] = "";
            // videos.list[5] = "";
            // videos.list[6] = "";
            videos.loop = true;
            videos.length = 1;
            videos.loaded = false;

            // Path to FLVPlayback components
            var m = this.video;

            // Set the path of the first video feed
            m.contentPath = videos.list[0];

            // Set a 'ready' event handler to load the videos
            videos.ready = function( evt:Object ):Void
            {
            if(!this.loaded){
            this.loaded = true;
            for( var n=1; n<this.list.length; n++ ){
            if( videos.list[n].indexOf(".flv") != -1 ){
            m.activeVideoPlayerIndex = n;
            m.contentPath = videos.list[n];
            this.length++;
            }
            }
            m.activeVideoPlayerIndex = 0;
            }
            }
            m.addEventListener("ready",videos);

            // Set a 'complete' event handler to load the next video
            videos.complete = function( evt:Object ):Void
            {
            var nextIndex = Number(evt.vp)+1;
            if( nextIndex == this.length){
            if( this.loop ){
            nextIndex = 0;
            }else{
            return;
            }
            }
            m.activeVideoPlayerIndex = nextIndex;
            m.visibleVideoPlayerIndex = nextIndex;
            m.play();
            }
            m.addEventListener("complete",videos);

            // End Set Videos Behavior
            // END REST OF CODE
            }
            }
            my_xml.load("videos.xml");


            The video does not show. I get that your code is correct. And the original code works, but I'm not putting them together correctly. Do I add the code to play the video where you have said //rest of code?
            Sorry to be so dense here.
            Thanks.
            --rayne
            • 3. Re: xml playlist
              The Feldkircher
              Hi

              There is a XML Video Player tutorial here XMLVidTutorial in the Tutorials Archive on the left of the screen select XML Video Playlist and enjoy.

              Hope it Helps
              • 4. Re: xml playlist
                raynestorm Level 1
                Thanks for the link to the tutorial. It plays from a list. which is populated from an xml file. I just need to play the videos straight from the xml file. So to back up and simplify, I can't figure out what goes in the " //rest of code" part of NSurveyor's answer.
                I think it should be something like this:
                my_xml = new XML();
                my_xml.onLoad = function(s){
                if(!s){
                trace("Unable to load XML file");
                }else{
                videos.list = new Array();
                for(var i=0;i<this.firstChild.childNodes.length;i++){
                videos.list = this.firstChild.childNodes.firstChild.nodeValue;
                }
                var nc:NetConnection = new NetConnection();
                nc.connect(null);

                var ns:NetStream = new NetStream(nc);

                ns.onStatus = function(info) {
                trace(info.code);
                }
                video.attachVideo(ns);

                ns.play("videos.list ");
                }
                }
                my_xml.load("videos.xml");

                But that's not quite it.
                Thanks for the help.
                --rayne
                • 5. Re: xml playlist
                  NSurveyor Level 2
                  The problem with the way you have it is "this" refers to my_xml instead of your timeline. Either replace all those this's with the correct absolute path (ie _root.etc...) OR you could try:

                  restOfCode(); // where the "//REST OF CODE" goes

                  And then, after ALL the code, place:

                  function restOfCode(){
                  //PUT YOUR CODE HERE
                  }