has.createCameraContext(): CameraContext
Creates a context object of the camera.
Since: 1.0.4
Returns:
CameraContext object.
Example:
const cameraContext = has.createCameraContext();
CameraContext.startRecord(Object object)
Starts recording.
Since: 1.0.4
Required permissions:
Declare ohos.permission.CAMERA and ohos.permission.MICROPHONE in the module.json5 file.
The scope.camera permission is required. In video recording scenarios, the scope.record permission is also required.
Parameters
The input parameter is an object containing the following fields.
| Parameter | Type | Default Value | Mandatory | Description |
|---|---|---|---|---|
| timeoutCallback | function | - | No | Callback triggered when the recording duration exceeds the upper limit or the recording terminates unexpectedly. |
| timeout | number | 30 | No | Maximum recording duration, in seconds. The maximum duration cannot exceed 5 minutes. |
| success | function | - | No | Callback triggered when the API call is successful. |
| fail | function | - | No | Callback triggered when the API call fails. |
| complete | function | - | No | Callback triggered when the API call is complete, regardless of success or failure. |
Return value of timeoutCallback
| Parameter | Type | Description |
|---|---|---|
| tempThumbPath | string | Temporary path (local path) of the thumbnail file. |
| tempVideoPath | string | Temporary path (local path) of the video file. |
Example:
const cameraContext = has.createCameraContext();
cameraContext.startRecord({
timeoutCallback: (res) => {
console.info('startRecord timeoutCallback', res);
},
timeout: 20,
success: () => {
console.info('startRecord success');
},
fail: (err) => {
console.error('startRecord fail', err);
},
complete: (res) => {
console.info('startRecord complete', res);
}
}); CameraContext.stopRecord(Object object)
Stops recording.
Since: 1.0.4
Parameters
The input parameter is an object containing the following fields.
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| success | function | No | Callback triggered when the API call is successful. |
| fail | function | No | Callback triggered when the API call fails. |
| complete | function | No | Callback triggered when the API call is complete, regardless of success or failure. |
Return value of success
| Parameter | Type | Description |
|---|---|---|
| tempThumbPath | string | Temporary path (local path) of the thumbnail file. |
| tempVideoPath | string | Temporary path (local path) of the video file. |
Example:
const cameraContext = has.createCameraContext();
cameraContext.stopRecord({
success: (res) => {
console.info('stopRecord success', res);
},
fail: (err) => {
console.error('stopRecord fail', err);
},
complete: (res) => {
console.info('stopRecord complete', res);
}
}); CameraContext.takePhoto(Object object)
Captures a photo.
Since: 1.0.4
Required permissions:
Declare ohos.permission.CAMERA and ohos.permission.MICROPHONE in the module.json5 file.
The scope.camera permission is required. In video recording scenarios, the scope.record permission is also required.
Parameters
The input parameter is an object containing the following fields.
| Parameter | Type | Default Value | Mandatory | Description |
|---|---|---|---|---|
| quality | string | normal | No | Quality of the photo. - high: high quality. - normal: medium quality. - low: low quality. |
| selfieMirror | boolean | true | No | Whether to enable mirroring. |
| success | function | - | No | Callback triggered when the API call is successful. |
| fail | function | - | No | Callback triggered when the API call fails. |
| complete | function | - | No | Callback triggered when the API call is complete, regardless of success or failure. |
Return value of success
| Parameter | Type | Description |
|---|---|---|
| tempImagePath | string | Temporary path (local path) of the photo file. |
Example:
const cameraContext = has.createCameraContext();
cameraContext.takePhoto({
quality: 'high',
selfieMirror: false,
success: (res) => {
console.info('takePhoto success', res);
},
fail: (err) => {
console.error('takePhoto fail', err);
},
complete: (res) => {
console.info('takePhoto complete', res);
}
});