5 Replies Latest reply on Dec 9, 2006 3:15 PM by Santhoshdotcom

    Random Play with XML Playlist

    racc1
      I created a custom flv player and loaded a xml playlist. I would like to the play the videos randomly. could anyone help me with my script.

      the following is my current action script:

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

      var ns:NetStream = new NetStream(nc);

      ns.setBufferTime(30);

      ns.onStatus = function(info) {
      if(info.code == "NetStream.Buffer.Full") {
      bufferClip._visible = false;
      }
      if(info.code == "NetStream.Buffer.Empty") {
      bufferClip._visible = true;
      }
      if(info.code == "NetStream.Buffer.Stop") {
      ns.seek(0);
      }
      }

      theVideo.attachVideo(ns);

      rewindButton.onRelease = function() {
      ns.seek(0);
      }

      playButton.onRelease = function() {
      ns.pause();
      }

      var videoInterval = setInterval(videoStatus,100);
      var amountLoaded:Number;
      var duration:Number;

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

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

      var scrubInterval;

      loader.scrub.onPress = function() {
      clearInterval(videoInterval);
      scrubInterval = setInterval(scrubit,10);
      this.startDrag(false,-5.3,this._y,193.3,this._y);
      }

      loader.scrub.onRelease = loader.scrub.onReleaseOutside = function() {
      clearInterval(scrubInterval);
      videoInterval = setInterval(videoStatus,100);
      this.stopDrag();
      }

      function scrubit() {
      ns.seek(Match.floor((loader.scrub._x/200)*duration));
      }

      var theMenu:ContextMenu = new ContextMenu();
      theMenu.hideBuiltInItems();
      _root.menu = theMenu;

      var i1:ContextMenuItem = new ContextMenuItem(":::: VideoControls ::::",trace);
      theMenu.customItems[0] = i1;

      var i2:ContextMenuItem = new ContextMenuItem("Play / Pause Video",pauseIt,true);
      theMenu.customItems[1] = i2;

      var i3:ContextMenuItem = new ContextMenuItem("Replay Video",replayIt);
      theMenu.customItems[2] = i3;

      var i4:ContextMenuItem = new ContextMenuItem("Copyright 2006 VideoLightTV.com",trace,true);
      theMenu.customItems[3] = i4;

      function pauseIt() {
      ns.pause();
      }

      function replayIt() {
      ns.seek(0);
      }

      var vlist:XML = new XML();
      vlist.ignoreWhite = true;

      vlist.onLoad = function() {
      var videos:Array = this.firstChild.childNodes;
      for(i=0;i<videos.length;i++) {
      videoList.addItem(videos .attributes.url,videos.attributes.url);
      }

      ns.play(videoList.getItemAt(0).data);
      videoList.selectedIndex = 0;
      }

      var vidList:Object = new Object();

      vidList.change = function() {
      ns.play(videoList.getItemAt(videoList.selectedIndex).data);
      }

      videoList.addEventListener("change",vidList);

      vlist.load("videos.xml");