- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在创建一个支持已弃用和新相机 API 的应用程序。第一个就像一个魅力,但我正在努力使用 Camera2 API。在测试阶段,我注意到了奇怪的行为。测试设备是 Samsung Galaxy S5 with android 6.0.1当我按下 Power/End 键然后返回应用程序时,这就是我得到的结果(并非每次都发生):
03-12 16:14:32.704 24117-24117/pl.tripper.tripper E/MainActivity: onPause
03-12 16:14:32.774 24117-24128/pl.tripper.tripper E/BufferQueueProducer: [SurfaceTexture-1-24117-2] dequeueBuffer: BufferQueue has been abandoned
03-12 16:14:32.784 24117-24145/pl.tripper.tripper E/BufferQueueProducer: [SurfaceTexture-1-24117-2] queueBuffer: BufferQueue has been abandoned
03-12 16:14:33.044 24117-24128/pl.tripper.tripper E/BufferQueueProducer: [SurfaceTexture-1-24117-2] cancelBuffer: BufferQueue has been abandoned
03-12 16:14:33.044 24117-24145/pl.tripper.tripper E/BufferQueueProducer: [SurfaceTexture-1-24117-2] cancelBuffer: BufferQueue has been abandoned
03-12 16:14:33.054 24117-24129/pl.tripper.tripper E/BufferQueueProducer: [SurfaceTexture-1-24117-2] cancelBuffer: BufferQueue has been abandoned
03-12 16:14:33.054 24117-24128/pl.tripper.tripper E/BufferQueueProducer: [SurfaceTexture-1-24117-2] cancelBuffer: BufferQueue has been abandoned
03-12 16:14:33.264 24117-24117/pl.tripper.tripper E/CameraNewApi: cameraComponentsReleased
03-12 16:14:33.264 24117-24117/pl.tripper.tripper E/CameraNewApi: StopCameraThread
03-12 16:14:33.264 24117-24117/pl.tripper.tripper E/CameraApiManager: cameraPreviewRemoved
03-12 16:14:33.264 24117-24117/pl.tripper.tripper E/CameraNewApi: onSurfaceDestroyed
03-12 16:14:33.634 24117-24117/pl.tripper.tripper E/MainActivity: onCreate
03-12 16:14:33.634 24117-24117/pl.tripper.tripper E/MainActivity: onResume
03-12 16:14:33.634 24117-24117/pl.tripper.tripper E/CameraNewApi: startCameraThread
03-12 16:14:33.634 24117-24117/pl.tripper.tripper E/CameraApiManager: cameraPreviewCreated
03-12 16:14:33.644 24117-24117/pl.tripper.tripper E/CameraNewApi: initCamera
03-12 16:14:33.674 24117-24117/pl.tripper.tripper E/CameraNewApi: onSurfaceCreated
03-12 16:14:33.674 24117-24117/pl.tripper.tripper E/CameraNewApi: openCamera
03-12 16:14:33.914 24117-24117/pl.tripper.tripper E/CameraNewApi: onSurfaceChanged
03-12 16:14:33.914 24117-25053/pl.tripper.tripper E/CameraNewApi: onOpened
03-12 16:14:33.914 24117-25053/pl.tripper.tripper E/CameraNewApi: createCameraPreview
03-12 16:14:33.934 24117-24117/pl.tripper.tripper E/MainActivity: onPause
03-12 16:14:34.174 24117-24117/pl.tripper.tripper E/CameraNewApi: cameraComponentsReleased
03-12 16:14:34.174 24117-25053/pl.tripper.tripper E/CameraNewApi: onConfigured
03-12 16:14:34.174 24117-24117/pl.tripper.tripper E/CameraNewApi: StopCameraThread
03-12 16:14:34.174 24117-24117/pl.tripper.tripper E/CameraApiManager: cameraPreviewRemoved
03-12 16:14:34.184 24117-24117/pl.tripper.tripper E/CameraNewApi: onSurfaceDestroyed
03-12 16:14:34.914 24117-24117/pl.tripper.tripper E/MainActivity: onResume
03-12 16:14:34.914 24117-24117/pl.tripper.tripper E/CameraNewApi: startCameraThread
03-12 16:14:34.924 24117-24117/pl.tripper.tripper E/CameraApiManager: cameraPreviewCreated
03-12 16:14:34.924 24117-24117/pl.tripper.tripper E/CameraNewApi: initCamera
03-12 16:14:34.964 24117-24117/pl.tripper.tripper E/CameraNewApi: onSurfaceCreated
03-12 16:14:34.964 24117-24117/pl.tripper.tripper E/CameraNewApi: openCamera
03-12 16:14:35.294 24117-24117/pl.tripper.tripper E/CameraNewApi: onSurfaceChanged
03-12 16:14:35.294 24117-25121/pl.tripper.tripper E/CameraNewApi: onOpened
03-12 16:14:35.294 24117-25121/pl.tripper.tripper E/CameraNewApi: createCameraPreview
03-12 16:14:35.354 24117-24117/pl.tripper.tripper E/CameraNewApi: onSurfaceChanged
03-12 16:14:35.374 24117-24117/pl.tripper.tripper E/MainActivity: onPause
03-12 16:14:35.384 24117-25121/pl.tripper.tripper E/CameraNewApi: onConfigured
03-12 16:14:35.594 24117-24117/pl.tripper.tripper E/CameraNewApi: cameraComponentsReleased
03-12 16:14:35.594 24117-25121/pl.tripper.tripper E/CameraNewApi: Session was closed or camera device has been closed.
java.lang.IllegalStateException: CameraDevice was already closed
at android.hardware.camera2.impl.CameraDeviceImpl.checkIfCameraClosedOrInError(CameraDeviceImpl.java:1997)
at android.hardware.camera2.impl.CameraDeviceImpl.submitCaptureRequest(CameraDeviceImpl.java:844)
at android.hardware.camera2.impl.CameraDeviceImpl.setRepeatingRequest(CameraDeviceImpl.java:899)
at android.hardware.camera2.impl.CameraCaptureSessionImpl.setRepeatingRequest(CameraCaptureSessionImpl.java:236)
at pl.tripper.tripper.camera.CameraNewApi$2.onConfigured(CameraNewApi.java:107)
at java.lang.reflect.Method.invoke(Native Method)
at android.hardware.camera2.dispatch.InvokeDispatcher.dispatch(InvokeDispatcher.java:39)
at android.hardware.camera2.dispatch.HandlerDispatcher$1.run(HandlerDispatcher.java:65)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.os.HandlerThread.run(HandlerThread.java:61)
03-12 16:14:35.594 24117-24117/pl.tripper.tripper E/CameraNewApi: StopCameraThread
03-12 16:14:35.594 24117-25121/pl.tripper.tripper E/CameraNewApi: cameraComponentsReleased
03-12 16:14:35.594 24117-24117/pl.tripper.tripper E/CameraApiManager: cameraPreviewRemoved
03-12 16:14:35.604 24117-24117/pl.tripper.tripper E/CameraNewApi: onSurfaceDestroyed
03-12 16:14:35.644 24117-24117/pl.tripper.tripper E/MainActivity: onCreate
03-12 16:14:35.654 24117-24117/pl.tripper.tripper E/MainActivity: onResume
03-12 16:14:35.654 24117-24117/pl.tripper.tripper E/CameraNewApi: startCameraThread
03-12 16:14:35.654 24117-24117/pl.tripper.tripper E/CameraApiManager: cameraPreviewCreated
03-12 16:14:35.654 24117-24117/pl.tripper.tripper E/CameraNewApi: initCamera
03-12 16:14:35.694 24117-24117/pl.tripper.tripper E/CameraNewApi: onSurfaceCreated
03-12 16:14:35.694 24117-24117/pl.tripper.tripper E/CameraNewApi: openCamera
03-12 16:14:35.934 24117-24117/pl.tripper.tripper E/CameraNewApi: onSurfaceChanged
03-12 16:14:35.934 24117-25184/pl.tripper.tripper E/CameraNewApi: onOpened
03-12 16:14:35.934 24117-25184/pl.tripper.tripper E/CameraNewApi: createCameraPreview
03-12 16:14:35.944 24117-24117/pl.tripper.tripper E/ViewRootImpl: sendUserActionEvent() mView == null
03-12 16:14:35.944 24117-24117/pl.tripper.tripper E/ViewRootImpl: sendUserActionEvent() mView == null
03-12 16:14:35.994 24117-25184/pl.tripper.tripper E/CameraNewApi: onConfigured
添加了调用方法时的一些错误日志。我知道当 session 仍在进行时 cameraDevice 为空,但我不知道如何修复它。 java.lang.IllegalStateException
错误发生后,相机继续工作。第二个问题是 BufferQueueProducer
错误,但我不知道这是从哪里来的。
03-12 15:47:40.244 30720-30731/pl.tripper.tripper E/BufferQueueProducer: [SurfaceTexture-1-30720-1] dequeueBuffer: BufferQueue has been abandoned
03-12 15:47:40.244 30720-30751/pl.tripper.tripper E/BufferQueueProducer: [SurfaceTexture-1-30720-1] queueBuffer: BufferQueue has been abandoned
03-12 15:47:40.524 30720-30731/pl.tripper.tripper E/BufferQueueProducer: [SurfaceTexture-1-30720-1] cancelBuffer: BufferQueue has been abandoned
03-12 15:47:40.524 30720-30751/pl.tripper.tripper E/BufferQueueProducer: [SurfaceTexture-1-30720-1] cancelBuffer: BufferQueue has been abandoned
03-12 15:47:40.524 30720-30732/pl.tripper.tripper E/BufferQueueProducer: [SurfaceTexture-1-30720-1] cancelBuffer: BufferQueue has been abandoned
03-12 15:47:40.524 30720-30731/pl.tripper.tripper E/BufferQueueProducer: [SurfaceTexture-1-30720-1] cancelBuffer: BufferQueue has been abandoned
这是我的代码:
MainActivity.class
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
Log.e(TAG, "onCreate");
isImmersiveAvailable();
cameraApiManager = new CameraApiManager(this, this);
}
@Override
protected void onResume() {
super.onResume();
Log.e(TAG, "onResume");
cameraApiManager.createCamera();
}
@Override
protected void onPause() {
super.onPause();
Log.e(TAG, "onPause");
cameraApiManager.releaseCameraAndPreview();
}
CameraApiManager.class
public class CameraApiManager implements CameraUtility.cameraOpenedListener {
private static final String TAG = "CameraApiManager";
private final WeakReference<MainActivity> mainActivity;
private Context context;
private CameraSourceApi cameraSourceApi;
private CameraPreview cameraPreview;
public CameraApiManager(Context context, MainActivity mainActivity){
this.mainActivity= new WeakReference<>(mainActivity);
cameraSourceApi = new CameraSourceApi<>(new CameraNewApi(context));
this.context = context;
}
private boolean cameraProgressBarEnable(){
return context.getResources().getBoolean(R.bool.camera_progress_bar_enable);
}
private void setCameraProgressBarVisibility(final int visibility ){
final MainActivity mainActivity = this.mainActivity.get();
if(mainActivity!= null){
// UI/Main Thread
if(Looper.myLooper() == Looper.getMainLooper()){
ProgressBar cameraProgressBar = (ProgressBar) mainActivity.findViewById(R.id.camera_progress_bar);
cameraProgressBar.setVisibility(visibility);
} else {
mainActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
ProgressBar cameraProgressBar = (ProgressBar) mainActivity.findViewById(R.id.camera_progress_bar);
cameraProgressBar.setVisibility(visibility);
}
});
}
}
}
private void showCameraOpenErrorToast(){
Toast.makeText(context, context.getResources().getString(R.string.camera_open_error_toast), Toast.LENGTH_LONG).show();
}
private boolean cameraPermissionGranted() {
return ContextCompat.checkSelfPermission(context, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED;
}
public void createCamera(){
if(cameraPermissionGranted()){
if(cameraProgressBarEnable()){
setCameraProgressBarVisibility(View.VISIBLE);
}
cameraSourceApi.createCamera(this);
}
}
public void releaseCameraAndPreview(){
if(cameraPermissionGranted()){
cameraSourceApi.releaseCamera();
removeCameraPreview();
}
}
@Override
public void onCameraOpened(boolean succeeded, boolean addPreview, boolean progressBar) {
if(addPreview) {
if (cameraPreview == null) {
Log.e(TAG, "cameraPreviewCreated");
cameraPreview = new CameraPreview(context, cameraSourceApi);
addCameraPreview();
}
}
if(!progressBar){
if(cameraProgressBarEnable()){
setCameraProgressBarVisibility(View.GONE);
}
}
if(!succeeded){
showCameraOpenErrorToast();
}
}
private void addCameraPreview(){
MainActivity mainActivity = this.mainActivity.get();
if(mainActivity != null && cameraPreview != null){
FrameLayout preview = (FrameLayout) mainActivity.findViewById(R.id.camera_preview);
preview.addView(cameraPreview);
}
}
private void removeCameraPreview(){
MainActivity mainActivity = this.mainActivity.get();
if(mainActivity!= null && cameraPreview != null){
Log.e(TAG, "cameraPreviewRemoved");
FrameLayout preview = (FrameLayout) mainActivity.findViewById(R.id.camera_preview);
preview.removeView(cameraPreview);
cameraPreview = null;
}
}
class CameraSourceApi<T extends CameraUtility> implements CameraUtility{
private T camera;
CameraSourceApi(T camera){
this.camera = camera;
}
@Override
public void createCamera(CameraUtility.cameraOpenedListener cameraOpenedListener) {
camera.createCamera(cameraOpenedListener);
}
@Override
public void releaseCamera() {
camera.releaseCamera();
}
@Override
public void onSurfaceCreated(SurfaceHolder surfaceHolder) {
camera.onSurfaceCreated(surfaceHolder);
}
@Override
public void onSurfaceChanged(SurfaceHolder surfaceHolder, int width, int height) {
camera.onSurfaceChanged(surfaceHolder, width, height);
}
@Override
public void onSurfaceDestroyed(SurfaceHolder surfaceHolder) {
camera.onSurfaceDestroyed(surfaceHolder);
}
}
}
CameraNewApi.class
@TargetApi(21)
class CameraNewApi implements CameraUtility {
private static final String TAG = "CameraNewApi";
private Semaphore cameraOpenCloseLock = new Semaphore(1);
private CameraUtility.cameraOpenedListener cameraOpenedListener;
private Context context;
private Handler backgroundHandler;
private HandlerThread backgroundThread;
private SurfaceHolder surfaceHolder;
private String backFacingCameraId;
private CaptureRequest.Builder captureRequestBuilder;
private CameraDevice cameraDevice;
private CameraCaptureSession cameraCaptureSessions;
CameraNewApi(Context context){
this.context = context;
}
private final CameraDevice.StateCallback cameraDeviceStateCallback = new CameraDevice.StateCallback() {
@Override
public void onOpened(@NonNull CameraDevice camera) {
Log.e(TAG, "onOpened");
cameraOpenCloseLock.release();
cameraDevice = camera;
if(surfaceHolder != null){
createCameraPreview();
} else {
releaseCameraComponents();
}
}
@Override
public void onDisconnected(@NonNull CameraDevice camera) {
Log.d(TAG, "deviceCallback.onDisconnected() start");
Log.e(TAG, "onDisconnected");
if(cameraOpenedListener != null) {
cameraOpenedListener.onCameraOpened(false, false, false);
}
cameraOpenCloseLock.release();
camera.close();
cameraDevice = null;
}
@Override
public void onError(@NonNull CameraDevice camera, int error) {
Log.e(TAG, "onError");
Log.d(TAG, "deviceCallback.onError() start");
if(cameraOpenedListener != null) {
cameraOpenedListener.onCameraOpened(false, false, false);
}
cameraOpenCloseLock.release();
camera.close();
cameraDevice = null;
}
};
private final CameraCaptureSession.StateCallback captureSessionStateCallback = new CameraCaptureSession.StateCallback() {
@Override
public void onConfigured(@NonNull CameraCaptureSession session) {
Log.e(TAG, "onConfigured");
if(cameraDevice != null){
cameraCaptureSessions = session;
captureRequestBuilder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO);
try {
if(cameraOpenedListener != null) {
cameraOpenedListener.onCameraOpened(true, false, false);
}
session.setRepeatingRequest(captureRequestBuilder.build(), null, backgroundHandler);
} catch (CameraAccessException e) {
Log.e(TAG, "Camera has been disconnected", e);
} catch (IllegalStateException e){
Log.e(TAG, "Session was closed or camera device has been closed. ", e);
releaseCameraComponents();
}
}
}
@Override
public void onConfigureFailed(@NonNull CameraCaptureSession session) {
Log.d(TAG, "Capture session configure failed: " + session);
Log.e(TAG, "onConfigureFailed");
}
};
@Override
public void createCamera(CameraUtility.cameraOpenedListener cameraOpenedListener) {
this.cameraOpenedListener = cameraOpenedListener;
startBackgroundThread();
if(cameraOpenedListener != null){
cameraOpenedListener.onCameraOpened(true, true, true);
}
initCamera();
}
private void releaseCameraComponents(){
try{
cameraOpenCloseLock.acquire();
if(cameraCaptureSessions != null){
cameraCaptureSessions.close();
cameraCaptureSessions = null;
}
if(cameraDevice != null){
cameraDevice.close();
cameraDevice = null;
}
if(surfaceHolder != null){
surfaceHolder = null;
}
if(cameraOpenedListener != null){
cameraOpenedListener = null;
}
Log.e(TAG, "cameraComponentsReleased");
} catch (InterruptedException e) {
throw new RuntimeException("Interrupted while trying to lock camera closing.", e);
} finally {
cameraOpenCloseLock.release();
}
}
@Override
public void releaseCamera() {
releaseCameraComponents();
stopBackgroundThread();
}
@Override
public void onSurfaceCreated(SurfaceHolder surfaceHolder) {
Log.e(TAG, "onSurfaceCreated");
this.surfaceHolder = surfaceHolder;
openCamera();
}
@Override
public void onSurfaceChanged(SurfaceHolder surfaceHolder, int width, int height) {
Log.e(TAG, "onSurfaceChanged");
setSurfaceSize(width, height);
}
@Override
public void onSurfaceDestroyed(SurfaceHolder surfaceHolder) {
Log.e(TAG, "onSurfaceDestroyed");
}
private void startBackgroundThread() {
Log.e(TAG, "startCameraThread");
backgroundThread = new HandlerThread("CameraBackground");
backgroundThread.start();
backgroundHandler = new Handler(backgroundThread.getLooper());
}
private void stopBackgroundThread() {
Log.e(TAG, "StopCameraThread");
backgroundThread.quitSafely();
try {
backgroundThread.join();
backgroundThread = null;
backgroundHandler = null;
} catch (InterruptedException e) {
Log.e(TAG, "Error message: ", e);
}
}
private void initCamera(){
Log.e(TAG, "initCamera");
CameraManager cameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
try{
for (String cameraId : cameraManager.getCameraIdList()) {
CameraCharacteristics characteristics
= cameraManager.getCameraCharacteristics(cameraId);
// Use back camera
Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);
if (facing != null && facing == CameraCharacteristics.LENS_FACING_BACK) {
backFacingCameraId = cameraId;
break;
}
}
if(backFacingCameraId == null){
Log.d(TAG, "Could not detect a camera");
}
} catch (CameraAccessException e) {
Log.e(TAG, "Could not get camera list", e);
}
}
private void openCamera(){
Log.e(TAG, "openCamera");
CameraManager cameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
try{
if(backFacingCameraId != null && cameraDevice == null){
try{
if (!cameraOpenCloseLock.tryAcquire(2500, TimeUnit.MILLISECONDS)) {
throw new RuntimeException("Time out waiting to lock camera opening.");
}
cameraManager.openCamera(backFacingCameraId, cameraDeviceStateCallback, backgroundHandler);
} catch (InterruptedException e) {
throw new RuntimeException("Interrupted while trying to lock camera opening.", e);
}
}
} catch(SecurityException e){
Log.e(TAG, "Camera permission is not granted", e);
} catch(CameraAccessException e){
Log.e(TAG, "Could not open camera", e);
}
}
private void createCameraPreview(){
Log.e(TAG, "createCameraPreview");
Surface surface = surfaceHolder.getSurface();
List<Surface> surfaceList = Collections.singletonList(surface);
try {
captureRequestBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
captureRequestBuilder.addTarget(surface);
cameraDevice.createCaptureSession(surfaceList, captureSessionStateCallback, null);
} catch (CameraAccessException e){
Log.e(TAG, "Could not create capture session for camera: " + cameraDevice.getId(), e);
} catch (IllegalStateException e){
Log.e(TAG, "Camera has been closed", e);
}
}
CameraUtility.interface
interface CameraUtility {
void createCamera(CameraUtility.cameraOpenedListener cameraOpenedListener);
void releaseCamera();
void onSurfaceCreated(SurfaceHolder surfaceHolder);
void onSurfaceChanged(SurfaceHolder surfaceHolder, int width, int height);
void onSurfaceDestroyed(SurfaceHolder surfaceHolder);
interface cameraOpenedListener{
void onCameraOpened(boolean succeeded, boolean addPreview, boolean progressBar);
}
}
更新
这就是为什么它不会每次都发生的原因。调用 onPause 后立即发生错误, session 开始重复请求以保持预览(onConfigured)。然后 cameraComponentsReleased 触发所有清理完成的地方,包括当前的 CameraDevice 对象。仍然不知道如何处理这种情况。
03-13 12:12:24.375 17555-17555/pl.tripper.tripper E/MainActivity: onPause
03-13 12:12:24.395 17555-20454/pl.tripper.tripper E/CameraNewApi: onConfigured
03-13 12:12:24.625 17555-17555/pl.tripper.tripper E/CameraNewApi: cameraComponentsReleased
03-13 12:12:24.625 17555-17555/pl.tripper.tripper E/CameraNewApi: StopCameraThread
03-13 12:12:24.625 17555-20454/pl.tripper.tripper E/CameraNewApi: Session was closed or camera device has been closed.
java.lang.IllegalStateException: CameraDevice was already closed
at android.hardware.camera2.impl.CameraDeviceImpl.checkIfCameraClosedOrInError(CameraDeviceImpl.java:1997)
at android.hardware.camera2.impl.CameraDeviceImpl.submitCaptureRequest(CameraDeviceImpl.java:844)
at android.hardware.camera2.impl.CameraDeviceImpl.setRepeatingRequest(CameraDeviceImpl.java:899)
at android.hardware.camera2.impl.CameraCaptureSessionImpl.setRepeatingRequest(CameraCaptureSessionImpl.java:236)
at pl.tripper.tripper.camera.CameraNewApi$2.onConfigured(CameraNewApi.java:114)
at java.lang.reflect.Method.invoke(Native Method)
at android.hardware.camera2.dispatch.InvokeDispatcher.dispatch(InvokeDispatcher.java:39)
at android.hardware.camera2.dispatch.HandlerDispatcher$1.run(HandlerDispatcher.java:65)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.os.HandlerThread.run(HandlerThread.java:61)
03-13 12:12:24.625 17555-20454/pl.tripper.tripper E/CameraNewApi: Camera onClosed
03-13 12:12:24.625 17555-17555/pl.tripper.tripper E/CameraApiManager: cameraPreviewRemoved
最佳答案
java.lang.IllegalStateException: CameraDevice was already closed
这意味着 CameraDevice 在某些情况下被某人关闭了。 (例如:内存不足)要处理此问题,您可以在 StateCallback - cameraDeviceStateCallback 中添加 onClosed() 回调。
android.hardware.camera2.CameraDevice.StateCallback.onClosed(CameraDevice)
更新:
这看起来像是一个竞争条件。在日志中,17555-17555 releaseCameraComponents
和 17555-20454 onConfigured
回调在不同的线程上被调用。 IMO,cameraCaptureSessions 应该在 releaseCameraComponents
和 onConfigured
中同步。
private void releaseCameraComponents(){
synchronized(lock) {
....
}
}
....
@Override
public void onConfigured(@NonNull CameraCaptureSession session) {
synchronized(lock) {
....
}
}
关于android - Camera2 API 和 java.lang.IllegalStateException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42749056/
我在 Android 中使用相机时遇到问题。 在 API 25 Nougat 7.1.1 SDK 上进行开发。最小目标 SDK 设置为 15。 每次调用时都会抛出错误: Camera camera =
在我尝试过的所有手机上,包括带有 API 2.3.7 和 4.0 的 Galaxy Nexus,在调用 takePicture 方法后表面 View 更改为拍摄的图像,即“图像查看”。 我已经在这些平
我正在尝试在 Flutter 中的相机预览上显示 CustomPaint 元素。现在,CustomPaint 元素显示在相机预览下方。我正在使用 Flutter camera plugin显示相机预览
我有一个自定义相机应用程序,它在 SurfaceView 上预览相机视频输出并尝试拍照,照片应该由“xzing”扫描仪 API 处理以解码图像中的任何条形码。 我的应用程序预览正确并且没有抛出任何错误
我已经实现了使用 Android MediaRecorder 在后台录制音频,如果录音正在进行并且用户打开了 native 摄像头来录制视频,它会提供 Camera Error "Can't Conn
我在浏览相机脚本时遇到了声明术语 new Camera camera; 我想知道这是做什么的。它是在创建一个实例吗?让我感到困惑的是脚本已经附加到 Inspector 中的相机对象。那么为什么需要创建
我使用了我的 Fabric 服务,并在大多数运行我的应用程序的设备上发现了这个错误。 错误是这样的: Fatal Exception: java.lang.NullPointerException A
private static final int SENSOR_ORIENTATION_DEFAULT_DEGREES = 90; private static final int SENSOR_OR
我正在开发一个基本的自定义相机应用这些是我的依赖 // CameraX core library dependency implementation "androidx.camera:camera-c
我正在为索尼相机制作一个跟焦应用程序。我的应用程序需要能够设置焦点标记并调用它们。有很多功能可以在 Sony Camera API 上进行自动对焦,但我希望能够手动将焦点设置为给定的绝对值。有没有办法
我已经浏览了 Nest 开发人员网站,但找不到与相机相关的任何内容。我可以找到很多关于恒温器和烟雾/一氧化碳警报器的重要信息,但没有关于相机的信息。 特别是,我正在寻找如何获取视频 URL、如何获取/
关闭。这个问题需要details or clarity .它目前不接受答案。 想改进这个问题吗? 通过 editing this post 添加细节并澄清问题. 关闭 8 年前。 Improve t
我使用 create-react-native-app (CRNA) 创建了一个 RN 项目。我想使用expo提供的Camera API。为此,我只是复制了此处的示例 https://docs.exp
我想让我的相机跟随移动实体的第一人称视角。我不相信 trackedEntity 将适用于此用例,因为我不想查看实体,但我想查看 从它。我还希望用户能够使用鼠标相对于移动实体转动相机(例如,从移动平面的
我有一个跟进问题 Android Camera Server Died and Camera ERROR 100 我的代码中出现了类似的错误。这个错误出现在我们随机运行许多应用程序的自动化测试中。很长
我正在尝试实现与 Facebook 或 Instagram 相同的功能: 即时预览相机拍摄的图像 此时,调用此函数时,我的拍摄已正确拍摄: takePicture = async function()
我想给 React native Camera 添加水印。每当我点击/拍摄图像时,应该保存带有水印的图像。 最佳答案 我用了react-native-image-marker它对我有用。 关于reac
虽然索尼向客户挑逗新相机型号(UMC-R10C、UMC-S3C)并提到 API 访问和 USB 连接(而不是 wifi),但索尼相机远程 API 目前只提到 wifi。有没有关于如何使用这些即将推出的
我正在尝试使用以下代码在我的 xamarin android 应用程序中使用相机功能。 Intent intent = new Intent(MediaStore.ActionImageCapture
我构建了一个人脸检测应用程序,我从 onPreviewFrame 获取帧,进行人脸检测,然后在 surfaceView 上方的 Canvas 上绘制一个圆圈。问题是当 Camera.StartPrev
我是一名优秀的程序员,十分优秀!