Play and Pause an MP3 File : Mp3 « Development « Flex






Play and Pause an MP3 File

Play and Pause an MP3 File
         

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
    <mx:HBox width="400" height="300">
        <mx:Script>
            
                import mx.collections.ArrayCollection;
    
                public var sound:Sound;
                public var mySoundChannel:SoundChannel;
                public var pausePos:int = 0;
    
                private function loadSound():void {
                    sound = new Sound();
                    sound.addEventListener(Event.SOUND_COMPLETE, soundComplete);
                    var req:URLRequest = new URLRequest("http://localhost/a.mp3");
                    sound.load(req);
                    pausePos = 0;
                    mySoundChannel = sound.play();
                }
                private function soundComplete(event:Event):void {
                    sound.load(new URLRequest("http://localhost/a.mp3"));
                    mySoundChannel = sound.play();
                }
    
                private function playPauseHandler():void{
                    if(pausePlayBtn.selected){
                        pausePos = mySoundChannel.position;
                        mySoundChannel.stop();
                    } else {
                        mySoundChannel = sound.play(pausePos);
                    }
                }    
          
        </mx:Script>
        <mx:Button label="Play" id="cb" click="loadSound()"/>
        <mx:Button label="start" id="pausePlayBtn" toggle="true" click="playPauseHandler()"/>
        <mx:Button label="stop" click="mySoundChannel.stop()"/>
    </mx:HBox>
</mx:Application>

   
    
    
    
    
    
    
    
    
  








Related examples in the same category

1.Create a Seek Bar for a Mp3 Sound FileCreate a Seek Bar for a Mp3 Sound File