title: Android Camera 2 Api
body: <p>I have been trying camera2 API. I have downloaded code from </p>
  
  <p><a href="https://developer.android.com/samples/Camera2Video/index.html">https://developer.android.com/samples/Camera2Video/index.html</a> to learn about how it works. It works fine till I stop recording. When I stop recording it runs following code.</p>
  
  <pre><code> private void stopRecordingVideo() {
          // UI
          mIsRecordingVideo = false;
          mBtn_Video.setText(R.string.record);
          // Stop recording
          try {
              mMediaRecorder.stop();
              mMediaRecorder.reset();
          }
          catch (Exception e) {
              e.printStackTrace();
          }
          Activity activity = getActivity();
          if (null != activity) {
              System.out.println("file " +  getVideoFile(activity));
              Toast.makeText(activity, "Video saved: " + getVideoFile(activity),
                      Toast.LENGTH_SHORT).show();
          }
          startPreview();
  </code></pre>
  
  <p>at mMediaRecorder.stop(); it throw following error</p>
  
  <pre><code>01-12 16:24:23.115    2161-2200/com.cameratwoapi E/Surface﹕ queueBuffer: error queuing buffer to SurfaceTexture, -19
  01-12 16:24:23.135    2161-2200/com.cameratwoapi E/EGL_emulation﹕ tid 2200: swapBuffers(285): error 0x3003 (EGL_BAD_ALLOC)
  01-12 16:24:23.197    2161-2200/com.cameratwoapi E/CameraDeviceGLThread-0﹕ Received exception on GL render thread:
      java.lang.IllegalStateException: swapBuffers: EGL error: 0x3003
              at android.hardware.camera2.legacy.SurfaceTextureRenderer.checkEglError(SurfaceTextureRenderer.java:487)
              at android.hardware.camera2.legacy.SurfaceTextureRenderer.swapBuffers(SurfaceTextureRenderer.java:480)
              at android.hardware.camera2.legacy.SurfaceTextureRenderer.drawIntoSurfaces(SurfaceTextureRenderer.java:681)
              at android.hardware.camera2.legacy.GLThreadManager$1.handleMessage(GLThreadManager.java:103)
              at android.os.Handler.dispatchMessage(Handler.java:98)
              at android.os.Looper.loop(Looper.java:135)
              at android.os.HandlerThread.run(HandlerThread.java:61)
  </code></pre>
  
  <p>Any Idea what I am doing wrong. I spent few hours but couldn't find any solution.</p>
  
  <p>Edit - I am using geneymotion emulator. The path I am using </p>
  
  <p>file /storage/emulated/0/Android/data/com.gold.cameratwoapi/files/video.mp4</p>
  
  <p>Thanks</p>