0 Replies Latest reply on Jan 25, 2010 10:29 AM by edwinmerced

    Tracking sound progress

    edwinmerced Level 1

      Hello everyone. I've managed to build this mp3player but need to have the horontal component advance as the sound progreses. Any ideas?

       

      Thanks for any help!

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" applicationComplete="appComplete()">

       

      <mx:Script>
              <![CDATA[


                  import mx.controls.Alert;
                  private static const MP3_URL:String = "sounds/sounda.mp3";
                  private var sound:Sound = null;
                  private var soundChannel:SoundChannel = null;
                  private var playResumePosition:Number = 0;
                  private var loaded:Boolean = false;
                 
                  private function appComplete():void
                  {
                      sound = new Sound();
                      sound.load(new URLRequest(MP3_URL));
                      sound.addEventListener(IOErrorEvent.IO_ERROR, function(event:IOError):void
                          {
                              Alert.show("There was an error loading the MP3 file");   
                          }
                      );
                     
                      sound.addEventListener(Event.COMPLETE, function(event:Event):void
                          {
                              loadingProgress.visible = false;
                              loaded = true;
                              soundChannel = sound.play();
                          }
                      );
                     
                      sound.addEventListener(ProgressEvent.PROGRESS, function(event:ProgressEvent):void
                          {
                              loadingProgress.setProgress(event.bytesLoaded, event.bytesTotal);
                          }
                      );
                  }
                 
                  private function play():void
                  {
                      if (loaded)
                      {
                          soundChannel.stop();
                          soundChannel = sound.play(playResumePosition);
                      }
                  }
                 
                  private function stop():void
                  {
                      if (loaded)
                      {
                          playResumePosition = 0;
                          soundChannel.stop();                   
                      }
                  }
                 
                  private function pause():void
                  {
                      if (loaded)
                      {
                          playResumePosition = soundChannel.position;
                          soundChannel.stop();
                      }
                  }
                 
                  private function onChangeVolSlider(event:Event):void{
                   SoundMixer.soundTransform = new SoundTransform(event.currentTarget.value);
                  }
              ]]>
          </mx:Script>

       

          <mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" title="MP3Player" showCloseButton="true" height="161" width="294" x="181" y="46">
                      
          <mx:Button x="11" y="39" label="Play" click="play()" />
          <mx:Button x="70" y="39" label="Pause" click=" pause()" />
          <mx:Button x="137" y="40" label="Stop" click="stop()" />
          <mx:VSlider x="215" y="8" height="95" labels="[0,25,50,100]" change="onChangeVolSlider(event)" minimum="0" maximum="1" liveDragging="true" showDataTip="false" allowTrackClick="true" value="1"/>
          <mx:HSlider x="12" y="88" width="177"/>
          <mx:ProgressBar width="166" mode="manual" id="loadingProgress" x="15" y="6"/>

       

      </mx:TitleWindow>
      </mx:Application>