Comunidad de diseño web y desarrollo en internet online

Mi 1er MP3 Player + AS3 = primeros problemas :p

Citar            
MensajeEscrito el 04 Ago 2007 02:21 am

Ando haciendo mi 1er player de mp3 con AS3 ,tiene sus botoncitos de Stop,Pause y Play
su barrita de volumen y su barra de tiempo aah y un boton FastForward para adelantarle

El problema es que al mover la barra de tiempo y despues querer pausar no se detiene el audio
Se muestra de nuevo el boton play y al picarle carga otro canal de audio (al parecer :S ) .

Hay una forma de borrar el canal de sonido ?

La forma de uso del método play según la ayuda de Flash CS3 funciona así:
play(startTime:Number = 0, loops:int = 0, sndTransform:SoundTransform = null):SoundChannel
y ahí dice:

Código :

Generates a new SoundChannel object to play back the sound.


Así que por el momento le echo la culpa a este método.
Help please!. :crap: Gracias.

Por Rafeo

650 de clabLevel

3 tutoriales
1 articulo

Genero:Masculino  

firefox
Citar            
MensajeEscrito el 07 Ago 2007 01:35 am
¿Puedes postear tu .fla para poder ver tu código completo y hacer pruebas?

Por Zguillez

BOFH

10744 de clabLevel

85 tutoriales
17 articulos
3 ejemplos

Genero:Masculino   Bastard Operators From Hell Héroes Team Cristalab Editores

BCN

