OpenHarmony 分布式相机代码片段

相机控制访问的流程

迁移时间 2022-11-26 22:20:14

引用相机服务api接口

1
import camera from '@ohos.multimedia.camera'

获取服务实例

1
let cameraManager = await camera.getCameraManager(null)

获取(有效的)设备信息

1
let cameras = await cameraManager.getCameras()

初始化 session 配置 session 输出

1
let captureSession = await camera.createCaptureSession(null)

选取摄像头(本地/远程)的 cameraId

1
2
3
let cameraId = cameras[0].cameraId
let cameraInput = await cameraManager.createCameraInput(cameraId)
await captureSession.addInput(cameraUnput)
启动相机
1
await captureSeesion.start()

分布式相机获取/判断API

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
interface CameraManager
{
// 略
getCameras():Promise<Array<Camera>>;
// 略
}

interface Camera
{
//省略
readonly cameraId:string;
readonly connectionType:ConnectionType;
//省略
}

enum ConnectionType
{
// 略
CAMERA_CONNECTION_REMOTE
}