未验证 提交 e1c03183 编写于 作者: O openharmony_ci 提交者: Gitee

!15154 翻译完成:14024 Modification of distributed camera development document (cherry-pick到beta5)

Merge pull request !15154 from wusongqing/cherry-pick-1677224326
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
You can call the APIs provided by the **Camera** module to develop a distributed camera that provides the basic camera functions such as shooting and video recording. You can call the APIs provided by the **Camera** module to develop a distributed camera that provides the basic camera functions such as shooting and video recording.
## How to Develop ## How to Develop
Connect your calculator to a distributed device. Your calculator will call **getCameras()** to obtain the camera list and traverse the returned camera list to check **ConnectionType** of the **Camera** objects. If **ConnectionType** of a **Camera** object is **CAMERA_CONNECTION_REMOTE**, your calculator will use this object to create a **CameraInput** object. The subsequent call process is the same as that of the local camera development. For details about the local camera development, see [Camera Development](./camera.md). Connect your calculator to a distributed device. Your calculator will call **getSupportedCameras()** to obtain the camera list and traverse the returned camera list to check **ConnectionType** of the **Camera** objects. If **ConnectionType** of a **Camera** object is **CAMERA_CONNECTION_REMOTE**, your calculator will use this object to create a **cameraInput** object. The subsequent call process is the same as that of the local camera development. For details about the local camera development, see [Camera Development](./camera.md).
For details about the APIs, see [Camera Management](../reference/apis/js-apis-camera.md). For details about the APIs, see [Camera Management](../reference/apis/js-apis-camera.md).
...@@ -24,15 +24,11 @@ import media from '@ohos.multimedia.media' ...@@ -24,15 +24,11 @@ import media from '@ohos.multimedia.media'
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
// Create a CameraManager object. // Create a CameraManager object.
let cameraManager let cameraManager = camera.getCameraManager(globalThis.Context)
await camera.getCameraManager(globalThis.Context, (err, manager) => { if (!cameraManager) {
if (err) { console.error("camera.getCameraManager error")
console.error('Failed to get the CameraManager instance ${err.message}'); return;
return; }
}
console.log('Callback returned with the CameraManager instance');
cameraManager = manager
})
// Register a callback to listen for camera status changes and obtain the updated camera status information. // Register a callback to listen for camera status changes and obtain the updated camera status information.
cameraManager.on('cameraStatus', (cameraStatusInfo) => { cameraManager.on('cameraStatus', (cameraStatusInfo) => {
...@@ -41,16 +37,12 @@ cameraManager.on('cameraStatus', (cameraStatusInfo) => { ...@@ -41,16 +37,12 @@ cameraManager.on('cameraStatus', (cameraStatusInfo) => {
}) })
// Obtain the camera list. // Obtain the camera list.
let cameraArray
let remoteCamera let remoteCamera
await cameraManager.getCameras((err, cameras) => { let cameraArray = cameraManager.getSupportedCameras();
if (err) { if (cameraArray.length <= 0) {
console.error('Failed to get the cameras. ${err.message}'); console.error("cameraManager.getSupportedCameras error")
return; return;
} }
console.log('Callback returned with an array of supported cameras: ' + cameras.length);
cameraArray = cameras
})
for(let cameraIndex = 0; cameraIndex < cameraArray.length; cameraIndex++) { for(let cameraIndex = 0; cameraIndex < cameraArray.length; cameraIndex++) {
console.log('cameraId : ' + cameraArray[cameraIndex].cameraId) // Obtain the camera ID. console.log('cameraId : ' + cameraArray[cameraIndex].cameraId) // Obtain the camera ID.
...@@ -58,15 +50,16 @@ for(let cameraIndex = 0; cameraIndex < cameraArray.length; cameraIndex++) { ...@@ -58,15 +50,16 @@ for(let cameraIndex = 0; cameraIndex < cameraArray.length; cameraIndex++) {
console.log('cameraType : ' + cameraArray[cameraIndex].cameraType) // Obtain the camera type. console.log('cameraType : ' + cameraArray[cameraIndex].cameraType) // Obtain the camera type.
console.log('connectionType : ' + cameraArray[cameraIndex].connectionType) // Obtain the camera connection type. console.log('connectionType : ' + cameraArray[cameraIndex].connectionType) // Obtain the camera connection type.
if (cameraArray[cameraIndex].connectionType == CAMERA_CONNECTION_REMOTE) { if (cameraArray[cameraIndex].connectionType == CAMERA_CONNECTION_REMOTE) {
remoteCamera = cameraArray[cameraIndex].cameraId remoteCamera = cameraArray[cameraIndex]
} }
} }
// Create a camera input stream. // Create a camera input stream.
let cameraInput let cameraInput
await cameraManager.createCameraInput(remoteCamera).then((input) => { try {
console.log('Promise returned with the CameraInput instance'); cameraInput = cameraManager.createCameraInput(remoteCamera);
cameraInput = input } catch () {
}) console.error('Failed to createCameraInput errorCode = ' + error.code);
}
``` ```
For details about the subsequent steps, see [Camera Development](./camera.md). For details about the subsequent steps, see [Camera Development](./camera.md).
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册