# XML Video Playlist Shuffle

**URL:** <https://forum.kirupa.com/t/xml-video-playlist-shuffle/254190>\
**Category:** flash\
**Created:** [March 9, 2008, 12:33pm UTC](https://forum.kirupa.com/t/xml-video-playlist-shuffle/254190 "2008-03-09T12:33:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tom5](https://avatars.discourse-cdn.com/v4/letter/t/a183cd/32.png) [@Tom5](https://forum.kirupa.com/u/Tom5)\
**Post date:** [March 9, 2008, 12:33pm UTC](https://forum.kirupa.com/t/xml-video-playlist-shuffle/254190/1 "2008-03-09T12:33:25Z")

</div>

Hello,

I have an xml video playlist that playes flv files in sequential order, one after the other. I am trying to make the playlist play random flv files (shuffle the playlist).

Could someone please help me to achieve this shuffle feature?

This is the code I have so far:

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

var ns:NetStream = new NetStream(nc);

theVideo.attachVideo(ns);

//Create array to hold all videos  
var videos\_array:Array = new Array();  
var totalVideos:Number;  
var duration:Number;

//create the XML object and populate with videos  
var videos\_xml:XML = new XML();  
videos\_xml.ignoreWhite = true;  
var RootNode:XMLNode;

videos\_xml.onLoad = function(success:Boolean) {  
if (success) {  
RootNode = this.firstChild;  
totalVideos = RootNode.childNodes.length;  
populateVideosArray();  
} else {  
trace(“error loading xml file”);  
}  
};  
videos\_xml.load(“videos.xml”);

function populateVideosArray():Void{  
for(var i:Number=0; i \< totalVideos;i++){  
videos\_array\* = RootNode.childNodes\*;  
videos\_array\*.url = RootNode.childNodes\*.attributes.url;  
videos\_array\*.desc = RootNode.childNodes\*.attributes.desc;  
}

```
//play first track 
ns.play(videos_array[0].url,videos_array[0].desc);

//Iterate through array & add videos to list box
for(i=0;i&lt;totalVideos;i++) {
    videoList.addItem(videos_array*.attributes.desc,videos_array*.attributes.url);
}

/////////////////////////////////
/*This is what i need to work!!*/
/////////////////////////////////

ns.onStatus = function(info) {
if(videoList.selectedIndex &lt; (totalVideos -1)) {
    if (info.code == "NetStream.Play.Stop") {
        videoList.selectedIndex += 1;
        ns.play(videoList.getItemAt(videoList.selectedIndex).data);
    }
}

```

};  
//function:playNextVideo();  
//if(videoList.selectedIndex \< (totalVideos -1)) {

```
   // if(the video has finished playing) {

           // videoList.selectedIndex += 1;
          // ns.play(videoList.getItemAt(next child node).data);
      // }else {
       // videoList.selectedIndex = 0;
      // }
//}

```

}

```
//Stop/Start video
playButton.onRelease = function() {
    ns.pause();
}

//call videoStatus() 10 times a second
var videoInterval = setInterval(videoStatus,100);
var amountLoaded:Number;

ns["onMetaData"] = function(obj) {
    duration = obj.duration;
    }

function videoStatus() {
    amountLoaded = ns.bytesLoaded / ns.bytesTotal;
    loader.loadbar._width = amountLoaded * 210;
    loader.scrub._x = ns.time / duration * 210;
    }

//Create listener object to respond to changes
var vidList:Object = new Object();

//Set up change event when user selects different video
vidList.change = function() {
    //get URL of currently selected item
    ns.play(videoList.getItemAt(videoList.selectedIndex).data);
}
//Register listener object to receive events from videoList
videoList.addEventListener("change",vidList);

```

Thanks
