title: audiotrack: playing noise for a raw pcm 16bit wav file
body: <p>I am trying to play a wav file of size 230mb and 20 min whose properties are as below: </p>
  
  <pre><code>ffmpeg -i 1.wav
  
  Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, stereo, s16, 1411 kb/s
  </code></pre>
  
  <p>I am learning how to use audiotrack.</p>
  
  <p>I found two solutions to play this audio play using audiotrack.</p>
  
  <p><strong>Solution 1: the following plays the audio</strong></p>
  
  <pre><code>int frequency = 44100;
  int channelConfiguration = AudioFormat.CHANNEL_CONFIGURATION_STEREO;
  int audioEncoding = AudioFormat.ENCODING_PCM_16BIT;
  
  int bufferSize = AudioTrack.getMinBufferSize(frequency, channelConfiguration,audioEncoding);
  
  AudioTrack audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, frequency,
          channelConfiguration, audioEncoding, bufferSize,
          AudioTrack.MODE_STREAM);
  
  int count = 0;
  byte[] data = new byte[bufferSize];
  try{
      FileInputStream fileInputStream = new FileInputStream(listMusicFiles.get(0).listmusicfiles_fullfilepath);
      DataInputStream dataInputStream = new DataInputStream(fileInputStream);
      audioTrack.play();
  
      while((count = dataInputStream.read(data, 0, bufferSize)) &gt; -1){
          audioTrack.write(data, 0, count);
      }
  
      audioTrack.stop();
      audioTrack.release();
      dataInputStream.close();
      fileInputStream.close();
  }
  catch (FileNotFoundException e){
      e.printStackTrace();
  } catch (IOException e) {
      e.printStackTrace();
  }
  </code></pre>
  
  <p><strong>Second Solution: Playing noise</strong></p>
  
  <pre><code>int frequency = 44100;
  int channelConfiguration = AudioFormat.CHANNEL_CONFIGURATION_STEREO;
  int audioEncoding = AudioFormat.ENCODING_PCM_16BIT;
  
  int bufferSize = AudioTrack.getMinBufferSize(frequency, channelConfiguration,audioEncoding);
  
  short[] audiodata = new short[bufferSize];
  
  try {
  
      DataInputStream dis = new DataInputStream(
              new BufferedInputStream(new FileInputStream(
                      listMusicFiles.get(0).listmusicfiles_fullfilepath)));
  
      AudioTrack audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, frequency,
              channelConfiguration, audioEncoding, bufferSize,
              AudioTrack.MODE_STREAM);
  
      audioTrack.play();
  
      while (dis.available() &gt; 0) {
          int i = 0;
          while (dis.available() &gt; 0 &amp;&amp; i &lt; audiodata.length) {
              audiodata[i] = dis.readShort();
              i++;
          }
          audioTrack.write(audiodata, 0, audiodata.length);
      }
  
      dis.close();
  } catch (Throwable t) {
      Log.e("AudioTrack", "Playback Failed");
  }
  </code></pre>
  
  <p>I am new to short sample and byte samples. I tried to understand but it not so easy.</p>
  
  <p>I could understand the first solution is using byte sample and the second solution is using short samples.</p>
  
  <p>So why is the second solution not working.</p>