PDA

Volledige versie bekijken : probleempje mp3player


edo081
%Europe/Berlin %695 %2007, 17:41
beste mensen, ik heb een mp3 speler met de volgende code:

als ik nu op het volgende nummer klik en dat blijf doen en mijn nummers zijn op dan geeft die een foutmelding "undefined" het moet dus eigenlijk zo zijn dat wanneer er geen nummers meer zijn mijn next button niet meer te gebruiken is en bij prev hetzelfde, hoe doe ik dit? of anders dat wanneer de nummers op zijn de nummers van voor af aan weer worden aangeroepen, kan iemand mij helpen kom er even niet uit..

greeeetszz erik


//generic actions involoved in loading XML and stripping whitespace
var SongsXML:XML = new XML();
SongsXML.ignoreWhite = true;
SongsXML.onLoad = loadSongsXML;
SongsXML.load("mySongs.xml");

//create a variable to hold the Sound object
var MP3ToPlay:Sound = new Sound();

//create a variable to hold the number of the song that is playing
var songNum:Number = 0;

//creates an array that holds the entire list of songs contained in the XML file
var songs_lst:Array = new Array();

//function to load the XML file that contains the Songs
//"success" is passed into this function to determine if and when the Function executes
function loadSongsXML(success):Void {

//if "success" gets passed here, that means the loadSongsXML function executed, so the following code will execute
if (success) { accessSongs(); }

}

function accessSongs(){

//set FolderNode variable equal to first ChildNode
//What the f does this mean? Well, it is setting up a variable called FolderNode, to hold the XML Node
//called "Folder," (in this case, the artist name)
//it is then locating this object in the XML document and setting it as the value of this variable
var FolderNode:XMLNode = SongsXML.firstChild.childNodes[0];


//Cycle through FolderNode, and add each item to songs_lst variable
//songs_lst was initialized above as an array. This for statement populates that array
for (var j:Number = 0 ; j < FolderNode.childNodes.length ; j++) {
songs_lst.addItem(FolderNode.childNodes[j].attributes.file);
}

//set the variable "currentSong" equal to the Childnode of "FolderNode" that is in the
//position referred to by the variable "songNum" (which is initialized above)
currentSong = FolderNode.childNodes[songNum].attributes.file;

//sets the Var numberOfSongs equal to the number (length) of childnodes within "FolderNode"
_root.numberOfSongs = FolderNode.childNodes.length;

//initialize variable that holds selected song
//and concatenate the path the that file using variables created above
SelectedSong = "MP3s/" + currentSong;

//stop sounds because we are going to load a new one in a minute
stopAllSounds();
//set the initial volume
var startVolume:Number=50;

//this function checks that MP3ToPlay loads successfully
MP3ToPlay.onLoad = function(success:Boolean) {

//if sound loaded successfully, then set the volume and start playing the sound
if (success) {
MP3ToPlay.setVolume(startVolume);
MP3ToPlay.start();

//once the current sound finishes playing, perform this action
//which advances the playlist to the next song
MP3ToPlay.onSoundComplete = function(){
songNum = songNum + 1;
if(songNum == (numberOfSongs)){ songNum = 0; }
field.songName.text = "Song Buffering";
accessSongs();
}

//makes sure that the sound file does not play until it is loaded completely
if((MP3ToPlay.getBytesLoaded() == MP3ToPlay.getBytesTotal()) && MP3ToPlay.duration > 0){
field.songName.text = "";
field.songName.text += MP3ToPlay.id3.songname;
}
}

}

//loads a sounds into the var MP3ToPlay that was created above.
//The song is loaded from the string created above in "selected song"
//The "false" refers to the streaming parameter
MP3ToPlay.loadSound(SelectedSong, false);

}



back.onRollOver=function(){
back.gotoAndPlay('speel');
}
back.onRollOut=function(){
back.gotoAndPlay('terug');
}
back.onRelease=function(){


songNum = songNum - 1;

if(songNum == -1){
songNum =numberOfSongs-1;
}

accessSongs();



}



stoppen.onRollOver=function(){
stoppen.gotoAndPlay('speel');
}
stoppen.onRollOut=function(){
stoppen.gotoAndPlay('terug');

}
stoppen.onRelease=function(){

stopAllSounds();

}


forward.onRollOver=function(){
forward.gotoAndPlay('speel');
}
forward.onRollOut=function(){
forward.gotoAndPlay('terug');
}
forward.onRelease=function(){
songNum =songNum + 1;

if(songNum == (numberOfSongs)){
songNum = 0;
}

accessSongs();

}

spelen.onRollOver=function(){
spelen.gotoAndPlay('speel');
}
spelen.onRollOut=function(){
spelen.gotoAndPlay('terug');
}

