title: FATAL EXCEPTION: CameraX-audio encoding thread
body: <p>I am recording videos using the camera X library. When i take video for 5 seconds before that (i,e)two seconds if i close the video its crashing with above error.How to handle this run time exception in android cameraX library</p>
  
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: CameraX-audio encoding thread
  Process: .debug, PID: 4625
  java.lang.IllegalStateException
      at android.media.MediaCodec.native_dequeueOutputBuffer(Native Method)
      at android.media.MediaCodec.dequeueOutputBuffer(MediaCodec.java:2698)
      at androidx.camera.core.VideoCapture.audioEncode(VideoCapture.java:705)
      at androidx.camera.core.VideoCapture$1.run(VideoCapture.java:340)
      at android.os.Handler.handleCallback(Handler.java:873)
      at android.os.Handler.dispatchMessage(Handler.java:99)
      at android.os.Looper.loop(Looper.java:201)
      at android.os.HandlerThread.run(HandlerThread.java:65)
  </code></pre>
  
  <p>sometimes the below issue </p>
  
  <pre><code>FATAL EXCEPTION: CameraX-video encoding thread
  Process: &lt;packagename&gt;, PID: 10794
  java.lang.NullPointerException: Attempt to invoke virtual method 'int android.media.MediaCodec.dequeueOutputBuffer(android.media.MediaCodec$BufferInfo, long)' on a null object reference
      at androidx.camera.core.VideoCapture.videoEncode(VideoCapture.java:604)
      at androidx.camera.core.VideoCapture$2.run(VideoCapture.java:348)
      at android.os.Handler.handleCallback(Handler.java:873)
      at android.os.Handler.dispatchMessage(Handler.java:99)
      at android.os.Looper.loop(Looper.java:193)
      at android.os.HandlerThread.run(HandlerThread.java:65)
  </code></pre>
  
  <p>in this samples also not fixed yet
  <a href="https://github.com/android/camera-samples/issues/2#issuecomment-546812852" rel="nofollow noreferrer">https://github.com/android/camera-samples/issues/2#issuecomment-546812852</a></p>