app/src/main/java/com/quintessential/gypsy/CameraHelper.java
/*
      Starts camera preview.
      Method should only be called when state is CameraHelperState.STARTED
   */
Starts camera preview.
Method should only be called when state is CameraHelperState.STARTED
Starts camera preview . Method should only be called when state is CameraHelperState . STARTED
private void startPreviewing(@NonNull SurfaceTexture texture) {
        Log.d(LOG_TAG, "startPreviewing");
        try {
            safeCamera.setPreviewTexture(texture);
        } catch (IOException e) {
            Log.i(LOG_TAG, "Unable to start camera preview" + e.getMessage());
        }
        orientationHelper.enable();
        safeCamera.setOneShotPreviewCallback(new Camera.PreviewCallback() {
            @Override
            public void onPreviewFrame(byte[] data, Camera camera) {
                if (listener != null) {
                    listener.onFrameAvailable(data, previewWidth, previewHeight, frameRotation);
                }
                setupPreviewWithCallbackBuffers();
            }
        });
        isPreviewing = true;
        try {
            safeCamera.startPreview();
        } catch (Exception e) {
            Log.e(LOG_TAG, "Failed to start preview!");
            stopPreviewing();
        }
    }
private void startPreviewing ( @ NonNull SurfaceTexture texture ) { Log . d ( LOG_TAG , "startPreviewing" ) ; try { safeCamera . setPreviewTexture ( texture ) ; } catch ( IOException e ) { Log . i ( LOG_TAG , "Unable to start camera preview" + e . getMessage ( ) ) ; } orientationHelper . enable ( ) ; safeCamera . setOneShotPreviewCallback ( new Camera . PreviewCallback ( ) { @ Override public void onPreviewFrame ( byte [ ] data , Camera camera ) { if ( listener != null ) { listener . onFrameAvailable ( data , previewWidth , previewHeight , frameRotation ) ; } setupPreviewWithCallbackBuffers ( ) ; } } ) ; isPreviewing = true ; try { safeCamera . startPreview ( ) ; } catch ( Exception e ) { Log . e ( LOG_TAG , "Failed to start preview!" ) ; stopPreviewing ( ) ; } }
Starts camera preview.
Starts camera preview .
// setPreviewCallbackWithBuffer only seems to work if you establish it after the first onPreviewFrame callback // (otherwise it never gets called back at all). So, use a one-shot callback for the first one, then // swap in the callback that uses the buffers.