I built a camera app for android in android studio and implementing video recording functionality (full screen preview). It records video successfully but when I press 'stop recording' button, it freezes the preview at last captured frame and stays there and displays a toast message: "Unable to setup camera preview". Here is my logcat messages:
12-21 16:39:05.924 9398-9398/com.example.androidcameraapp I/art: Late-enabling -Xcheck:jni
12-21 16:39:05.987 9398-9398/com.example.androidcameraapp W/ActivityThread: Application com.example.androidcameraapp is waiting for the debugger on port 8100...
12-21 16:39:05.987 9398-9398/com.example.androidcameraapp I/System.out: Sending WAIT chunk
12-21 16:39:06.849 9398-9408/com.example.androidcameraapp I/art: Debugger is active
12-21 16:39:06.989 9398-9398/com.example.androidcameraapp I/System.out: Debugger has connected
12-21 16:39:06.989 9398-9398/com.example.androidcameraapp I/System.out: waiting for debugger to settle...
12-21 16:39:07.189 9398-9398/com.example.androidcameraapp I/System.out: waiting for debugger to settle...
12-21 16:39:07.390 9398-9398/com.example.androidcameraapp I/System.out: waiting for debugger to settle...
12-21 16:39:07.591 9398-9398/com.example.androidcameraapp I/System.out: waiting for debugger to settle...
12-21 16:39:07.791 9398-9398/com.example.androidcameraapp I/System.out: waiting for debugger to settle...
12-21 16:39:07.992 9398-9398/com.example.androidcameraapp I/System.out: waiting for debugger to settle...
12-21 16:39:08.192 9398-9398/com.example.androidcameraapp I/System.out: waiting for debugger to settle...
12-21 16:39:08.392 9398-9398/com.example.androidcameraapp I/System.out: waiting for debugger to settle...
12-21 16:39:08.592 9398-9398/com.example.androidcameraapp I/System.out: waiting for debugger to settle...
12-21 16:39:08.793 9398-9398/com.example.androidcameraapp I/System.out: waiting for debugger to settle...
12-21 16:39:08.993 9398-9398/com.example.androidcameraapp I/System.out: debugger has settled (1437)
12-21 16:39:09.923 9398-9398/com.example.androidcameraapp W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
12-21 16:39:10.186 9398-9655/com.example.androidcameraapp D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
12-21 16:39:10.197 9398-9398/com.example.androidcameraapp D/Atlas: Validating map...
12-21 16:39:10.244 9398-9655/com.example.androidcameraapp I/Adreno-EGL: <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_LA.BF.1.1.1_RB1.05.00.02.042.016_msm8226_LA.BF.1.1.1_RB1__release_AU ()
OpenGL ES Shader Compiler Version: E031.25.03.00
Build Date: 02/11/15 Wed
Local Branch:
Remote Branch: quic/LA.BF.1.1.1_rb1.10
Local Patches: NONE
Reconstruct Branch: AU_LINUX_ANDROID_LA.BF.1.1.1_RB1.05.00.02.042.016 + 62ca4eb + acd831d + 9f8b442 + e027a02 + cba30ba + 53c303a + a649d79 + 23e16f8 + 5e97da7 + cbd2a44 + 33d072a + 7aacf06 + 72b33e7 + 28f6f60 + b4c13d8 + NOTHING
12-21 16:39:10.245 9398-9655/com.example.androidcameraapp I/OpenGLRenderer: Initialized EGL, version 1.4
12-21 16:39:10.262 9398-9655/com.example.androidcameraapp D/OpenGLRenderer: Enabling debug mode 0
12-21 16:39:10.288 9398-9398/com.example.androidcameraapp I/CameraManagerGlobal: getCameraService: Reconnecting to camera service
12-21 16:39:10.344 9398-9398/com.example.androidcameraapp I/CameraManager: Using legacy camera HAL.
12-21 16:39:10.716 9398-9656/com.example.androidcameraapp I/CameraDeviceState: Legacy camera service transitioning to state CONFIGURING
12-21 16:39:10.730 9398-9698/com.example.androidcameraapp I/RequestThread-0: Configure outputs: 1 surfaces configured.
12-21 16:39:10.730 9398-9698/com.example.androidcameraapp D/Camera: app passed NULL surface
12-21 16:39:10.814 9398-9656/com.example.androidcameraapp I/CameraDeviceState: Legacy camera service transitioning to state IDLE
12-21 16:39:10.827 9398-9656/com.example.androidcameraapp I/RequestQueue: Repeating capture request set.
12-21 16:39:10.833 9398-9698/com.example.androidcameraapp W/LegacyRequestMapper: convertRequestMetadata - control.awbRegions setting is not supported, ignoring value
12-21 16:39:10.833 9398-9698/com.example.androidcameraapp W/LegacyRequestMapper: Only received metering rectangles with weight 0.
12-21 16:39:10.833 9398-9698/com.example.androidcameraapp W/LegacyRequestMapper: Only received metering rectangles with weight 0.
12-21 16:39:10.898 9398-9398/com.example.androidcameraapp I/Choreographer: Skipped 36 frames! The application may be doing too much work on its main thread.
12-21 16:39:11.196 9398-9708/com.example.androidcameraapp I/CameraDeviceState: Legacy camera service transitioning to state CAPTURING
12-21 16:39:18.826 9398-9398/com.example.androidcameraapp I/RequestQueue: Repeating capture request cancelled.
12-21 16:39:18.871 9398-9698/com.example.androidcameraapp I/CameraDeviceState: Legacy camera service transitioning to state IDLE
12-21 16:39:18.873 9398-9398/com.example.androidcameraapp I/CameraDeviceState: Legacy camera service transitioning to state CONFIGURING
12-21 16:39:18.873 9398-9698/com.example.androidcameraapp I/RequestThread-0: Configure outputs: 2 surfaces configured.
12-21 16:39:19.085 9398-9698/com.example.androidcameraapp D/Camera: app passed NULL surface
12-21 16:39:19.130 9398-9398/com.example.androidcameraapp I/CameraDeviceState: Legacy camera service transitioning to state IDLE
12-21 16:39:19.135 9398-9398/com.example.androidcameraapp I/Choreographer: Skipped 38 frames! The application may be doing too much work on its main thread.
12-21 16:39:19.148 9398-9398/com.example.androidcameraapp I/RequestQueue: Repeating capture request set.
12-21 16:39:19.157 9398-9698/com.example.androidcameraapp W/LegacyRequestMapper: convertRequestMetadata - control.awbRegions setting is not supported, ignoring value
12-21 16:39:19.157 9398-9698/com.example.androidcameraapp W/LegacyRequestMapper: Only received metering rectangles with weight 0.
12-21 16:39:19.157 9398-9698/com.example.androidcameraapp W/LegacyRequestMapper: Only received metering rectangles with weight 0.
12-21 16:39:19.533 9398-9708/com.example.androidcameraapp I/CameraDeviceState: Legacy camera service transitioning to state CAPTURING
12-21 16:39:26.624 9398-9398/com.example.androidcameraapp I/RequestQueue: Repeating capture request cancelled.
12-21 16:39:26.630 9398-9708/com.example.androidcameraapp W/Adreno-EGLSUB: <DequeueBuffer:720>: dequeue native buffer fail: No such device, buffer=0x0, handle=0x0
12-21 16:39:26.630 9398-9708/com.example.androidcameraapp W/Adreno-EGL: <qeglDrvAPI_eglSwapBuffers:3702>: EGL_BAD_SURFACE
12-21 16:39:26.637 9398-9708/com.example.androidcameraapp E/CameraDeviceGLThread-0: Received exception on GL render thread:
java.lang.IllegalStateException: swapBuffers: EGL error: 0x300d
at android.hardware.camera2.legacy.SurfaceTextureRenderer.checkEglError(SurfaceTextureRenderer.java:530)
at android.hardware.camera2.legacy.SurfaceTextureRenderer.swapBuffers(SurfaceTextureRenderer.java:523)
at android.hardware.camera2.legacy.SurfaceTextureRenderer.drawIntoSurfaces(SurfaceTextureRenderer.java:729)
at android.hardware.camera2.legacy.GLThreadManager$1.handleMessage(GLThreadManager.java:105)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:135)
at android.os.HandlerThread.run(HandlerThread.java:61)
12-21 16:39:26.637 9398-9708/com.example.androidcameraapp I/CameraDeviceState: Legacy camera service transitioning to state ERROR
12-21 16:39:26.638 9398-9398/com.example.androidcameraapp I/CameraDeviceState: Legacy camera service transitioning to state CONFIGURING
12-21 16:39:26.638 9398-9398/com.example.androidcameraapp E/CameraDeviceState: Cannot call configure while in state: 0
12-21 16:39:26.648 9398-9398/com.example.androidcameraapp E/CameraCaptureSession: Session 2: Failed to create capture session; configuration failed
12-21 16:39:26.649 9398-9398/com.example.androidcameraapp D/Camera release Failed: ERROR releasing camera: Illegal state encountered in camera service.
12-21 16:39:26.738 9398-9655/com.example.androidcameraapp V/RenderScript: Application requested CPU execution
12-21 16:39:26.754 9398-9655/com.example.androidcameraapp V/RenderScript: 0xb7450bd8 Launching thread(s), CPUs 4
12-21 16:39:30.569 9398-9698/com.example.androidcameraapp E/RequestThread-0: Timed out while waiting for request to complete.
12-21 16:39:30.570 9398-9698/com.example.androidcameraapp W/CaptureCollector: Preview buffers dropped for request: 1
12-21 16:39:30.570 9398-9698/com.example.androidcameraapp E/CameraDeviceState: Cannot receive result while in state: 0
12-21 16:39:30.570 9398-9698/com.example.androidcameraapp E/CameraDeviceState: Cannot receive result while in state: 0
12-21 16:39:30.575 9398-9698/com.example.androidcameraapp E/CameraDeviceState: Cannot receive result while in state: 0
12-21 16:39:30.816 9398-9725/com.example.androidcameraapp E/BufferQueueProducer: [unnamed-9398-2] cancelBuffer: BufferQueue has been abandoned
12-21 16:39:30.816 9398-9415/com.example.androidcameraapp E/BufferQueueProducer: [unnamed-9398-2] cancelBuffer: BufferQueue has been abandoned
12-21 16:39:30.816 9398-9414/com.example.androidcameraapp E/BufferQueueProducer: [unnamed-9398-2] cancelBuffer: BufferQueue has been abandoned
12-21 16:39:30.817 9398-9725/com.example.androidcameraapp E/BufferQueueProducer: [unnamed-9398-2] cancelBuffer: BufferQueue has been abandoned
12-21 16:39:30.817 9398-9415/com.example.androidcameraapp E/BufferQueueProducer: [unnamed-9398-2] cancelBuffer: BufferQueue has been abandoned
12-21 16:39:30.817 9398-9414/com.example.androidcameraapp E/BufferQueueProducer: [unnamed-9398-2] cancelBuffer: BufferQueue has been abandoned
12-21 16:39:30.818 9398-9725/com.example.androidcameraapp E/BufferQueueProducer: [unnamed-9398-2] cancelBuffer: BufferQueue has been abandoned
12-21 16:39:30.818 9398-9415/com.example.androidcameraapp E/BufferQueueProducer: [unnamed-9398-2] cancelBuffer: BufferQueue has been abandoned
My MainActivity.java file is at the following link: https://drive.google.com/file/d/0B5iNYhRnlfTUTnFEbFVmNkkwSUE/view
I want that my application should show preview after the user have stopped recording video. What should I do to unfreeze the preview and ready to take another video recording?
You should reset your CaptureRequest.Builder to Preview state and then set the CaptureSession to repeat this request. Something like this:
I hope this helps.
Regards