title: android record mic to ByteArray without saving audio file
body: <p>Sorry for my bad english :(</p>
  
  <p>I start my project for android application, this app record microphone, if I click to start record button the app get microphone and write it on a file and when I click to stop , a file saved into SD card.</p>
  
  <p>project code :</p>
  
  <p><em><strong>The output file</em></strong></p>
  
  <pre><code>OUTPUT_FILE = Environment.getExternalStorageState() + "/myaudio.3gp";
  </code></pre>
  
  <p><em><strong>Start recording</em></strong></p>
  
  <pre><code>public void startRecord() throws IOException{
      if (recorder != null)
      {
          recorder.release();
      }
      File outFile = new File(OUTPUT_FILE);
      if (outFile.exists())
      {
          outFile.delete();
      }
  
      recorder = new MediaRecorder();
      recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
      recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
      recorder.setOutputFormat(MediaRecorder.AudioEncoder.AMR_NB);
      recorder.setOutputFile(OUTPUT_FILE);
      recorder.prepare();
      recorder.start();
  }
  </code></pre>
  
  <p><em><strong>Stop recording</em></strong></p>
  
  <pre><code>public void stopRec(){
      recorder.stop();
  }
  </code></pre>
  
  <p><em><strong>PlaySound recorded file</em></strong></p>
  
  <pre><code>public void playRecFile() throws IOException{
      mediaPlayer = new MediaPlayer();
      mediaPlayer.setDataSource(OUTPUT_FILE);
      mediaPlayer.prepare();
      mediaPlayer.start();
  
  }
  </code></pre>
  
  <p>I want to get recorded voice and put it into a variable ByteArray and play it whitout saving the audio file to SD card</p>
  
  <p>I have a project like what I want but it is written in actionscript 3</p>
  
  <pre><code>import flash.media.*;
  import flash.events.*;
  import flash.utils.ByteArray;
  
  var ch:SoundChannel
  var mic:Microphone = Microphone.getMicrophone();
  
  mic.addEventListener(SampleDataEvent.SAMPLE_DATA, micSampleDataHandler);
  mic.addEventListener(ActivityEvent.ACTIVITY,onAct);
  
  function onAct(evt:ActivityEvent):void
  {
      trace(evt.activating,mic.activityLevel);
      if (!evt.activating)
      {
          if (soundBytes.length)
          {
              timerHandler();
          }
      }
  }
  
  var soundBytes:ByteArray = new ByteArray();
  var soundO:ByteArray = new ByteArray();
  
  function micSampleDataHandler(event:SampleDataEvent):void
  {
      trace(event.data.length,event.data.bytesAvailable, soundBytes.length);
      while (event.data.bytesAvailable)
      {
          var sample:Number = event.data.readFloat();
          soundBytes.writeFloat(sample);
      }
  }
  
  function timerHandler():void
  {
      mic.removeEventListener(SampleDataEvent.SAMPLE_DATA, micSampleDataHandler);
      soundBytes.position = 0;
      soundO.writeBytes(soundBytes);
      soundO.position = 0;
      soundBytes.position = 0;
      soundBytes.length=0;
  
      var sound:Sound= new Sound();
      sound.addEventListener(SampleDataEvent.SAMPLE_DATA, playbackSampleHandler);
      ch=sound.play();
      ch.addEventListener(Event.SOUND_COMPLETE,onSC)
      trace("OUTPUT",soundO.bytesAvailable);
  
  }
  function onSC(evt:Event):void
  {
      trace("SOUND_COMPLETE");
  }
  function playbackSampleHandler(event:SampleDataEvent):void
  {
      trace("SAMPLE_DATA: ",soundO.bytesAvailable)
      for (var i:int = 0; i &lt; 8192; i++)
      {
          if (soundO.bytesAvailable &lt; 4)
          {
           break;
          }
          var sample:Number = soundO.readFloat();
          event.data.writeFloat(sample);
          event.data.writeFloat(sample);      
      }
      if (soundO.bytesAvailable &lt; 4 &amp;&amp; soundO.position!==0)
      {
          mic.addEventListener(SampleDataEvent.SAMPLE_DATA, micSampleDataHandler);
          soundO.position=0
          soundO.length = 0;
  
          trace("END
      }
  }
  </code></pre>