欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Android Camera相机 Camera is being used after Camera.release() was called

程序员文章站 2022-06-15 14:06:25
...

camera在切换前后摄像头时的异常

    Process: com.test.wrapper, PID: 8923
    java.lang.RuntimeException: Camera is being used after Camera.release() was called
        at android.hardware.Camera.setHasPreviewCallback(Native Method)
        at android.hardware.Camera.-wrap1(Unknown Source:0)
        at android.hardware.Camera$EventHandler.handleMessage(Camera.java:1237)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:173)
        at android.app.ActivityThread.main(ActivityThread.java:6698)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:782)
原因:

缺少mCamera?.setPreviewCallback(null)
果然调试代码时候还是要小心翼翼点儿啊...

       mCamera?.stopPreview()
       mCamera?.setPreviewDisplay(null)
       mCamera?.setPreviewCallback(null)
       mCamera?.lock()
       mCamera?.release()
       mCamera = null

转载于:https://www.jianshu.com/p/bbdeea0d94a0