title: Android:Playing AudioTrack multiple times producing crash
body: <p>I am trying to play audio buffered sound (.wav) using AudioTrack. Please see the code below. I need to call this function under a Thread to support simultaneous play. It is fine being under a Thread. It is working fine playing the sound normally. But if i execute playing the sound using AudioTrack one after another continuously(i.e. executing second play before completing the first play sound), produces device crash (force close unexpectedly error).
  Does anyone come across such problems and resolve it in a way?</p>
  
  <pre><code>private void PlayAudioTrack(String filePath) throws IOException
  {
  
      if (filePath==null)
          return;
  
      byte[] byteData = null;
  
      File file = null; 
      file = new File(filePath); // sdcard path
      byteData = new byte[(int) file.length()];
      FileInputStream in = null;
      try {
          in = new FileInputStream( file );
          in.read( byteData );
          in.close(); 
  
      } catch (FileNotFoundException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  
      int intSize = android.media.AudioTrack.getMinBufferSize(8000, AudioFormat.CHANNEL_CONFIGURATION_MONO,
              AudioFormat.ENCODING_PCM_8BIT);
  
      at = new AudioTrack(AudioManager.STREAM_MUSIC, 8000, AudioFormat.CHANNEL_CONFIGURATION_MONO,
                          AudioFormat.ENCODING_PCM_8BIT, intSize, AudioTrack.MODE_STREAM);
  
      at.play();
  
      at.write(byteData, 0, byteData.length);
      at.stop();              
  
  }
  </code></pre>
  
  <p>Appreciate your response.</p>
  
  <p>Thanks.</p>