Comunidad de diseño web y desarrollo en internet online

Dudas Mp3 player

Citar            
MensajeEscrito el 09 Nov 2010 09:20 pm
Hola chicos!!! :wink:

Tal vez puedan ayudarme, estoy haciendo un mp3 player que funciona correctamente como va hasta el momento, pero
hay unas cosillas que no he podido hacer, me gustaria guiaran en lo siguiente:

1. Quiero que el boton play/pause sean el mismo, es decir que se transforme al oprimirlo y cumpla su respectiva funcion, tengo un mc con dos fotogramas: play y pause.

Lo mismo para el mc volumen: con volumen y sin volumen.

2. Cuando llega a la ultima cancion el reproductor se detiene, ¿Como hago para que se reproduzca en bucle? que al acabar la ultima cancion comienze la primera...

Adjunto mi AS
Gracias Muchachos!!!! ^^

Código ActionScript :

package clases{
   //
   import flash.display.Loader;
   import flash.net.URLLoader;
   import flash.net.URLRequest;
   import flash.media.Sound;
   import flash.media.SoundChannel;
   import flash.events.MouseEvent;
   import flash.media.SoundLoaderContext;    
   
   public class Main extends MovieClip{
      
      private var musicReq: URLRequest;   
       private var music:Sound = new Sound();  
       private var sndC:SoundChannel;  
       private var currentSnd:Sound = music;  
       private var position:Number;  
       private var currentIndex:Number = 0;  
       private var songPaused:Boolean;  
       private var songStopped:Boolean;  
      private var changeClr:Boolean;  
       private var xml:XML;  
       private var songList:XMLList;  
       private var loader:URLLoader = new URLLoader(); 
      private var context:SoundLoaderContext = new SoundLoaderContext(30000, false); 
       

      public function Main(){
         
         //mp3 botones
         mp3player_mc.prev_mc.addEventListener(MouseEvent.CLICK, prevSong);
         mp3player_mc.next_mc.addEventListener(MouseEvent.CLICK, nextSong);
         mp3player_mc.play_mc.addEventListener(MouseEvent.CLICK, playSong);
         mp3player_mc.stop_mc.addEventListener(MouseEvent.CLICK, stopSong);
         
         loader.addEventListener(Event.COMPLETE, Loaded);  
              loader.load(new URLRequest("xml/music.xml"));
      }
      
      //mp3 player
        private function Loaded(e:Event):void{  
          xml = new XML(e.target.data);  
          songList = xml.song;  
          musicReq = new URLRequest(songList[0].url);

          music.load(musicReq, context);  
          sndC = music.play();  
        mp3player_mc.title_txt.text = songList[0].title;
           sndC.addEventListener(Event.SOUND_COMPLETE, nextSong);
      } 
      
        private function prevSong(e:Event):void{  
            if(currentIndex > 0){  
               currentIndex--;
            }
            else{  
              currentIndex = songList.length() - 1;  
             }  
         var prevReq:URLRequest = new URLRequest(songList[currentIndex].url);  
         var prevPlay:Sound = new Sound(prevReq, context);
            sndC.stop();  
            mp3player_mc.title_txt.text = songList[currentIndex].title;    
            sndC = prevPlay.play();  
            currentSnd = prevPlay;  
           // songPaused = false;   
          sndC.addEventListener(Event.SOUND_COMPLETE, nextSong);  
       } 
       
        private  function nextSong(e:Event):void {  
            if(currentIndex < (songList.length() - 1)){  
                 currentIndex++;  
            }  
                else {  
               currentIndex = 0;
             }  
         var nextReq:URLRequest = new URLRequest(songList[currentIndex].url);  
       var nextPlay:Sound = new Sound(nextReq, context);
         sndC.stop();  
         mp3player_mc.title_txt.text = songList[currentIndex].title;   
         sndC = nextPlay.play();  
          currentSnd = nextPlay;  
        // songPaused = false;  
         sndC.addEventListener(Event.SOUND_COMPLETE, nextSong);
       }
       
        private function playSong(e:Event):void{
          if(songPaused){
             sndC = currentSnd.play(position);
             //songPaused = false;
             }  
              else if(songStopped){  
                  sndC = currentSnd.play(position);  
                  songStopped = false;  
             }  
            else if(!sndC){  
           sndC = currentSnd.play(position);
         }
         }
         
        private function stopSong(e:Event):void{
           sndC.stop();  
             position = 0;  
              songStopped = true;
           }   
   }
}



   

Por dianita666

Claber

185 de clabLevel



 

firefox
Citar            
MensajeEscrito el 10 Nov 2010 01:26 am
Honestamente no leeré todo el código, dudo alguien lo haga.

Pero para orientarte, para hacer play pause un mismo botón, solo tienes que usar una variable.

Código ActionScript :

if(playing){
   //pause
}else{
   //start
}
playing = !playing;


Para evaluar cuando termina algo, debes usar Event.SOUND_COMPLETE y un indice de canción. Algo como:

Código ActionScript :

private function onNextSong(e:Event):void{
   index_song++;
   //start usando index_song
}


Saludos, Hernán . -

Por Hernán

BOFH

6148 de clabLevel

19 tutoriales
23 articulos

Genero:Masculino   REC Desarrollador de GAIA

Marketing & IT

firefox

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.