常见黑屏问题场景 | 常见报错日志 | 根因 | 排查步骤 |
未取得相机权限 | Permission denied. | 获取相机设备前未获取相机权限。 | 1、检查应用是否已声明相机权限;2、检查应用是否未向用户申请权限;3、检查用户是否拒绝授权。 |
无法获取相机设备 | Can not use camera cause of preempted. | 相机对象被其他应用占用。 | 排查日志。 |
使用了不可用的摄像头 | 无 | 折叠屏切换折叠状态后未更换当前使用的摄像头。 | 排查应用监听折叠状态切换时是否重新获取并切换到当前可用的摄像头。 |
createPreviewOutput参数配置异常 | failed to get surface. | 在XComponent创建前就创建预览流,未获取到surfaceId。 | 检查onPageShow中是否在初次进入页面就初始化相机。 |
方法调用存在时序问题 | Operation not allowed. | 添加或移除相机的输入流和输出流操作未在beginConfig和commitConfig之间。 | 检查beginConfig、commitConfig和添加输入输出流的执行顺序。 |
未beginConfig就开始进行commitConfig操作。 | |||
Session not config. | 会话配置前,调用start操作。 | 检查beginConfig、commitConfig和start的执行顺序。 | |
添加了不可用的输入流/输出流 | canAddInput/CanAddOutput check failed. | 添加相机的输入流/输出流时,添加了不可用的输入流/输出流。 | 排查日志。 |
返回页面后未重新初始化相机。 | 无 | onPageShow中未设置初始化相机。 | 查看页面在onPageShow中是否设置初始化相机。 |
I [CreateBusinessError:30] CreateBusinessError errCode: 201 errMsg: Permission denied.
说明:需要考虑用户拒绝授权后不会出现上方的日志,此时需要继续筛查日志。
[IsDynamicRequest:444]Permission: ohos.permission.CAMERA: state: 2, errorReason: 2
说明:errorReason: 2表示应用未声明该权限。详情参照PermissionRequestResult属性中errorReasons属性部分。
[SPC][PermissionDialog][Model]: terminate session with result, resultCode: 1, reqPerms: [ohos.permission.CAMERA], result: [-1].
[IsDynamicRequest:444]Permission: ohos.permission.CAMERA: state: -1, errorReason: 0 [RequestPermissionsFromUserExecute:704]It does not need to request permission
xxx, Camera input error code: 7400109 Can not use camera cause of preempted
{CreatePreviewOutputInstance():869} CameraManagerNapi::CreatePreviewOutputInstance ParseProfile size.width = xxx, size.height = xxx, format = 1003, surfaceId =
{CreatePreviewOutput():341} CreatePreviewOutput is called
<surface_utils.cpp:48-GetSurface>: Cannot find surface, uniqueId: 0.
{CreatePreviewOutput():357} failed to get surface 可能原因为初次进入页面时在onPageShow中初始化相机,而此时XComponent组件还未创建,无法获取到XComponent组件的surfaceId。
{AddInput():666} CaptureSession::AddInput operation Not allowed!
initCamera fail: {"code":"7400102"} {CommitConfig():424} CaptureSession::CommitConfig operation Not allowed!
initCamera fail: {"code":"7400102","message":"Operation not allowed."} {Start():1261} CaptureSession::Start Session not Commited
initCamera fail: {"code":"7400103","message":"Session not config."} CanAddxxx check failed.
initCamera fail: {"code":"7400201","message":"Camera service fatal error."} 示例代码可以参考预览(ArkTS)。