spelen.onRelease=function(){
accessSongs();

}

Jan
%Europe/Berlin %732 %2007, 18:34
Zet je even een "]" achter die eerste "[as" want op deze manier is je code/script heel moeilijk te lezen/ontcijferen.

Groeten,
Jan

edo081
%Europe/Berlin %739 %2007, 18:45
sorrie je hebt gelijk!!!! excuses...

znort
%Europe/Berlin %852 %2007, 21:28
ik heb een soortgelijk probleem met:
//feel free to use this MP3 player as you wish
//if you like it, or even if you don't, drop by my blog and hopefully get a little inspired at:
// http://www.asiabackpacker.com/blog/

//I've tried to add tons of comments to make it really easy to understand what everything does
//if you want to make any changes, or just understand how it works
//However, the only thing you have to edit is the .XML file, and the files in the MP3's folder


//generic actions involoved in loading XML and stripping whitespace
var SongsXML:XML = new XML();
SongsXML.ignoreWhite = true;
SongsXML.onLoad = loadSongsXML;
SongsXML.load("mySongs.xml");

//create a variable to hold the Sound object
var MP3ToPlay:Sound = new Sound();

//create a variable to hold the number of the song that is playing
var songNum:Number = 0;

//creates an array that holds the entire list of songs contained in the XML file
var songs_lst:Array = new Array();

//function to load the XML file that contains the Songs
//"success" is passed into this function to determine if and when the Function executes
function loadSongsXML(success):Void {

//if "success" gets passed here, that means the loadSongsXML function executed, so the following code will execute
if (success) { accessSongs(); }

}

function accessSongs(){

//set FolderNode variable equal to first ChildNode
//What the f does this mean? Well, it is setting up a variable called FolderNode, to hold the XML Node
//called "Folder," (in this case, the artist name)
//it is then locating this object in the XML document and setting it as the value of this variable
var FolderNode:XMLNode = SongsXML.firstChild.childNodes[0];


//Cycle through FolderNode, and add each item to songs_lst variable
//songs_lst was initialized above as an array. This for statement populates that array
for (var j:Number = 0 ; j < FolderNode.childNodes.length ; j++) {
songs_lst.addItem(FolderNode.childNodes[j].attributes.file);
}

//set the variable "currentSong" equal to the Childnode of "FolderNode" that is in the
//position referred to by the variable "songNum" (which is initialized above)
currentSong = FolderNode.childNodes[songNum].attributes.file;

//sets the Var numberOfSongs equal to the number (length) of childnodes within "FolderNode"
_root.numberOfSongs = FolderNode.childNodes.length;

//initialize variable that holds selected song
//and concatenate the path the that file using variables created above
SelectedSong = "MP3s/" + currentSong;

//stop sounds because we are going to load a new one in a minute
stopAllSounds();
//set the initial volume
var startVolume:Number=50;

//this function checks that MP3ToPlay loads successfully
MP3ToPlay.onLoad = function(success:Boolean) {

//if sound loaded successfully, then set the volume and start playing the sound
if (success) {
MP3ToPlay.setVolume(startVolume);
MP3ToPlay.start();

//once the current sound finishes playing, perform this action
//which advances the playlist to the next song
MP3ToPlay.onSoundComplete = function(){
_root.songNum = _root.songNum + 1;
if(_root.songNum == (_root.numberOfSongs)){ _root.songNum = 0; }
field.songName.text = "Song Buffering";
_root.accessSongs();
}

//makes sure that the sound file does not play until it is loaded completely
if((MP3ToPlay.getBytesLoaded() == MP3ToPlay.getBytesTotal()) && MP3ToPlay.duration > 0){
field.songName.text = "";
field.songName.text += MP3ToPlay.id3.songname;
}
}

}

//loads a sounds into the var MP3ToPlay that was created above.
//The song is loaded from the string created above in "selected song"
//The "false" refers to the streaming parameter
MP3ToPlay.loadSound(SelectedSong, false);

}

stop();
en met deze xml-file:
<?xml version="1.0" standalone="yes"?>
<sounds>
<artist name = "Alan ODay">
<song file = "AngieBaby.mp3" />
<song file = "RockAndRollHeaven.mp3" />
<song file = "SkinnyGirls.mp3" />
<song file = "UndercoverAngel.mp3" />
</artist>
</sounds>

Zodra ik mijn mp3's in de daarvoor bestemde map zet en de xml file aanpas krijg ik in mijn swf file uiteindelijk een "Undefined" melding op de plaats waar normaal de titel vh nummer komt...

Weet iemand raad (met een andere movie, die ik echter niet wil gebruiken heb ik dit probleem niet)...?