Aqui teneys la parte importante (que he considerado) del código del xspf player (un reproductor flash en actionscript). Tengo un archivho .php que me genera un playlist XML dinamica basandoose en una tabla de MySQL con esta informacion:
ID; uniqueID; url; titulo
lo que quiero conseguir es que mi reproductor cada vez que acabe una cancion (o se clicke sobre el boton de "siguente") vuelva a leer el archivo playlist.php (que es mi XML dinamico) y busque la uniqueID de la cancion que acaba d reproducir, seleccione la ID de esa misma cancion y reproduzca la cancion que tenga esa ID+1 (estnado todos los datos que tengo en mi tabla MySQL en el XML.
Lo que quiero con esto es conseguir que un usuario pueda modificar su playlist como quiera sin que se corte la reproduccion de una cancion qeu esté escuchando y que cuando acabe de escuchar dicha cancion se reproduzca la cancion que el ha colocado justo despues en la lista, es decir, estilo [URL="http://www.grooveshark.com"]grooveshark[/URL]
Código:
DEFAULT_PLAYLIST_URL = "http://webjay.org/by/hideout/allshows.xspf";
DEFAULT_WELCOME_MSG = "Hideout XSPF Music Player - by Fabricio Zuardi";
LOADING_PLAYLIST_MSG = "Loading Playlist...";
DEFAULT_LOADED_PLAYLIST_MSG = "- click to start"
DEFAULT_INFOBUTTON_TXT = "Track Info"
//default playlist if none is passed through query string
if(!playlist_url){
if(!song_url){
playlist_url = DEFAULT_PLAYLIST_URL;
}else{
single_music_playlist = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><playlist version=\"1\" xmlns = \"http://xspf.org/ns/0/\"><trackList>";
single_music_playlist += "<track><location>"+song_url+"</location><annotation>"+song_title+"</annotation></track>"
single_music_playlist += "</trackList></playlist>"
}
}
//info button
info_mc._visible=false;
if(!info_button_text){
info_button_text = DEFAULT_INFOBUTTON_TXT;
}
//variables initialization
playlist_array = [];
track_index = 0;
volume_level = 100;
pause_position = 0;
playlist_xml = new XML();
playlist_xml.ignoreWhite = true;
playlist_xml.onLoad = playlistLoaded;
mysound = new Sound(this);
playlist_listener = new Object();
playlist_list.addEventListener("change", playlist_listener)
//play_btn.onPress = playTrack;
//functions
//xml parser
function playlistLoaded (success){
if(success){
var root_node = this.firstChild;
for(var node = root_node.firstChild; node != null; node = node.nextSibling){
if(node.nodeName == "title"){
playlist_title = node.firstChild.nodeValue;
}
if(node.nodeName == "trackList"){
//tracks
var tracks_array = [];
for(var track_node = node.firstChild; track_node != null; track_node = track_node.nextSibling){
var track_obj = new Object()
//track attributes
for(var track_child = track_node.firstChild; track_child != null; track_child = track_child.nextSibling){
if(track_child.nodeName=="location"){
track_obj.location = track_child.firstChild.nodeValue
}
if(track_child.nodeName=="image"){
track_obj.image = track_child.firstChild.nodeValue
}
if(track_child.nodeName=="title"){
track_obj.title = track_child.firstChild.nodeValue
}
if(track_child.nodeName=="creator"){
track_obj.creator = track_child.firstChild.nodeValue
}
if(track_child.nodeName=="annotation"){
track_obj.annotation = track_child.firstChild.nodeValue
}
if(track_child.nodeName=="info"){
track_obj.info = track_child.firstChild.nodeValue
}
}
track_obj.label = (tracks_array.length+1) +". ";
if(track_obj.title) {
if(track_obj.creator) {
track_obj.label += track_obj.creator+' - ';
}
track_obj.label += track_obj.title;
} else {
track_obj.label += track_obj.annotation;
}
tracks_array.push(track_obj)
}
}
}
playlist_array = tracks_array;
if(!playlist_size) playlist_size = playlist_array.length;
if(autoplay){
loadTrack()
}else{
start_btn_mc.start_btn.onPress = loadTrack;
track_display_mc.display_txt.text = playlist_title+" "+DEFAULT_LOADED_PLAYLIST_MSG;
if(track_display_mc.display_txt._width>track_display_mc.mask_mc._width){
track_display_mc.onEnterFrame = scrollTitle;
}else{
track_display_mc.onEnterFrame = null;
track_display_mc.display_txt._x = 0;
}
}
}else{
annotation_txt.text = "Error opening "+playlist_url;
}
}
playlist_listener.change = function(eventObject){
annotation_txt.text = playlist_list.selectedItem.annotation;
location_txt.text = playlist_list.selectedItem.location;
}
function loadTrack(){
if (radio_mode && track_index==playlist_size-1) {
playlist_url=playlist_array[track_index].location;
for (i=0;i<playlist_mc.track_count;++i) {
removeMovieClip(playlist_mc.tracks_mc["track_"+i+"_mc"]);
}
playlist_mc.track_count=0;
playlist_size=0;
track_index=0;
autoload=true;
autoplay=true;
loadPlaylist();
return(0);
}
start_btn_mc.start_btn._visible = false;
track_display_mc.display_txt.text = playlist_array[track_index].label;
if(track_display_mc.display_txt._width>track_display_mc.mask_mc._width){
track_display_mc.onEnterFrame = scrollTitle;
}else{
track_display_mc.onEnterFrame = null;
track_display_mc.display_txt._x = 0;
}
mysound.loadSound(playlist_array[track_index].location,true);
play_mc.gotoAndStop(2)
//info button
if(playlist_array[track_index].info!=undefined){
info_mc._visible = true;
info_mc.info_btn.onPress = function(){
getURL(playlist_array[track_index].info,"_blank")
}
info_mc.info_btn.onRollOver = function(){
track_display_mc.display_txt.text = info_button_text;
}
info_mc.info_btn.onRollOut = function(){
track_display_mc.display_txt.text = playlist_array[track_index].label;
}
}else{
info_mc._visible = false;
}
resizeUI();
_root.onEnterFrame=function(){
//HACK doesnt need to set the volume at every enterframe
mysound.setVolume(this.volume_level)
var load_percent = (mysound.getBytesLoaded()/mysound.getBytesTotal())*100
track_display_mc.loader_mc.load_bar_mc._xscale = load_percent;
if(mysound.getBytesLoaded()==mysound.getBytesTotal()){
//_root.onEnterFrame = null;
}
}
}
stop_btn.onRelease = stopTrack;
play_mc.play_btn.onRelease = playTrack
next_btn.onRelease = nextTrack
prev_btn.onRelease = prevTrack
mysound.onSoundComplete = nextTrack;
volume_mc.volume_btn.onPress = volumeChange;
volume_mc.volume_btn.onRelease = volume_mc.volume_btn.onReleaseOutside = function(){
this._parent.onEnterFrame = null;
}
function stopTrack() {
mysound.stop();
play_mc.gotoAndStop(1)
mysound.stop();
mysound.start();
mysound.stop();
_root.pause_position = 0;
};
function playTrack() {
if(play_mc._currentframe==1){ //play
seekTrack(_root.pause_position)
play_mc.gotoAndStop(2)
}else if(play_mc._currentframe==2){
_root.pause_position = mysound.position;
mysound.stop();
play_mc.gotoAndStop(1)
}
};
function seekTrack(p_offset:Number){
mysound.stop()
mysound.start(int((p_offset)/1000),1)
}
function nextTrack(){
if(track_index<playlist_size-1){
track_index ++;
loadTrack();
}else{
if(repeat_playlist){
last_track_index = track_index;
track_index = 0;
loadTrack()
}
}
}
function prevTrack(){
if(track_index>0){
track_index --;
loadTrack();
}
}
function loadPlaylist(){
track_display_mc.display_txt.text = LOADING_PLAYLIST_MSG;
if(track_display_mc.display_txt._width>track_display_mc.mask_mc._width){
track_display_mc.onEnterFrame = scrollTitle;
}else{
track_display_mc.onEnterFrame = null;
track_display_mc.display_txt._x = 0;
}
//playlist
if(playlist_url){
playlist_xml.load(playlist_url)
}else{
//single track
playlist_xml.parseXML(single_music_playlist)
playlist_xml.onLoad(true);
}
}
//first click - load playlist
start_btn_mc.start_btn.onPress = function(){
autoplay = true;
loadPlaylist();
}
//main
Stage.scaleMode = "noScale"
Stage.align = "LT";
this.onResize = resizeUI;
Stage.addListener(this);
if(!player_title) player_title = DEFAULT_WELCOME_MSG;
track_display_mc.display_txt.autoSize = "left";
track_display_mc.display_txt.text = player_title;
if(track_display_mc.display_txt._width>track_display_mc.mask_mc._width){
track_display_mc.onEnterFrame = scrollTitle;
}else{
track_display_mc.onEnterFrame = null;
track_display_mc.display_txt._x = 0;
}
//start to play automatically if parameter autoplay is present
if(autoplay){
start_btn_mc.start_btn.onPress();
} else if (autoload){
loadPlaylist()
}
alguna sugerencia de que debo cambiar en mi actionscript? tengamos en cuenta que mi XML tiene una forma estilo
Código:
<tracklist>
<track>
<id>1</id>
<uniqueid>479035702657</uniqueid>
<url>blablabla/mp3/swgrtg.mp3</url>
<titulo>musicaaa</mp3>
</track>
</tracklist>
si no me he explicado bien o teneys alguna duda sobre lo que pido como ayuda exactamente preguntad eh!
muchas gracias de antemano!