title: android Audio Record not playing the whole PCM file
body: <p>I have my PCM file recorded using.</p>
  
  <pre><code>try {
  
          DataOutputStream dos = new DataOutputStream(
                  new BufferedOutputStream(
                          new FileOutputStream(recordingFile)));
  
          int bufferSize = AudioRecord.getMinBufferSize(frequency,
                  channelConfiguration, audioEncoding);
  
          AudioRecord audioRecord = new AudioRecord(
                  MediaRecorder.AudioSource.MIC, frequency,
                  channelConfiguration, audioEncoding, bufferSize);
  
          AudioTrack audioPlayer = new AudioTrack(AudioManager.STREAM_MUSIC,
                  frequency, AudioFormat.CHANNEL_OUT_STEREO, audioEncoding,
                  bufferSize, AudioTrack.MODE_STREAM);
  
          short[] buffer = new short[blockSize];
          double[] toTransform = new double[blockSize];
          int readBytes = 0;
          int writtenBytes = 0;
  
          audioRecord.startRecording();
          audioPlayer.play();
  
          AudioManager audioManager = (AudioManager) ctx
                  .getSystemService(Context.AUDIO_SERVICE);
  
          while (started) {
              int bufferReadResult = audioRecord.read(buffer, 0, blockSize);
  
              for (int i = 0; i &lt; blockSize &amp;&amp; i &lt; bufferReadResult; i++) {
                  toTransform[i] = (double) buffer[i] / 32768.0; // signed
                  // 16
                  dos.writeShort(buffer[i]);
  
              } // bit
  
              // filterAudio(bufferSize, toTransform, frequency);
              transformer.ft(toTransform);
              publishProgress(toTransform);
  
              // capture data and record to file
  
              if (audioManager.isWiredHeadsetOn()) {
                  if (audioPlayer.getPlayState() != AudioTrack.PLAYSTATE_PLAYING) {
                      audioPlayer.play();
                  }
                  if (AudioRecord.ERROR_INVALID_OPERATION != bufferReadResult) {
                      writtenBytes += audioPlayer.write(buffer, 0,
                              bufferReadResult);
                  }
              } else {
                  if (audioPlayer.getPlayState() == AudioTrack.PLAYSTATE_PLAYING) {
                      audioPlayer.pause();
                  }
              }
  
          }
  
          audioRecord.stop();
          audioPlayer.stop();
          audioRecord.release();
          audioPlayer.release();
          try {
              dos.close();
          } catch (Exception e) {
              e.printStackTrace();
          }
  
      } catch (Throwable t) {
          t.printStackTrace();
          Log.e("AudioRecord", "Recording Failed");
      }
  
      return null;
  </code></pre>
  
  <p>and I play it by:</p>
  
  <pre><code>private AsyncTask&lt;Void, Void, Void&gt; task = new AsyncTask&lt;Void, Void, Void&gt;() {
  
      @Override
      protected Void doInBackground(Void... params) {
          try {
  
              musicLength = (int) (recordedFile.length() / 2);
              music = new short[musicLength];
  
              InputStream is = new FileInputStream(recordedFile);
              BufferedInputStream bis = new BufferedInputStream(is);
              DataInputStream dis = new DataInputStream(bis);
  
              int i = 0;
              while (dis.available() &gt; 0) {
                  music[i] = dis.readShort();
                  i++;
              }
  
              dis.close();
  
              audioTrackRecorded = new AudioTrack(AudioManager.STREAM_MUSIC,
                      frequency, AudioFormat.CHANNEL_CONFIGURATION_STEREO,
                      AudioFormat.ENCODING_PCM_16BIT, musicLength,
                      AudioTrack.MODE_STREAM);
  
              audioTrackRecorded.write(music, 0, musicLength);
  
          } catch (Exception e) {
              e.printStackTrace();
          }
          return null;
      }
  
      protected void onPostExecute(Void result) {
          progressBarLayout.setVisibility(View.GONE);
          seekbarLayout.setVisibility(View.VISIBLE);
  
          isInitialized = true;
  
      };
  };
  </code></pre>
  
  <p>I'm having a problem playing this PCM, I got only Half of it during play back. Hope you could help me in this. Thank you.</p>