0 Replies Latest reply on Mar 11, 2010 5:52 AM by david128

    Sound.extract problem...bug (i think it is) ?

    david128

      Hi all.

      I rewrite an "old" MP3 application from Flex 3 to Flash Builder.

      I have weird problem with a function that work like a charm before.

      I try to find the problem, and it seems to be the extract function of Sound instance.

       

      ok...demo (AIR 2.0 - Framework 14607):

       

      <?xml version="1.0" encoding="utf-8"?>
      <s:WindowedApplication
          initialize="onInitialize()"
          xmlns:fx="http://ns.adobe.com/mxml/2009"
          xmlns:s="library://ns.adobe.com/flex/spark"
          xmlns:mx="library://ns.adobe.com/flex/halo">
         
          <fx:Script>
              <![CDATA[
                  import flash.events.Event;
                  import flash.events.IOErrorEvent;
                  import flash.media.Sound;
                  import flash.net.URLRequest;
                  import flash.utils.ByteArray;
                 
                  private static const MP3_URL:    String = File.desktopDirectory.resolvePath("c.mp3").url;
                  private var _oSound:            Sound;
                             
                  private function onInitialize() : void
                  {
                      //Load MP3 file
                      var oErrorHandler: Function = function(oEvent: IOErrorEvent) : void
                      {
                          trace("Error: " + oEvent.text);
                      };
                      _oSound = new Sound();
                      _oSound.addEventListener(IOErrorEvent.IO_ERROR,    oErrorHandler);
                      _oSound.addEventListener(Event.COMPLETE,        onLoadFileComplete);
                      _oSound.load(new URLRequest(MP3_URL));
                  }
                 
                 
                  private function onLoadFileComplete(oEvent: Event) : void
                  {
                      var oBuffer:            ByteArray    = new ByteArray();
                      var oSampleCount:        Number        = 0;
                      var oSampleExtracted:    Number;
                     
                      //Count sample count
                      while(true)
                      {
                          oBuffer.position = 0;
                          oSampleExtracted = _oSound.extract(oBuffer, 4096);
                          if (oSampleExtracted == 0) break;
                          oSampleCount += oSampleExtracted;
                      }
                     
                      //
      *** ERROR IS HERE ***

                      trace(_oSound.extract(oBuffer, 1, oSampleCount-1));    //Read last sample => OK (trace 1)
                      trace(_oSound.extract(oBuffer, 1, 0));                //Read first sample => OK (trace 1)
                      trace(_oSound.extract(oBuffer, 1, oSampleCount-1));    //ReRead last sample => !!! ERROR !!! (trace 0)
                  }
              ]]>
          </fx:Script>
      </s:WindowedApplication>

       

      Can someone confirm this ?