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

flash actionscript

group:

xml playlist


xml playlist raynestorm
10/22/2006 9:39:55 PM
flash actionscript:
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.

Thanks for any help.
--rayne
Re: xml playlist NSurveyor
10/22/2006 10:35:37 PM
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:



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[i] = this.firstChild.childNodes[i].firstChild.nodeValue;
}
// REST OF CODE
}
}
my_xml.load("videos.xml");
Re: xml playlist raynestorm
10/22/2006 11:12:28 PM
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[i] = this.firstChild.childNodes[i].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");
[hr]
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
Re: xml playlist The Feldkircher
10/23/2006 12:00:00 AM
Hi

There is a XML Video Player tutorial here http://www.gotoandlearn.com in the Tutorials Archive on the left of the screen select XML Video Playlist and enjoy.

Re: xml playlist Travis Newbury
10/23/2006 2:43:11 AM
[quoted text, click to view]

Do a google search on XPathAPI and actionscript. It is a simple way of
parsing XML for the data you want.
Re: xml playlist raynestorm
10/23/2006 1:00:48 PM
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[i] = this.firstChild.childNodes[i].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[i]");
}
}
my_xml.load("videos.xml");

But that's not quite it.
Thanks for the help.
--rayne
Re: xml playlist NSurveyor
10/23/2006 11:14:35 PM
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
}
AddThis Social Bookmark Button