all groups > flash actionscript > november 2006 >
You're in the

flash actionscript

group:

Random Play with XML Playlist


Random Play with XML Playlist racc1
11/25/2006 6:51:13 PM
flash actionscript:
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[i].attributes.url,videos[i].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");






Re: Random Play with XML Playlist WebXperience
11/25/2006 7:45:44 PM
Try something like this:

vidList.change = function() {
var nextVideo =Math.floor(Math.random()/videos.length);
ns.play(videoList.getItemAt(nextVideo).data);
}
Re: Random Play with XML Playlist racc1
11/25/2006 8:38:35 PM
Thanks for the script, I'm trying it now, but should i keep the following:

Re: Random Play with XML Playlist racc1
11/25/2006 10:01:12 PM
Re: Random Play with XML Playlist WebXperience
11/30/2006 11:28:43 PM
Just replace the contents of your [b]"vidList.change"[/b] function with the
contents of the one I've included here.

vidList.change = function() {
var nextVideo =Math.floor(Math.random()/videos.length);
ns.play(videoList.getItemAt(nextVideo).data);
}
Re: Random Play with XML Playlist Santhoshdotcom
12/9/2006 11:15:12 PM
How do I auto play next clip. Once the movie finish it stops, How can i code to
play next clip.
here is my code..
Thanks


stop();
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
theVideo.attachVideo(ns);

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[i].attributes.desc,videos[i].attributes.url);
}

i = 0;
if (i<0){
i++
}

ns.play(videoList.getItemAt(i).data);
ns.seek(2);


videoList.selectedIndex = i;
}
var vidList:Object = new Object();
vidList.change = function() {
ns.play(videoList.getItemAt(videoList.selectedIndex).data);
}
videoList.addEventListener("change",vidList);

vlist.load("videos.xml");
AddThis Social Bookmark Button