firefox
Citar            
MensajeEscrito el 07 Ago 2007 02:08 am
Es cierto zguillez vale más que cuelgue el código (espero que no sea a alguien más a quien cuelguen por hacerlo :( :P (ahh, no, nada de código robado)).
Aquí está el mp3player.as el cuàl está linkeado a un mc de la library y no al Document class.

Código :

package {
    import flash.display.MovieClip;
    import flash.media.Sound;
    import flash.media.SoundChannel;   
   import flash.media.SoundMixer;
   import flash.media.SoundTransform;
    import flash.net.URLRequest;
    import flash.net.URLLoader;
   import flash.net.URLLoaderDataFormat;
   import flash.display.SimpleButton;
   import flash.events.Event;
   import flash.events.MouseEvent;
    import flash.utils.Timer;
    import flash.events.TimerEvent;   
    
    public class mp3player extends MovieClip {
      // objetos de sonido
        private var _sound:Sound;
        private var _channel:SoundChannel;
      private var _soundTransform:SoundTransform;
      //estatus de reproduccion
      private var _statusMP3:String;
      // tiempo en el que se pauso
      private var _pauseTime:int;
      // FlashVars
      private var _urlmp3:String;
      //variables para volumen
      private var _vol:Number=1;
      private var _volWidth:Number;
        private var _volBarWidth:Number;      
        //_abreviaturas para barras de progreso
       private  var progressBar:MovieClip;
          private  var thumbPos:MovieClip;
       private  var barWidth:Number;      
        
      private var tmrProgress:Timer;
      private var tmrPosition:Timer;
      //------------------------------------------------------------------Constuctor
        public function mp3player() {
         //variables de  referencia a la barra de tiempo
            barWidth = mTimeBar.mFondoTimeBar.width;
          progressBar = mTimeBar.mProgressBar.mMaskProgress;
          thumbPos = mTimeBar.mPosThumb;
          //variables concernientes a la barra de volumen 
         _volWidth=mVolume.mMaskVolBar.width;
            _volBarWidth = mVolume.VolumeBar.width;               
         //carga el xml de la cancion
         loadXML();         
         bPlay.addEventListener(MouseEvent.CLICK,playSong);
         bPause.addEventListener(MouseEvent.CLICK,pauseSong);                  
         bStop.addEventListener(MouseEvent.CLICK,stopSong);
            bFF.addEventListener(MouseEvent.CLICK,FastForwardSong);
         mVolume.addEventListener(MouseEvent.MOUSE_DOWN,onPressmVolume);
         mVolume.addEventListener(MouseEvent.MOUSE_UP,onReleasemVolume);
         mTimeBar.addEventListener(MouseEvent.MOUSE_DOWN,onPress_mTimeBar);
         
            tmrProgress = new Timer(1000, 0);
            tmrProgress.addEventListener(TimerEvent.TIMER, moveProgress);
            tmrProgress.start();         
            tmrPosition = new Timer(200, 0);
            tmrPosition.addEventListener(TimerEvent.TIMER, movePosition);
            tmrPosition.start();         
         
         _soundTransform = new SoundTransform();
         
        }
      
      //----------------------------------------------------------------  loadXML
      private function loadXML():void{
            var loader:URLLoader = new URLLoader(  );
         var request:URLRequest=new URLRequest("C:/Flash/Proyectos/Audio/cancion.xml");
   
         loader.dataFormat = URLLoaderDataFormat.TEXT;
         loader.addEventListener( Event.COMPLETE, onCompleteXML );
         loader.load( request );         
      }
      
      //------------------------------------------------------------  onCompleteXML (cuando se carga el XML)
      private function onCompleteXML( event:Event ):void {
         try {
            // Convierte el texto descargado a instancia XML
            var xml:XML = new XML( event.target.data );
            // obitiene la url del mp3
            _urlmp3=unescape(xml.tracklist.track.@url);
//            trace("xml = "+xml);
//            trace("_urlmp3 = "+_urlmp3);
            
         } catch (e:TypeError) {
            trace( "Could not parse text into XML" );
            trace( e.message );
         }
         
         _statusMP3="stopped";
            _sound = new Sound();
            _sound.load(new URLRequest(_urlmp3));   
         bPlay.visible=false;

         doPlay();
         
      }         
      
      //------------------------------------------------------- Funciones para los CONTROLES
      private function playSong(e:MouseEvent):void{
         if(_statusMP3!="playing" ){ doPlay();   }
      }
      private function pauseSong(e:MouseEvent):void{
         if(_statusMP3=="playing"){    doPause()  }
      }
      
      private function stopSong(e:MouseEvent):void{
           doStop();
      }
      private function FastForwardSong(e:MouseEvent):void{
           doFF();
      }
      
      private function doPlay():void{
         _channel=_sound.play(_pauseTime);
         if (!_channel.hasEventListener(Event.SOUND_COMPLETE)){
             _channel.addEventListener(Event.SOUND_COMPLETE,on_SoundComplete);
         }
         
         //obtiene el volumen actual
         _vol = _volBarWidth/_volWidth;
         _soundTransform.volume=_vol;         
         trace("_vol ="+_vol);
         bPause.visible=true;
         bPlay.visible=false;            
         _statusMP3="playing";
         trace("_pauseTime (doPlay)"+_pauseTime);
         trace("_channel ------ "+_channel);
      }
      
      private function doPause():void{
           _pauseTime=_channel.position;
         //obtiene el volumen actual
         _vol = _volBarWidth/_volWidth;
         _soundTransform.volume=_vol;         
         
         trace("_pauseTime (doPause)"+_pauseTime);         
         trace("_vol ="+_vol);         
           _channel.stop();
         bPause.visible=false;
         bPlay.visible=true;
         _statusMP3="paused";         
      }

      private function doStop():void{
           _pauseTime=0;
         trace("_pauseTime (doStop)"+_pauseTime);         
           _channel.stop();
         thumbPos.width=0;
         SoundMixer.stopAll();
         bPause.visible=false;
         bPlay.visible=true;
         _statusMP3="stopped";         
      }
      
      private function doFF():void{
         //incremento en milisegundos para hacer Fast Forward
         var step:int=4000;
         if(_channel.position+step<_sound.length){
             trace("_sound.length = "+_sound.length+"_channel.position = "+_channel.position);
           _pauseTime=_channel.position + step;
           _channel.stop();
           if (_statusMP3=="playing"){
              _channel=_sound.play(_pauseTime);              
           }
           else if(_statusMP3=="paused"){
              _channel=_sound.play(_pauseTime);
            //recalcula el tamaño del thumbPos
            thumbPos.width= barWidth*(_channel.position/_sound.length);
            _channel.stop();  
           }
           
         }
         else{
            trace("Ya te pasaste de la longitud de _sound");
         }
      }
      
      
      private function on_SoundComplete(e:Event): void{
         _channel.stop(); 
         thumbPos.width=0;
         bPlay.visible=true;
         bPause.visible=false;            
//         tmrPosition.stop();
      }
      //------------------------------------------------------- control de volumen
      private function onPressmVolume(e:MouseEvent):void{
         mVolume.VolumeBar.addEventListener(Event.ENTER_FRAME,enterFrameVolumeBar);
            stage.addEventListener(MouseEvent.MOUSE_UP, mouseUp_mVolume);         
      }
      // funcion para implementar el onReleaseOutside
      private function mouseUp_mVolume(e:MouseEvent):void{
           // onReleaseOutside
          if (e.target != mVolume){ mVolume.VolumeBar.removeEventListener(Event.ENTER_FRAME,enterFrameVolumeBar); }
             // nos aseguramos de limpiar el listener del stage
          stage.removeEventListener(MouseEvent.MOUSE_UP, mouseUp_mVolume);         
      }
      
      private function enterFrameVolumeBar(e:Event):void{
         _volBarWidth = mVolume.mMaskVolBar.mouseX;

         // valida que no se pase de los limites izquierdo y derecho
         if (_volBarWidth<0) {         _volBarWidth = 0;          }
         if (_volBarWidth>_volWidth){  _volBarWidth = _volWidth;   }
         
         //asigna la anchura a la barra de volumen   
         mVolume.VolumeBar.width = _volBarWidth;
         //obtiene el volumen actual
         _vol = _volBarWidth/_volWidth;
         // actualiza volumen
         _soundTransform.volume=_vol;
            _channel.soundTransform=_soundTransform;            
          trace(_vol);         
      }
      
      private function onReleasemVolume(e:MouseEvent):void{
         mVolume.VolumeBar.removeEventListener(Event.ENTER_FRAME,enterFrameVolumeBar);
      }

      //------------------------------------------------------- Funciones para timer de progreso y posicion en el archivo
       private function moveProgress(e:TimerEvent):void {
        if (_statusMP3 != "stopped") {
         if (progressBar.width<barWidth) {
            // barra de progreso de carga del archivo 
            progressBar.width = barWidth*_sound.bytesLoaded/_sound.bytesTotal;
            mTimeBar.mProgressBar.visible = true;
         } else if (progressBar.width>=barWidth) {
            mTimeBar.mProgressBar.visible = false;
                tmrProgress.stop();
         }
       }
       }      
      private function movePosition(e:TimerEvent):void {
       try{  
        if (_statusMP3 != "stopped") {
          //posicion nueva en la cancion
         var thumbposX:Number = barWidth*(_channel.position/_sound.length);
//         if (thumbposX<progressBar.width && thumbposX>=0) {
            thumbPos.width = thumbposX;
//         } 
        }
       }
       catch(error:Error){
       }
       }  
      
      private function onPress_mTimeBar(e:MouseEvent):void{
        try{
            tmrPosition.stop();         
         _channel.stop();
         thumbPos.addEventListener(Event.ENTER_FRAME,enterFrame_thumbPos);
         stage.addEventListener(MouseEvent.MOUSE_UP,mouseUp_mTimeBar);
        }
        catch(error:Error){
        }
      }
      
      private function enterFrame_thumbPos(e:Event):void{
            // da una nueva anchura a la barra de posicion actual 
            thumbPos.width = mTimeBar.mouseX;
            // en caso de pasarse del limite izquierdo (<0)
            if (thumbPos.width<0) {
               thumbPos.width = 0;
            }
            // en caso de pasarse del limite derecho (>progressBar._width)       
            if (thumbPos.width>progressBar.width) {
               thumbPos.width = progressBar.width;
               bPause.visible=false;
               bPlay.visible=true;
               if(_channel.position>=_sound.length){_channel.stop();}
            }
            // toma el tiempo en milisegundos correspondientes al ancho de la barra de posicion       
            _pauseTime = _sound.length*((mTimeBar.mouseX-thumbPos.x)/barWidth);
            trace("_pauseTime (enterFrame_thumbPos)="+_pauseTime);
   
      }
       
      private function mouseUp_mTimeBar(e:MouseEvent):void{
          if (e.target != mTimeBar){
           var posX = mTimeBar.mouseX;
              thumbPos.removeEventListener(Event.ENTER_FRAME,enterFrame_thumbPos);

         _pauseTime = _sound.length*((posX-thumbPos.x)/barWidth);
         trace("_pauseTime (mouseUp_mTimeBar) ="+_pauseTime);
           tmrPosition.start();         
         
         if (_statusMP3 == "playing") {
            _channel=_sound.play(_pauseTime);
         } else if (_statusMP3 == "paused") {
            thumbPos.width = posX;
            _channel=_sound.play(_pauseTime);
            _pauseTime = _channel.position;
            _channel.stop();            
         }
         tmrProgress.start();
        }         
      }
      
    }    
}


I really need help :cry: . Thanks.
Enjoy...if you can. :?

Por Rafeo

650 de clabLevel

3 tutoriales
1 articulo

Genero:Masculino  

firefox
Citar            
MensajeEscrito el 08 Ago 2007 07:20 am
El problema al parecer hasta hoy es por los addEventListeners que puse al tratar de implementar los onReleaseOutside del scrubber de tiempo como el de volumen. Alguien me puede dar más recomendaciones porfavor :D ?.

Por Rafeo

650 de clabLevel

3 tutoriales
1 articulo

Genero:Masculino  

firefox

 

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