gpt4 book ai didi

android - Camera Error "Can' t Connect to the Camera”或者在某些手机中出现错误 "Camera is using by another app"

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:44:27 26 4
gpt4 key购买 nike

我已经实现了使用 Android MediaRecorder 在后台录制音频,如果录音正在进行并且用户打开了 native 摄像头来录制视频,它会提供

Camera Error "Can't Connect to the Camera"

或者在某些手机上,错误显示为

Your camera is in use by another application

enter image description here

如果我停止 mediarecorder 那么 native 摄像头视频录制工作正常,我搜索事件以了解相机何时开始视频,然后在我的应用程序中停止 mediarecorder,我发现 < strong>BroadcastReceiver 带过滤器

        <receiver android:name=".receiver.CameraReceiver">
<intent-filter android:priority="10000">
<action android:name="android.Medintent.action.CAMERA_BUTTON" />
<action android:name="android.hardware.action.NEW_PICTURE" />
<action android:name="android.hardware.action.NEW_VIDEO" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
<data android:mimeType="video/*" />
</intent-filter>
</receiver>

NEW_VIDEONEW_PICTURE 事件在捕获图片或视频并保存在目录中时触发。任何人都知道如何解决这个问题?我想在我的应用程序中知道 native /相机应用程序开始录制视频的事件。提前致谢

最佳答案

即使我也有同样的问题。一旦相机资源被应用程序使用,直到它被释放,您可以在其他应用程序甚至服务中使用它们。如果任何服务正在使用相机资源,直到它释放相同的资源,我们才能使用相机硬件。您可以使用此代码仔细检查是否正在使用相机硬件:-

 private boolean isCameraInUse() {
Log.v(TAG, "isCameraInUse()");
boolean isCameraInUse = false;
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)//Use Camera Api for Version Code < 23 and mCamera manager above it.
{
String cameraId = null;
CameraManager camManager = (CameraManager) mContext.getSystemService(Context.CAMERA_SERVICE);
// Usually front mCamera is at 0 position.
try {
cameraId = camManager.getCameraIdList()[0];
} catch (CameraAccessException e) {
Log.e(TAG, Log.getStackTraceString(e));
isCameraInUse = true;
}
try {
camManager.setTorchMode(cameraId, true);
camManager.setTorchMode(cameraId, false);
} catch (CameraAccessException e) {
Log.e(TAG, Log.getStackTraceString(e));
isCameraInUse = true;
}
} else {
Camera c = null;
try {
c = Camera.open();
} catch (RuntimeException e) {
Log.e(TAG, Log.getStackTraceString(e));
turnFlashOff(mContext);
isCameraInUse = true;
} finally {
if (c != null) c.release();
}
}
return isCameraInUse;
}

关于android - Camera Error "Can' t Connect to the Camera”或者在某些手机中出现错误 "Camera is using by another app",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45483442/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com