title: Android Camera2 getPreviewFrame
body: <p>I am trying to get the camera frame in preview mode. I am running the sample project from github <a href="https://github.com/googlesamples/android-Camera2Basic">https://github.com/googlesamples/android-Camera2Basic</a></p>
  
  <p>The issue I am having is getting the frame in preview mode.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>private CameraCaptureSession.CaptureCallback mCaptureCallback = new CameraCaptureSession.CaptureCallback() {
  
      private void process(CaptureResult result) {
          switch (mState) {
              case STATE_PREVIEW: {
  
                  //HERE, HOW CAN I RETRIEVE THE CURRENT FRAME?
  
                  break;
              }
              case STATE_WAITING_LOCK: {
                 ...
                  break;
              }
              case STATE_WAITING_PRECAPTURE: {
               ...
                  break;
              }
              case STATE_WAITING_NON_PRECAPTURE: {
               ...
                  break;
              }
          }
      }
  </code></pre>
  
  <p>Another thing I tried to get the frame is setting the  mImageReader.setOnImageAvailableListener.
  I was expecting to be able to get the frame onImageAvailable callback, but onImageAvailable is never called. onPreviewFrame is my own method, I need to pass it the current frame.</p>
  
  <pre><code>  mImageReader = ImageReader.newInstance(largest.getWidth(), largest.getHeight(), ImageFormat.JPEG, /*maxImages*/2);
    mImageReader.setOnImageAvailableListener(mOnImageAvailableListener, mBackgroundHandler);
  
    private final ImageReader.OnImageAvailableListener mOnImageAvailableListener  = new ImageReader.OnImageAvailableListener() {
  
      @Override
      public void onImageAvailable(ImageReader reader) {
          mTextureView.onPreviewFrame(reader.acquireNextImage().getPlanes([0].getBuffer().array());
      }
  
  };
  </code></pre>
  
  <p>What I am doing wrong?
  Thanks.</p>