title: android.media.MediaCodec throws exception on queueInputBuffer()
body: <p>I need to convert audio file from PCM to AMR and I tried to make it with MediaCodec from Android API 16+. I got an IllegalStateException on calling it's queueInputBuffer:</p>
  
  <pre><code>07-16 19:40:55.519: E/AndroidRuntime(19227): FATAL EXCEPTION: main
  07-16 19:40:55.519: E/AndroidRuntime(19227): java.lang.IllegalStateException
  07-16 19:40:55.519: E/AndroidRuntime(19227):    at android.media.MediaCodec.queueInputBuffer(Native Method)
  </code></pre>
  
  <p>Here is my code:</p>
  
  <pre><code>    private static MediaCodec mediaCodec;
  
      private static void initMediaCodec() {
          mediaCodec = MediaCodec.createEncoderByType("audio/3gpp");
          MediaFormat mediaFormat = MediaFormat.createAudioFormat("audio/3gpp", 8000, 1);
          mediaFormat.setInteger(MediaFormat.KEY_BIT_RATE, 12800);
          mediaFormat.setInteger(MediaFormat.KEY_SAMPLE_RATE, 8000);
          mediaFormat.setInteger(MediaFormat.KEY_CHANNEL_COUNT, 1);
          mediaCodec.configure(mediaFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
          mediaCodec.start();
      }
  
  &lt;...&gt;
          initMediaCodec();       
          ByteBuffer[] inputBuffers = mediaCodec.getInputBuffers();
          ByteBuffer[] outputBuffers = mediaCodec.getOutputBuffers();
          int inputBufferIndex = mediaCodec.dequeueInputBuffer(-1);
          if (inputBufferIndex &gt;= 0) {
              ByteBuffer inputBuffer = inputBuffers[inputBufferIndex];
              inputBuffer.clear();
              inputBuffer.put(fileBuffer); //fileBuffer is ByteBuffer from my input audio file
              mediaCodec.queueInputBuffer(inputBufferIndex, 0, fileBuffer.capacity(), 0, 0);
          }
  &lt;...&gt;
  </code></pre>
  
  <p>I mentioned that inputBuffers has 4 elements in it with capacity of 320, my audio file buffer might have capacity 96000+.</p>
  
  <p>Any help will be appreciate. Thanks!</p>