在后置摄像头和前置摄像头之间切换时,我在Nexus S(Android 4.1.2)上遇到以下错误:
E/CameraHardwareSec(90): ERR(virtual android::status_t android::CameraHardwareSec::setParameters(const android::CameraParameters&)): preview is running, cannot change size and format!
紧接着是:
06-30 16:43:38.961: E/AndroidRuntime(10946): java.lang.RuntimeException: setParameters failed
06-30 16:43:38.961: E/AndroidRuntime(10946): at android.hardware.Camera.native_setParameters(Native Method)
06-30 16:43:38.961: E/AndroidRuntime(10946): at android.hardware.Camera.setParameters(Camera.java:1410)
06-30 16:43:38.961: E/AndroidRuntime(10946): at com.commonsware.cwac.camera.CameraView.initPreview(CameraView.java:279)
06-30 16:43:38.961: E/AndroidRuntime(10946): at com.commonsware.cwac.camera.TexturePreviewStrategy.onSurfaceTextureAvailable(TexturePreviewStrategy.java:45)
06-30 16:43:38.961: E/AndroidRuntime(10946): at android.view.TextureView.getHardwareLayer(TextureView.java:368)
...
尽管我在使用新的预览尺寸(适用于FFC)调用stopPreview()
之前在我的后置摄像头预览上调用了setParameters()
。相同的代码适用于其他设备(例如,Galaxy Nexus,Nexus 4)。
除了选择两个相机可用的预览尺寸外,有没有人知道如何解决这个问题?该解决方案可行,但我无法确保 两个摄像机之间的共同预览大小,加上它会人为地限制预览大小。
谢谢!
更新
这是来自LogCat的较长转储,显示我停止预览,然后稍后启动并崩溃。这个显示在via postDelayed()
中添加的人为的一秒延迟;那没有解决问题:
06-30 17:20:14.375: D/CameraView(12663): stopping preview
06-30 17:20:14.414: I/CameraHardwareSec(90): int android::CameraHardwareSec::previewThreadWrapper(): calling mSecCamera->stopPreview() and waiting
06-30 17:20:14.492: I/CameraHardwareSec(90): void android::CameraHardwareSec::stopPreviewInternal() : preview not running, doing nothing
06-30 17:20:14.492: I/CameraHardwareSec(90): int android::CameraHardwareSec::previewThreadWrapper(): return from wait
06-30 17:20:14.492: I/CameraHardwareSec(90): int android::CameraHardwareSec::previewThreadWrapper(): exiting
06-30 17:20:14.500: W/SecCamera(90): int android::SecCamera::stopPreview(): doing nothing because m_flag_camera_start is zero
06-30 17:20:14.507: W/SecCamera(90): int android::SecCamera::stopRecord(): doing nothing because m_flag_record_start is zero
06-30 17:20:14.507: I/SecCamera(90): DeinitCamera: m_cam_fd(39)
06-30 17:20:14.523: I/SecCamera(90): DeinitCamera: m_cam_fd2(40)
06-30 17:20:14.550: E/CameraHardwareSec(90): preview window is NULL!
06-30 17:20:14.550: I/CameraService(90): Destroying camera 0
06-30 17:20:14.550: I/CameraHardwareSec(90): int android::HAL_camera_device_close(hw_device_t*)
06-30 17:20:14.550: I/SecCamera(90): DeinitCamera : already deinitialized
06-30 17:20:14.554: W/AudioFlinger(90): session id 206 not found for pid 90
06-30 17:20:14.558: W/AudioFlinger(90): session id 207 not found for pid 90
06-30 17:20:15.480: E/DemoCameraHost(12663): facing: 0, useFFC: true
06-30 17:20:15.480: E/DemoCameraHost(12663): facing: 1, useFFC: true
06-30 17:20:15.480: I/CameraService(90): Opening camera 1
06-30 17:20:15.480: I/CameraHardwareSec(90): int android::HAL_camera_device_open(const hw_module_t*, char const*, hw_device_t**): open camera 1
06-30 17:20:15.484: E/SecCamera(90): initCamera: m_cam_fd(39), m_jpeg_fd(0)
06-30 17:20:15.484: I/SecCamera(90): Name of input channel[1] is S5KA3DFX
06-30 17:20:15.496: E/SecCamera(90): initCamera: m_cam_fd2(40)
06-30 17:20:15.496: I/SecCamera(90): Name of input channel[1] is S5KA3DFX
06-30 17:20:15.496: I/SecCamera(90): initCamera : initialized
06-30 17:20:15.496: I/SecCamera(90): Name of input channel[1] is S5KA3DFX
06-30 17:20:15.496: I/CameraHardwareSec(90): int android::HAL_camera_device_open(const hw_module_t*, char const*, hw_device_t**): opened camera 1 (0x412688a8)
06-30 17:20:15.496: I/AwesomePlayer(90): setDataSource_l('/system/media/audio/ui/camera_click.ogg')
06-30 17:20:15.504: I/CameraHardwareSec(90): int android::CameraHardwareSec::previewThreadWrapper(): starting
06-30 17:20:15.504: I/CameraHardwareSec(90): int android::CameraHardwareSec::previewThreadWrapper(): calling mSecCamera->stopPreview() and waiting
06-30 17:20:15.507: W/SecCamera(90): int android::SecCamera::stopPreview(): doing nothing because m_flag_camera_start is zero
06-30 17:20:15.515: D/dalvikvm(12663): GC_CONCURRENT freed 159K, 4% free 8249K/8519K, paused 53ms+7ms, total 98ms
06-30 17:20:15.519: I/AwesomePlayer(90): setDataSource_l('/system/media/audio/ui/VideoRecord.ogg')
06-30 17:20:15.535: I/CameraHardwareSec(90): void android::CameraHardwareSec::stopPreviewInternal() : preview not running, doing nothing
06-30 17:20:15.535: E/CameraHardwareSec(90): preview window is NULL!
06-30 17:20:15.539: I/CameraHardwareSec(90): virtual android::status_t android::CameraHardwareSec::startPreview() : deferring
06-30 17:20:15.640: D/CameraHardwareSec(90): mPreviewHeap(fd(39), size(460800), width(640), height(480))
06-30 17:20:15.640: I/CameraHardwareSec(90): int android::CameraHardwareSec::previewThreadWrapper(): return from wait
06-30 17:20:15.640: D/CameraView(12663): initPreview() called, setting up 320 x 240
06-30 17:20:15.644: E/CameraHardwareSec(90): ERR(virtual android::status_t android::CameraHardwareSec::setParameters(const android::CameraParameters&)): preview is running, cannot change size and format!
06-30 17:20:15.648: D/AndroidRuntime(12663): Shutting down VM
06-30 17:20:15.648: W/dalvikvm(12663): threadid=1: thread exiting with uncaught exception (group=0x40c33300)
06-30 17:20:15.679: E/AndroidRuntime(12663): FATAL EXCEPTION: main
06-30 17:20:15.679: E/AndroidRuntime(12663): java.lang.RuntimeException: setParameters failed
06-30 17:20:15.679: E/AndroidRuntime(12663): at android.hardware.Camera.native_setParameters(Native Method)
06-30 17:20:15.679: E/AndroidRuntime(12663): at android.hardware.Camera.setParameters(Camera.java:1410)
06-30 17:20:15.679: E/AndroidRuntime(12663): at com.commonsware.cwac.camera.CameraView.initPreview(CameraView.java:280)
06-30 17:20:15.679: E/AndroidRuntime(12663): at com.commonsware.cwac.camera.TexturePreviewStrategy.onSurfaceTextureAvailable(TexturePreviewStrategy.java:45)
06-30 17:20:15.679: E/AndroidRuntime(12663): at android.view.TextureView.getHardwareLayer(TextureView.java:368)
...
答案 0 :(得分:4)
我发现了我的问题。在我想到之前我正在打开预览模式,这在以后设置预览尺寸时会引起问题。
这个故事的道德:如果有疑问,请在Camera
的每一次使用中设置断点,并确保事件的顺序与您的想法一致。