virtex
asked on
xml playlist id3 for flash and how to make one and play info.
I am currently messing around with a lil bit of code. never used xml b4. here it is
var tracklist = new Array ();
var mp3List = new XML ();
mp3List.ignoreWhite = true;
mp3List.onLoad = createPlayList;
mp3List.load ("playlist.xml");
function createPlayList (success)
{
if (!success)
{
return;
}
var topLevel = null;
for (i = 0; i <= this.childNodes.length; i++)
{
if (this.childNodes[i].nodeVa lue == null &&
this.childNodes[i].nodeNam e == "playlist")
{
topLevel = this.childNodes[i];
break;
}
}
if (topLevel != null)
{
for (i = 0; i <= topLevel.childNodes.length ; i++)
{
if (topLevel.childNodes[i].no deName == "mp3file")
{
var track =
topLevel.childNodes[i].att ributes["t rack"];
_root.tracklist.push (track);
}
}
}
}
function randomBetween (a, b)
{
return Math.min (a, b) + random (Math.abs (a - b) + 1);
}
function playTrack ()
{
var track = _root.track;
if (track.getBytesLoaded () == track.getBytesTotal () &&
track.duration > 0)
{
clearInterval (_root.checkLoaded);
trackID3Info.text = "";
trackID3Info.text += "Title: " + track.id3.songname +
newline;
trackID3Info.text += "Artist: " + track.id3.artist +
newline;
trackID3Info.text += "Album: " + track.id3.album +
newline;
trackID3Info.text += "Year: " + track.id3.year + newline;
trackID3Info.text += "Comments: " + track.id3.comment +
newline;
}
}
randomPlayer.onPress = function ()
{
stopAllSounds ();
var trackNo = randomBetween (0, trackInfo.length - 1);
var track = new Sound ();
track.onID3 = function ()
{
trackID3Info.text = "";
trackID3Info.text += "Title: " + track.id3.TIT2 + newline;
trackID3Info.text += "Artist: " + track.id3.TPE1 + newline;
trackID3Info.text += "Album: " + track.id3.TALB + newline;
trackID3Info.text += "Year: " + track.id3.TYER + newline;
trackID3Info.text += "Comments: " + track.id3.COMM +
newline;
};
track.loadSound (tracklist[trackNo], true);
};
It loads up a mp3 from xml then gets id3.
I would like to know what I should be doing from here to get it to play. the mc has 3 buttons, a dynamic text box and a background. buttons are forwards backwards and play. if you can complete this please let me know. graphics can be generic. Thanks alot.
500 points goes out to the person who gives me back a working result using the above information.!
var tracklist = new Array ();
var mp3List = new XML ();
mp3List.ignoreWhite = true;
mp3List.onLoad = createPlayList;
mp3List.load ("playlist.xml");
function createPlayList (success)
{
if (!success)
{
return;
}
var topLevel = null;
for (i = 0; i <= this.childNodes.length; i++)
{
if (this.childNodes[i].nodeVa
this.childNodes[i].nodeNam
{
topLevel = this.childNodes[i];
break;
}
}
if (topLevel != null)
{
for (i = 0; i <= topLevel.childNodes.length
{
if (topLevel.childNodes[i].no
{
var track =
topLevel.childNodes[i].att
_root.tracklist.push (track);
}
}
}
}
function randomBetween (a, b)
{
return Math.min (a, b) + random (Math.abs (a - b) + 1);
}
function playTrack ()
{
var track = _root.track;
if (track.getBytesLoaded () == track.getBytesTotal () &&
track.duration > 0)
{
clearInterval (_root.checkLoaded);
trackID3Info.text = "";
trackID3Info.text += "Title: " + track.id3.songname +
newline;
trackID3Info.text += "Artist: " + track.id3.artist +
newline;
trackID3Info.text += "Album: " + track.id3.album +
newline;
trackID3Info.text += "Year: " + track.id3.year + newline;
trackID3Info.text += "Comments: " + track.id3.comment +
newline;
}
}
randomPlayer.onPress = function ()
{
stopAllSounds ();
var trackNo = randomBetween (0, trackInfo.length - 1);
var track = new Sound ();
track.onID3 = function ()
{
trackID3Info.text = "";
trackID3Info.text += "Title: " + track.id3.TIT2 + newline;
trackID3Info.text += "Artist: " + track.id3.TPE1 + newline;
trackID3Info.text += "Album: " + track.id3.TALB + newline;
trackID3Info.text += "Year: " + track.id3.TYER + newline;
trackID3Info.text += "Comments: " + track.id3.COMM +
newline;
};
track.loadSound (tracklist[trackNo], true);
};
It loads up a mp3 from xml then gets id3.
I would like to know what I should be doing from here to get it to play. the mc has 3 buttons, a dynamic text box and a background. buttons are forwards backwards and play. if you can complete this please let me know. graphics can be generic. Thanks alot.
500 points goes out to the person who gives me back a working result using the above information.!
Can you add an extract of playlist.xml that we can look at too?
ASKER
<playlist>
<mp3file track="song1.mp3"/>
<mp3file track="song2.mp3"/>
<mp3file track="song3.mp3"/>
<mp3file track="song4.mp3"/>
<mp3file track="song5.mp3"/>
</playlist>
<mp3file track="song1.mp3"/>
<mp3file track="song2.mp3"/>
<mp3file track="song3.mp3"/>
<mp3file track="song4.mp3"/>
<mp3file track="song5.mp3"/>
</playlist>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
great that part works. how do you get it to go back a song or forward a song though using that method? if you can do that for me it would be very appreciated. basically like I originally said I have a back a song button and a forward a song button.
ASKER
and play song which is the randomplayer mc
Ok replace the code i gave earlier with this:
//------------------------ ---------- ---------- ----
//------------------------ ---------- ---------- ----
var tracklist = new Array ();
var track ="";
currentSong = "";
var mp3List = new XML ();
mp3List.ignoreWhite = true;
mp3List.onLoad = createPlayList;
mp3List.load ("playlist.xml");
function createPlayList (success)
{
if (!success)
{
return;
}
var topLevel = null;
trace("CHILD: "+this.childNodes.length);
for (i = 0; i <= this.childNodes.length; i++)
{
if (this.childNodes[i].nodeVa lue == null &&
this.childNodes[i].nodeNam e == "playlist")
{
topLevel = this.childNodes[i];
trace("testing"+topLevel);
break;
}
}
if (topLevel != null)
{
trace("TOPLEVEL: "+topLevel.childNodes.leng th);
for (i = 0; i <= topLevel.childNodes.length ; i++)
{
if (topLevel.childNodes[i].no deName == "mp3file")
{
var track = topLevel.childNodes[i].att ributes["t rack"];
trace("THIS IS PROBLEM: "+topLevel.childNodes[i].a ttributes[ "track"]);
_root.tracklist.push (track);
}
// trace("sajid:"+_root.track list);
}
}
trace(tracklist);
}
function randomBetween (a, b)
{
return Math.min (a, b) + random (Math.abs (a - b) + 1);
}
function playTrack ()
{
var track = _root.track;
trace("THIS IS TRACK: "+track);
if (track.getBytesLoaded () == track.getBytesTotal () &&
track.duration > 0)
{
clearInterval (_root.checkLoaded);
trackID3Info.text = "";
trackID3Info.text += "Title: " + track.id3.songname +
newline;
trackID3Info.text += "Artist: " + track.id3.artist +
newline;
trackID3Info.text += "Album: " + track.id3.album +
newline;
trackID3Info.text += "Year: " + track.id3.year + newline;
trackID3Info.text += "Comments: " + track.id3.comment +
newline;
}
}
randomPlayer.onPress = function ()
{
stopAllSounds ();
var trackNo = randomBetween (0, tracklist.length - 1);
currentSong = trackNo;
trace("rand Tracn No: "+trackNo);
loadSong(currentSong);
}
function loadSong(tNo){
var track = new Sound ();
track.onID3 = function ()
{
trace("ON ID# CALLED");
trackID3Info.text = "";
trackID3Info.text += "Title: " + track.id3.TIT2 + newline;
trackID3Info.text += "Artist: " + track.id3.TPE1 + newline;
trackID3Info.text += "Album: " + track.id3.TALB + newline;
trackID3Info.text += "Year: " + track.id3.TYER + newline;
trackID3Info.text += "Comments: " + track.id3.COMM +
newline;
trace("Album: " + track.id3.TALB + newline);
};
track.loadSound (tracklist[tNo], true);
}
function playNext(){
++currentSong;
trace("THIS IS CURRENT: "+currentSong);
if(_root.currentSong <=(_root.tracklist.length- 1)){
//trace(_root.currentSong +": AND :"+(_root.tracklist.length - 1));
_root.loadSong(_root.curre ntSong);
} else {
_root.nextPlayer.enabled=f alse;
}
}
function playPrev(){
--currentSong;
trace("THIS IS CURRENT: "+currentSong);
if(_root.currentSong >= 0){
//trace(_root.currentSong +": AND :"+(_root.tracklist.length - 1));
_root.loadSong(_root.curre ntSong);
} else {
_root.nextPlayer.enabled=f alse;
}
}
//------------------------ ---------- ---------- ----
//------------------------ ---------- ---------- ----
I added two more functions called:
playNext()
and
playPrev()
Call these functions to move to next or previous songs.
You can call then on button actions like this:
on(release){
_root.playNext();
}
or
on(release){
_root.playPrev();
}
//------------------------
//------------------------
var tracklist = new Array ();
var track ="";
currentSong = "";
var mp3List = new XML ();
mp3List.ignoreWhite = true;
mp3List.onLoad = createPlayList;
mp3List.load ("playlist.xml");
function createPlayList (success)
{
if (!success)
{
return;
}
var topLevel = null;
trace("CHILD: "+this.childNodes.length);
for (i = 0; i <= this.childNodes.length; i++)
{
if (this.childNodes[i].nodeVa
this.childNodes[i].nodeNam
{
topLevel = this.childNodes[i];
trace("testing"+topLevel);
break;
}
}
if (topLevel != null)
{
trace("TOPLEVEL: "+topLevel.childNodes.leng
for (i = 0; i <= topLevel.childNodes.length
{
if (topLevel.childNodes[i].no
{
var track = topLevel.childNodes[i].att
trace("THIS IS PROBLEM: "+topLevel.childNodes[i].a
_root.tracklist.push (track);
}
// trace("sajid:"+_root.track
}
}
trace(tracklist);
}
function randomBetween (a, b)
{
return Math.min (a, b) + random (Math.abs (a - b) + 1);
}
function playTrack ()
{
var track = _root.track;
trace("THIS IS TRACK: "+track);
if (track.getBytesLoaded () == track.getBytesTotal () &&
track.duration > 0)
{
clearInterval (_root.checkLoaded);
trackID3Info.text = "";
trackID3Info.text += "Title: " + track.id3.songname +
newline;
trackID3Info.text += "Artist: " + track.id3.artist +
newline;
trackID3Info.text += "Album: " + track.id3.album +
newline;
trackID3Info.text += "Year: " + track.id3.year + newline;
trackID3Info.text += "Comments: " + track.id3.comment +
newline;
}
}
randomPlayer.onPress = function ()
{
stopAllSounds ();
var trackNo = randomBetween (0, tracklist.length - 1);
currentSong = trackNo;
trace("rand Tracn No: "+trackNo);
loadSong(currentSong);
}
function loadSong(tNo){
var track = new Sound ();
track.onID3 = function ()
{
trace("ON ID# CALLED");
trackID3Info.text = "";
trackID3Info.text += "Title: " + track.id3.TIT2 + newline;
trackID3Info.text += "Artist: " + track.id3.TPE1 + newline;
trackID3Info.text += "Album: " + track.id3.TALB + newline;
trackID3Info.text += "Year: " + track.id3.TYER + newline;
trackID3Info.text += "Comments: " + track.id3.COMM +
newline;
trace("Album: " + track.id3.TALB + newline);
};
track.loadSound (tracklist[tNo], true);
}
function playNext(){
++currentSong;
trace("THIS IS CURRENT: "+currentSong);
if(_root.currentSong <=(_root.tracklist.length-
//trace(_root.currentSong +": AND :"+(_root.tracklist.length
_root.loadSong(_root.curre
} else {
_root.nextPlayer.enabled=f
}
}
function playPrev(){
--currentSong;
trace("THIS IS CURRENT: "+currentSong);
if(_root.currentSong >= 0){
//trace(_root.currentSong +": AND :"+(_root.tracklist.length
_root.loadSong(_root.curre
} else {
_root.nextPlayer.enabled=f
}
}
//------------------------
//------------------------
I added two more functions called:
playNext()
and
playPrev()
Call these functions to move to next or previous songs.
You can call then on button actions like this:
on(release){
_root.playNext();
}
or
on(release){
_root.playPrev();
}
ASKER
now there is only one problem with this. if I start it up it will continue to play the mp3 that was playing b4 and play the next one at the same time. I tried doing a track.sound.stop();
but it still plays. Any ideas?
but it still plays. Any ideas?
On my cmoputer it does not play the previous song. Because when you loadSound, it should automatically unload the first one.
I will see what i can figure out more here.
I will see what i can figure out more here.
Hi, Any success? Let me know where you are stuck and we can resolve it.
ASKER
none, it still plays the second one over the first one. If it is possible could you replace the random with just a straight play and on hit again stop then use the 2 other buttons to play one forward or one backward?
Please let me know. seems it isnt unloading it still.
Please let me know. seems it isnt unloading it still.
ASKER
could you post the .fla so I can see what I am doing wrong compared to what you are doing? Please let me know. thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
yay!, that actually worked,
on(release){
stopAllSounds();
_root.playPrev();
}
I will give you some points for that still lol
I forgot all about that.
on(release){
stopAllSounds();
_root.playPrev();
}
I will give you some points for that still lol
I forgot all about that.
ASKER
Will figure out a way of getting you some points. maybe another way to do it. thnx still. was just weird and I forgot about that command :/
> Will figure out a way of getting you some points
Really, don't worry about it ;-)
I just wanted to help, ssdesign did all of the hard work!
Really, don't worry about it ;-)
I just wanted to help, ssdesign did all of the hard work!
ASKER
btw, seems there is another error in here. it wont play intil you press the play button twice. any help?