0 Replies Latest reply on Dec 15, 2011 3:29 AM by hincauti

    AIR mobile for android, saving file in documents directory - weird behavior!

    hincauti Level 1

      Hi there,

      I have a function which automatically saves a wav file into the documents directory. When I simulate the application on my computer the .wav file lenght is as it should be - 20 seconds. When I run the application on my phone, the .wav file lenght is either 4, 5, 6 or 7 seconds. Does anybody know why is this happening?

       

      this is the function:

       

      protected function concatSounds():void{
      
                      output_ba.writeBytes(sound_ba, 0);
                      output_ba.writeBytes(silence_ba);
                      for (var i:int = 0; i <= 20; i++){
                          output_ba.writeBytes(sound_ba);
                          output_ba.writeBytes(silence_ba);
      
                          if(i == 20){
                              output_ba = encoder.encode(output_ba,1);
                              test.text = String (output_ba.length);
                          }
                      }
                  }
      

       

      the output sound is a 20 seconds heart beat sound, that's why in my output_ba(byte array) I'm writing in a "beat - silence- beat - silence....etc." sequence.

      1. the 'beat' sound in this case has 480 milliseconds;

      2. the 'silence' in this example has say 500 milliseconds;

       

      though the final sound should have (480 + 500) * 20 = 19.6 seconds as it actually is when running the app in a simulator, not the case when running on the actual device.

       

      in order to save the wav file i'm using this function:

       

      protected function onSaveSound():void{
                      
                      soundFile.resolvePath("Pulsimeter/Sounds/sample.wav");
                      var fileStream:FileStream = new FileStream();
                      fileStream.openAsync(soundFile, FileMode.WRITE);
                      fileStream.writeBytes(output_ba);
                      fileStream.close();
                  }
      

       

      I have no ideea why on my phone, the for loop doesn't run 20 times.