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

!3958 翻译完成:3522 API 9 Canary文档合并

Merge pull request !3958 from wusongqing/TR3522
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
## When to Use ## When to Use
You can use video playback APIs to convert video data into visible signals, play the signals using output devices, and manage playback tasks. This document describes the following video playback development scenarios: full-process, normal playback, video switching, and loop playback. You can use video playback APIs to convert video data into visible signals, play the signals using output devices, and manage playback tasks. This document describes development for the following video playback scenarios: full-process, normal playback, video switching, and loop playback.
**Figure 1** Video playback state transition **Figure 1** Video playback state transition
...@@ -16,17 +16,17 @@ You can use video playback APIs to convert video data into visible signals, play ...@@ -16,17 +16,17 @@ You can use video playback APIs to convert video data into visible signals, play
Note: Video playback requires hardware capabilities such as display, audio, and codec. Note: Video playback requires hardware capabilities such as display, audio, and codec.
1. A third-party application obtains a surface ID from the Xcomponent. 1. A third-party application obtains a surface ID from the XComponent.
2. The third-party application transfers the surface ID to the VideoPlayer JS. 2. The third-party application transfers the surface ID to the VideoPlayer JS.
3. The media service flushes the frame data to the surface buffer. 3. The media service flushes the frame data to the surface buffer.
## Compatibility ## Compatibility
You are advised to use the mainstream playback formats and resolutions, rather than custom or abnormal streams to avoid playback failure, frame freezing, and artifacts. The system is not affected by incompatibility issues. If such an error occurs, you can exit stream playback mode. Use the mainstream playback formats and resolutions, rather than custom ones to avoid playback failures, frame freezing, and artifacts. The system is not affected by incompatibility issues. If such an issue occurs, you can exit stream playback mode.
The table below lists the mainstream playback formats and resolutions. The table below lists the mainstream playback formats and resolutions.
| Video Container Specification| Specification Description | Resolution | | Video Container Format| Description | Resolution |
| :----------: | :-----------------------------------------------: | :--------------------------------: | | :----------: | :-----------------------------------------------: | :--------------------------------: |
| mp4 | Video format: H.264/MPEG-2/MPEG-4/H.263; audio format: AAC/MP3| Mainstream resolutions, such as 1080p, 720p, 480p, and 270p| | mp4 | Video format: H.264/MPEG-2/MPEG-4/H.263; audio format: AAC/MP3| Mainstream resolutions, such as 1080p, 720p, 480p, and 270p|
| mkv | Video format: H.264/MPEG-2/MPEG-4/H.263; audio format: AAC/MP3| Mainstream resolutions, such as 1080p, 720p, 480p, and 270p| | mkv | Video format: H.264/MPEG-2/MPEG-4/H.263; audio format: AAC/MP3| Mainstream resolutions, such as 1080p, 720p, 480p, and 270p|
...@@ -41,140 +41,137 @@ For details about the APIs, see [VideoPlayer in the Media API](../reference/apis ...@@ -41,140 +41,137 @@ For details about the APIs, see [VideoPlayer in the Media API](../reference/apis
The full video playback process includes creating an instance, setting the URL, setting the surface ID, preparing for video playback, playing video, pausing playback, obtaining track information, seeking to a playback position, setting the volume, setting the playback speed, stopping playback, resetting the playback configuration, and releasing resources. The full video playback process includes creating an instance, setting the URL, setting the surface ID, preparing for video playback, playing video, pausing playback, obtaining track information, seeking to a playback position, setting the volume, setting the playback speed, stopping playback, resetting the playback configuration, and releasing resources.
For details about the **url** media source input types supported by **VideoPlayer**, see the [url attribute](../reference/apis/js-apis-media.md#videoplayer_attributes). For details about the **url** types supported by **VideoPlayer**, see the [url attribute](../reference/apis/js-apis-media.md#videoplayer_attributes).
For details about how to create an Xcomponent, see [Xcomponent Creation](#Xcomponent). For details about how to create an XComponent, see [XComponent](https://gitee.com/openharmony/docs/blob/master/en/application-dev/reference/arkui-ts/ts-basic-components-xcomponent.md).
*Note: **setSurface** must be called after the URL is set but before **prepare** is called.
```js ```js
import media from '@ohos.multimedia.media' import media from '@ohos.multimedia.media'
import fileIO from '@ohos.fileio' import fileIO from '@ohos.fileio'
export class VideoPlayerDemo {
let videoPlayer = undefined; // Used to store instances created by calling the createVideoPlayer API. // Report an error in the case of a function invocation failure.
let surfaceID = undefined; // Used to save the surface ID returned by the Xcomponent interface. failureCallback(error) {
// The LoadXcomponent() API is used to obtain the surface ID and save it to the **surfaceID** variable. This API is automatically called when the Xcomponent is loaded.
LoadXcomponent() {
surfaceID = this.$element('Xcomponent').getXComponentSurfaceId();
console.info('LoadXcomponent surfaceID is' + surfaceID);
}
// Report an error in the case of a function invocation failure.
function failureCallback(error) {
console.info(`error happened,error Name is ${error.name}`); console.info(`error happened,error Name is ${error.name}`);
console.info(`error happened,error Code is ${error.code}`); console.info(`error happened,error Code is ${error.code}`);
console.info(`error happened,error Message is ${error.message}`); console.info(`error happened,error Message is ${error.message}`);
} }
// Report an error in the case of a function invocation exception. // Report an error in the case of a function invocation exception.
function catchCallback(error) { catchCallback(error) {
console.info(`catch error happened,error Name is ${error.name}`); console.info(`catch error happened,error Name is ${error.name}`);
console.info(`catch error happened,error Code is ${error.code}`); console.info(`catch error happened,error Code is ${error.code}`);
console.info(`catch error happened,error Message is ${error.message}`); console.info(`catch error happened,error Message is ${error.message}`);
} }
// Used to print the video track information. // Used to print the video track information.
function printfDescription(obj) { printfDescription(obj) {
for (let item in obj) { for (let item in obj) {
let property = obj[item]; let property = obj[item];
console.info('key is ' + item); console.info('key is ' + item);
console.info('value is ' + property); console.info('value is ' + property);
} }
} }
// Call createVideoPlayer to create a VideoPlayer instance. async videoPlayerDemo() {
await media.createVideoPlayer().then((video) => { let videoPlayer = undefined;
if (typeof (video) != 'undefined') { let surfaceID = 'test' // The surfaceID parameter is used for screen display. Its value is obtained through the XComponent interface. For details about the document link, see the method of creating the XComponent.
let fdPath = 'fd://'
// The stream in the path can be pushed to the device by running the "hdc file send D:\xxx\H264_AAC.mp4 /data/app/el1/bundle/public/ohos.acts.multimedia.video.videoplayer/ohos.acts.multimedia.video.videoplayer/assets/entry/resources/rawfile" command.
let path = '/data/app/el1/bundle/public/ohos.acts.multimedia.video.videoplayer/ohos.acts.multimedia.video.videoplayer/assets/entry/resources/rawfile/H264_AAC.mp4';
await fileIO.open(path).then((fdNumber) => {
fdPath = fdPath + '' + fdNumber;
console.info('open fd sucess fd is' + fdPath);
}, (err) => {
console.info('open fd failed err is' + err);
}).catch((err) => {
console.info('open fd failed err is' + err);
});
// Call createVideoPlayer to create a VideoPlayer instance.
await media.createVideoPlayer().then((video) => {
if (typeof (video) != 'undefined') {
console.info('createVideoPlayer success!'); console.info('createVideoPlayer success!');
videoPlayer = video; videoPlayer = video;
} else { } else {
console.info('createVideoPlayer fail!'); console.info('createVideoPlayer fail!');
} }
}, failureCallback).catch(catchCallback); }, this.failureCallback).catch(this.catchCallback);
// Set the playback source URL for the player.
// Set the FD (local playback) of the video file selected by the user. videoPlayer.url = fdPath;
let fdPath = 'fd://'
let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp4'; // Set the surface ID to display the video image.
await fileIO.open(path).then(fdNumber) => { await videoPlayer.setDisplaySurface(surfaceID).then(() => {
fdPath = fdPath + '' + fdNumber; console.info('setDisplaySurface success');
console.info('open fd sucess fd is' + fdPath); }, this.failureCallback).catch(this.catchCallback);
}, (err) => {
console.info('open fd failed err is' + err); // Call the prepare API to prepare for playback.
}),catch((err) => { await videoPlayer.prepare().then(() => {
console.info('open fd failed err is' + err); console.info('prepare success');
}); }, this.failureCallback).catch(this.catchCallback);
videoPlayer.url = fdPath; // Call the play API to start playback.
await videoPlayer.play().then(() => {
// Set the surface ID to display the video image. console.info('play success');
await videoPlayer.setDisplaySurface(surfaceID).then(() => { }, this.failureCallback).catch(this.catchCallback);
console.info('setDisplaySurface success');
}, failureCallback).catch(catchCallback); // Pause playback.
await videoPlayer.pause().then(() => {
// Call the prepare interface to prepare for playback. console.info('pause success');
await videoPlayer.prepare().then(() => { }, this.failureCallback).catch(this.catchCallback);
console.info('prepare success');
}, failureCallback).catch(catchCallback); // Use a promise to obtain the video track information.
let arrayDescription;
// Call the play interface to start playback. await videoPlayer.getTrackDescription().then((arrlist) => {
await videoPlayer.play().then(() => { if (typeof (arrlist) != 'undefined') {
console.info('play success');
}, failureCallback).catch(catchCallback);
// Pause playback.
await videoPlayer.pause().then(() => {
console.info('pause success');
}, failureCallback).catch(catchCallback);
// Use a promise to obtain the video track information.
let arrayDescription;
await videoPlayer.getTrackDescription().then((arrlist) => {
if (typeof (arrlist) != 'undefined') {
arrayDescription = arrlist; arrayDescription = arrlist;
} else { } else {
console.log('video getTrackDescription fail'); console.log('video getTrackDescription fail');
}
}, this.failureCallback).catch(this.catchCallback);
for (let i = 0; i < arrayDescription.length; i++) {
this.printfDescription(arrayDescription[i]);
} }
}, failureCallback).catch(catchCallback);
for (let i = 0; i < arrayDescription.length; i++) { // Seek to the 50s position. For details about the input parameters, see the interface document.
printfDescription(arrayDescription[i]); let seekTime = 50000;
await videoPlayer.seek(seekTime, media.SeekMode.SEEK_NEXT_SYNC).then((seekDoneTime) => {
console.info('seek success');
}, this.failureCallback).catch(this.catchCallback);
// Set the volume. For details about the input parameters, see the interface document.
let volume = 0.5;
await videoPlayer.setVolume(volume).then(() => {
console.info('setVolume success');
}, this.failureCallback).catch(this.catchCallback);
// Set the playback speed. For details about the input parameters, see the interface document.
let speed = media.PlaybackSpeed.SPEED_FORWARD_2_00_X;
await videoPlayer.setSpeed(speed).then(() => {
console.info('setSpeed success');
}, this.failureCallback).catch(this.catchCallback);
// Stop playback.
await videoPlayer.stop().then(() => {
console.info('stop success');
}, this.failureCallback).catch(this.catchCallback);
// Reset the playback configuration.
await videoPlayer.reset().then(() => {
console.info('reset success');
}, this.failureCallback).catch(this.catchCallback);
// Release playback resources.
await videoPlayer.release().then(() => {
console.info('release success');
}, this.failureCallback).catch(this.catchCallback);
// Set the related instances to undefined.
videoPlayer = undefined;
surfaceID = undefined;
}
} }
// Seek to the 50s position. For details about the input parameters, see the interface document.
let seekTime = 50000;
await videoPlayer.seek(seekTime, media.SeekMode._NEXT_SYNC).then((seekDoneTime) => {
console.info('seek success');
}, failureCallback).catch(catchCallback);
// Set the volume. For details about the input parameters, see the interface document.
let volume = 0.5;
await videoPlayer.setVolume(volume).then(() => {
console.info('setVolume success');
}, failureCallback).catch(catchCallback);
// Set the playback speed. For details about the input parameters, see the interface document.
let speed = media.PlaybackRateMode.SPEED_FORWARD_2_00_X;
await videoPlayer.setSpeed(speed).then(() => {
console.info('setSpeed success');
}, failureCallback).catch(catchCallback);
// Stop playback.
await videoPlayer.stop().then(() => {
console.info('stop success');
}, failureCallback).catch(catchCallback);
// Reset the playback configuration.
await videoPlayer.reset().then(() => {
console.info('reset success');
}, failureCallback).catch(catchCallback);
// Release playback resources.
await videoPlayer.release().then(() => {
console.info('release success');
}, failureCallback).catch(catchCallback);
// Set the related instances to undefined.
videoPlayer = undefined;
surfaceID = undefined;
``` ```
### Normal Playback Scenario ### Normal Playback Scenario
...@@ -182,85 +179,86 @@ surfaceID = undefined; ...@@ -182,85 +179,86 @@ surfaceID = undefined;
```js ```js
import media from '@ohos.multimedia.media' import media from '@ohos.multimedia.media'
import fileIO from '@ohos.fileio' import fileIO from '@ohos.fileio'
export class VideoPlayerDemo {
let videoPlayer = undefined; // Used to store instances created by calling the createVideoPlayer API. // Report an error in the case of a function invocation failure.
let surfaceID = undefined; // Used to save the surface ID returned by the Xcomponent interface. failureCallback(error) {
// The LoadXcomponent() API is used to obtain the surface ID and save it to the **surfaceID** variable. This API is automatically called when the Xcomponent is loaded.
LoadXcomponent() {
surfaceID = this.$element('Xcomponent').getXComponentSurfaceId();
console.info('LoadXcomponent surfaceID is' + surfaceID);
}
// Report an error in the case of a function invocation failure.
function failureCallback(error) {
console.info(`error happened,error Name is ${error.name}`); console.info(`error happened,error Name is ${error.name}`);
console.info(`error happened,error Code is ${error.code}`); console.info(`error happened,error Code is ${error.code}`);
console.info(`error happened,error Message is ${error.message}`); console.info(`error happened,error Message is ${error.message}`);
} }
// Report an error in the case of a function invocation exception. // Report an error in the case of a function invocation exception.
function catchCallback(error) { catchCallback(error) {
console.info(`catch error happened,error Name is ${error.name}`); console.info(`catch error happened,error Name is ${error.name}`);
console.info(`catch error happened,error Code is ${error.code}`); console.info(`catch error happened,error Code is ${error.code}`);
console.info(`catch error happened,error Message is ${error.message}`); console.info(`catch error happened,error Message is ${error.message}`);
} }
// Set the 'playbackCompleted' event callback, which is triggered when the playback is complete. // Used to print the video track information.
function SetCallBack(videoPlayer) { printfDescription(obj) {
videoPlayer.on('playbackCompleted', () => { for (let item in obj) {
console.info('video play finish'); let property = obj[item];
console.info('key is ' + item);
await videoPlayer.release().then(() => { console.info('value is ' + property);
console.info('release success'); }
}, failureCallback).catch(catchCallback); }
videoPlayer = undefined; async videoPlayerDemo() {
surfaceID = undefined; let videoPlayer = undefined;
let surfaceID = 'test' // The surfaceID parameter is used for screen display. Its value is obtained through the XComponent interface. For details about the document link, see the method of creating the XComponent.
let fdPath = 'fd://'
// The stream in the path can be pushed to the device by running the "hdc file send D:\xxx\H264_AAC.mp4 /data/app/el1/bundle/public/ohos.acts.multimedia.video.videoplayer/ohos.acts.multimedia.video.videoplayer/assets/entry/resources/rawfile" command.
let path = '/data/app/el1/bundle/public/ohos.acts.multimedia.video.videoplayer/ohos.acts.multimedia.video.videoplayer/assets/entry/resources/rawfile/H264_AAC.mp4';
await fileIO.open(path).then((fdNumber) => {
fdPath = fdPath + '' + fdNumber;
console.info('open fd sucess fd is' + fdPath);
}, (err) => {
console.info('open fd failed err is' + err);
}).catch((err) => {
console.info('open fd failed err is' + err);
}); });
} // Call createVideoPlayer to create a VideoPlayer instance.
await media.createVideoPlayer().then((video) => {
// Call createVideoPlayer to create a VideoPlayer instance. if (typeof (video) != 'undefined') {
await media.createVideoPlayer().then((video) => {
if (typeof (video) != 'undefined') {
console.info('createVideoPlayer success!'); console.info('createVideoPlayer success!');
videoPlayer = video; videoPlayer = video;
} else { } else {
console.info('createVideoPlayer fail!'); console.info('createVideoPlayer fail!');
} }
}, failureCallback).catch(catchCallback); }, this.failureCallback).catch(this.catchCallback);
// Set the playback source for the player.
// Set the event callbacks. videoPlayer.url = fdPath;
SetCallBack(videoPlayer);
// Set the surface ID to display the video image.
// Set the FD (local playback) of the video file selected by the user. await videoPlayer.setDisplaySurface(surfaceID).then(() => {
let fdPath = 'fd://' console.info('setDisplaySurface success');
let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp4'; }, this.failureCallback).catch(this.catchCallback);
await fileIO.open(path).then(fdNumber) => {
fdPath = fdPath + '' + fdNumber; // Call the prepare API to prepare for playback.
console.info('open fd sucess fd is' + fdPath); await videoPlayer.prepare().then(() => {
}, (err) => { console.info('prepare success');
console.info('open fd failed err is' + err); }, this.failureCallback).catch(this.catchCallback);
}),catch((err) => {
console.info('open fd failed err is' + err); // Call the play API to start playback.
}); await videoPlayer.play().then(() => {
console.info('play success');
videoPlayer.url = fdPath; }, this.failureCallback).catch(this.catchCallback);
// Set the surface ID to display the video image. // Stop playback.
await videoPlayer.setDisplaySurface(surfaceID).then(() => { await videoPlayer.stop().then(() => {
console.info('setDisplaySurface success'); console.info('stop success');
}, failureCallback).catch(catchCallback); }, this.failureCallback).catch(this.catchCallback);
// Call the prepare interface to prepare for playback. // Release playback resources.
await videoPlayer.prepare().then(() => { await videoPlayer.release().then(() => {
console.info('prepare success'); console.info('release success');
}, failureCallback).catch(catchCallback); }, this.failureCallback).catch(this.catchCallback);
// Call the play interface to start playback. // Set the related instances to undefined.
await videoPlayer.play().then(() => { videoPlayer = undefined;
console.info('play success'); surfaceID = undefined;
}, failureCallback).catch(catchCallback); }
}
``` ```
### Switching to the Next Video Clip ### Switching to the Next Video Clip
...@@ -268,120 +266,110 @@ await videoPlayer.play().then(() => { ...@@ -268,120 +266,110 @@ await videoPlayer.play().then(() => {
```js ```js
import media from '@ohos.multimedia.media' import media from '@ohos.multimedia.media'
import fileIO from '@ohos.fileio' import fileIO from '@ohos.fileio'
export class VideoPlayerDemo {
let videoPlayer = undefined; // Used to store instances created by calling the createVideoPlayer API. // Report an error in the case of a function invocation failure.
let surfaceID = undefined; // Used to save the surface ID returned by the Xcomponent interface. failureCallback(error) {
// The LoadXcomponent() API is used to obtain the surface ID and save it to the **surfaceID** variable. This API is automatically called when the Xcomponent is loaded.
LoadXcomponent() {
surfaceID = this.$element('Xcomponent').getXComponentSurfaceId();
console.info('LoadXcomponent surfaceID is' + surfaceID);
}
// Report an error in the case of a function invocation failure.
function failureCallback(error) {
console.info(`error happened,error Name is ${error.name}`); console.info(`error happened,error Name is ${error.name}`);
console.info(`error happened,error Code is ${error.code}`); console.info(`error happened,error Code is ${error.code}`);
console.info(`error happened,error Message is ${error.message}`); console.info(`error happened,error Message is ${error.message}`);
} }
// Report an error in the case of a function invocation exception. // Report an error in the case of a function invocation exception.
function catchCallback(error) { catchCallback(error) {
console.info(`catch error happened,error Name is ${error.name}`); console.info(`catch error happened,error Name is ${error.name}`);
console.info(`catch error happened,error Code is ${error.code}`); console.info(`catch error happened,error Code is ${error.code}`);
console.info(`catch error happened,error Message is ${error.message}`); console.info(`catch error happened,error Message is ${error.message}`);
} }
// Set the 'playbackCompleted' event callback, which is triggered when the playback is complete. // Used to print the video track information.
function SetCallBack(videoPlayer) { printfDescription(obj) {
videoPlayer.on('playbackCompleted', () => { for (let item in obj) {
console.info('video play finish'); let property = obj[item];
console.info('key is ' + item);
await videoPlayer.release().then(() => { console.info('value is ' + property);
console.info('release success'); }
}, failureCallback).catch(catchCallback); }
videoPlayer = undefined; async videoPlayerDemo() {
surfaceID = undefined; let videoPlayer = undefined;
let surfaceID = 'test' // The surfaceID parameter is used for screen display. Its value is obtained through the XComponent interface. For details about the document link, see the method of creating the XComponent.
let fdPath = 'fd://'
// The stream in the path can be pushed to the device by running the "hdc file send D:\xxx\H264_AAC.mp4 /data/app/el1/bundle/public/ohos.acts.multimedia.video.videoplayer/ohos.acts.multimedia.video.videoplayer/assets/entry/resources/rawfile" command.
let path = '/data/app/el1/bundle/public/ohos.acts.multimedia.video.videoplayer/ohos.acts.multimedia.video.videoplayer/assets/entry/resources/rawfile/H264_AAC.mp4';
let nextPath = '/data/app/el1/bundle/public/ohos.acts.multimedia.video.videoplayer/ohos.acts.multimedia.video.videoplayer/assets/entry/resources/rawfile/MP4_AAC.mp4';
await fileIO.open(path).then((fdNumber) => {
fdPath = fdPath + '' + fdNumber;
console.info('open fd sucess fd is' + fdPath);
}, (err) => {
console.info('open fd failed err is' + err);
}).catch((err) => {
console.info('open fd failed err is' + err);
}); });
} // Call createVideoPlayer to create a VideoPlayer instance.
await media.createVideoPlayer().then((video) => {
// Call createVideoPlayer to create a VideoPlayer instance. if (typeof (video) != 'undefined') {
await media.createVideoPlayer().then((video) => {
if (typeof (video) != 'undefined') {
console.info('createVideoPlayer success!'); console.info('createVideoPlayer success!');
videoPlayer = video; videoPlayer = video;
} else { } else {
console.info('createVideoPlayer fail!'); console.info('createVideoPlayer fail!');
} }
}, failureCallback).catch(catchCallback); }, this.failureCallback).catch(this.catchCallback);
// Set the playback source for the player.
// Set the event callbacks. videoPlayer.url = fdPath;
SetCallBack(videoPlayer);
// Set the surface ID to display the video image.
// Set the FD (local playback) of the video file selected by the user. await videoPlayer.setDisplaySurface(surfaceID).then(() => {
let fdPath = 'fd://' console.info('setDisplaySurface success');
let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp4'; }, this.failureCallback).catch(this.catchCallback);
await fileIO.open(path).then(fdNumber) => {
fdPath = fdPath + '' + fdNumber; // Call the prepare API to prepare for playback.
console.info('open fd sucess fd is' + fdPath); await videoPlayer.prepare().then(() => {
}, (err) => { console.info('prepare success');
console.info('open fd failed err is' + err); }, this.failureCallback).catch(this.catchCallback);
}),catch((err) => {
console.info('open fd failed err is' + err); // Call the play API to start playback.
}); await videoPlayer.play().then(() => {
console.info('play success');
videoPlayer.url = fdPath; }, this.failureCallback).catch(this.catchCallback);
// Set the surface ID to display the video image. // Reset the playback configuration.
await videoPlayer.setDisplaySurface(surfaceID).then(() => { await videoPlayer.reset().then(() => {
console.info('setDisplaySurface success'); console.info('reset success');
}, failureCallback).catch(catchCallback); }, this.failureCallback).catch(this.catchCallback);
// Call the prepare interface to prepare for playback. // Obtain the next video FD address.
await videoPlayer.prepare().then(() => { fdPath = 'fd://'
console.info('prepare success'); await fileIO.open(nextPath).then((fdNumber) => {
}, failureCallback).catch(catchCallback); fdPath = fdPath + '' + fdNumber;
console.info('open fd sucess fd is' + fdPath);
// Call the play interface to start playback. }, (err) => {
await videoPlayer.play().then(() => { console.info('open fd failed err is' + err);
console.info('play success'); }).catch((err) => {
}, failureCallback).catch(catchCallback); console.info('open fd failed err is' + err);
});
// Send the instruction to switch to the next video clip after a period of time. // Set the second video playback source.
// Reset the playback configuration. videoPlayer.url = fdPath;
await videoPlayer.reset().then(() => {
console.info('reset success'); // Call the prepare interface to prepare for playback.
}, failureCallback).catch(catchCallback); await videoPlayer.prepare().then(() => {
console.info('prepare success');
// Set the FD (local playback) of the video file selected by the user. }, this.failureCallback).catch(this.catchCallback);
let fdNextPath = 'fd://'
let nextPath = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/02.mp4'; // Call the play API to start playback.
await fileIO.open(nextPath).then(fdNumber) => { await videoPlayer.play().then(() => {
fdNextPath = fdNextPath + '' + fdNumber; console.info('play success');
console.info('open fd sucess fd is' + fdNextPath); }, this.failureCallback).catch(this.catchCallback);
}, (err) => {
console.info('open fd failed err is' + err); // Release playback resources.
}),catch((err) => { await videoPlayer.release().then(() => {
console.info('open fd failed err is' + err); console.info('release success');
}); }, this.failureCallback).catch(this.catchCallback);
videoPlayer.url = fdNextPath; // Set the related instances to undefined.
videoPlayer = undefined;
// Set the surface ID to display the video image. surfaceID = undefined;
await videoPlayer.setDisplaySurface(surfaceID).then(() => { }
console.info('setDisplaySurface success'); }
}, failureCallback).catch(catchCallback);
// Call the prepare interface to prepare for playback.
await videoPlayer.prepare().then(() => {
console.info('prepare success');
}, failureCallback).catch(catchCallback);
// Call the play interface to start playback.
await videoPlayer.play().then(() => {
console.info('play success');
}, failureCallback).catch(catchCallback);
``` ```
### Looping a Video Clip ### Looping a Video Clip
...@@ -389,99 +377,88 @@ await videoPlayer.play().then(() => { ...@@ -389,99 +377,88 @@ await videoPlayer.play().then(() => {
```js ```js
import media from '@ohos.multimedia.media' import media from '@ohos.multimedia.media'
import fileIO from '@ohos.fileio' import fileIO from '@ohos.fileio'
export class VideoPlayerDemo {
let videoPlayer = undefined; // Used to store instances created by calling the createVideoPlayer API. // Report an error in the case of a function invocation failure.
let surfaceID = undefined; // Used to save the surface ID returned by the Xcomponent interface. failureCallback(error) {
// The LoadXcomponent() API is used to obtain the surface ID and save it to the **surfaceID** variable. This API is automatically called when the Xcomponent is loaded.
LoadXcomponent() {
surfaceID = this.$element('Xcomponent').getXComponentSurfaceId();
console.info('LoadXcomponent surfaceID is' + surfaceID);
}
// Report an error in the case of a function invocation failure.
function failureCallback(error) {
console.info(`error happened,error Name is ${error.name}`); console.info(`error happened,error Name is ${error.name}`);
console.info(`error happened,error Code is ${error.code}`); console.info(`error happened,error Code is ${error.code}`);
console.info(`error happened,error Message is ${error.message}`); console.info(`error happened,error Message is ${error.message}`);
} }
// Report an error in the case of a function invocation exception. // Report an error in the case of a function invocation exception.
function catchCallback(error) { catchCallback(error) {
console.info(`catch error happened,error Name is ${error.name}`); console.info(`catch error happened,error Name is ${error.name}`);
console.info(`catch error happened,error Code is ${error.code}`); console.info(`catch error happened,error Code is ${error.code}`);
console.info(`catch error happened,error Message is ${error.message}`); console.info(`catch error happened,error Message is ${error.message}`);
} }
// Set the 'playbackCompleted' event callback, which is triggered when the playback is complete. // Used to print the video track information.
function SetCallBack(videoPlayer) { printfDescription(obj) {
videoPlayer.on('playbackCompleted', () => { for (let item in obj) {
console.info('video play finish'); let property = obj[item];
console.info('key is ' + item);
await videoPlayer.release().then(() => { console.info('value is ' + property);
console.info('release success'); }
}, failureCallback).catch(catchCallback); }
videoPlayer = undefined; sleep(time) {
surfaceID = undefined; for(let t = Date.now(); Date.now() - t <= time;);
}
async videoPlayerDemo() {
let videoPlayer = undefined;
let surfaceID = 'test' // The surfaceID parameter is used for screen display. Its value is obtained through the XComponent interface. For details about the document link, see the method of creating the XComponent.
let fdPath = 'fd://'
// The stream in the path can be pushed to the device by running the "hdc file send D:\xxx\H264_AAC.mp4 /data/app/el1/bundle/public/ohos.acts.multimedia.video.videoplayer/ohos.acts.multimedia.video.videoplayer/assets/entry/resources/rawfile" command.
let path = '/data/app/el1/bundle/public/ohos.acts.multimedia.video.videoplayer/ohos.acts.multimedia.video.videoplayer/assets/entry/resources/rawfile/H264_AAC.mp4';
await fileIO.open(path).then((fdNumber) => {
fdPath = fdPath + '' + fdNumber;
console.info('open fd sucess fd is' + fdPath);
}, (err) => {
console.info('open fd failed err is' + err);
}).catch((err) => {
console.info('open fd failed err is' + err);
}); });
} // Call createVideoPlayer to create a VideoPlayer instance.
await media.createVideoPlayer().then((video) => {
// Call createVideoPlayer to create a VideoPlayer instance. if (typeof (video) != 'undefined') {
await media.createVideoPlayer().then((video) => {
if (typeof (video) != 'undefined') {
console.info('createVideoPlayer success!'); console.info('createVideoPlayer success!');
videoPlayer = video; videoPlayer = video;
} else { } else {
console.info('createVideoPlayer fail!'); console.info('createVideoPlayer fail!');
} }
}, failureCallback).catch(catchCallback); }, this.failureCallback).catch(this.catchCallback);
// Set the playback source for the player.
// Set the event callbacks. videoPlayer.url = fdPath;
SetCallBack(videoPlayer);
// Set the surface ID to display the video image.
// Set the FD (local playback) of the video file selected by the user. await videoPlayer.setDisplaySurface(surfaceID).then(() => {
let fdPath = 'fd://' console.info('setDisplaySurface success');
let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp4'; }, this.failureCallback).catch(this.catchCallback);
await fileIO.open(path).then(fdNumber) => {
fdPath = fdPath + '' + fdNumber; // Call the prepare API to prepare for playback.
console.info('open fd sucess fd is' + fdPath); await videoPlayer.prepare().then(() => {
}, (err) => { console.info('prepare success');
console.info('open fd failed err is' + err); }, this.failureCallback).catch(this.catchCallback);
}),catch((err) => { // Set the loop playback attribute.
console.info('open fd failed err is' + err); videoPlayer.loop = true;
}); // Call the play API to start playback.
await videoPlayer.play().then(() => {
videoPlayer.url = fdPath; console.info('play success');
}, this.failureCallback).catch(this.catchCallback);
// Set the surface ID to display the video image. // After the progress bar reaches the end, the playback continues for 3 seconds and then starts from the beginning, since loop playback is configured.
await videoPlayer.setDisplaySurface(surfaceID).then(() => { await videoPlayer.seek(videoPlayer.duration, media.SeekMode.SEEK_NEXT_SYNC).then((seekDoneTime) => {
console.info('setDisplaySurface success'); console.info('seek duration success');
}, failureCallback).catch(catchCallback); }, this.failureCallback).catch(this.catchCallback);
this.sleep(3000);
// Call the prepare interface to prepare for playback. // Release playback resources.
await videoPlayer.prepare().then(() => { await videoPlayer.release().then(() => {
console.info('prepare success'); console.info('release success');
}, failureCallback).catch(catchCallback); }, this.failureCallback).catch(this.catchCallback);
// Set the loop playback attribute. // Set the related instances to undefined.
videoPlayer.loop = true; videoPlayer = undefined;
surfaceID = undefined;
// Call the play interface to start playback. }
await videoPlayer.play().then(() => { }
console.info('play success');
}, failureCallback).catch(catchCallback);
```
### Xcomponent Creation
The Xcomponent is used to obtain the surface ID during video playback. You need to create an xxx.hml file and add the following code to the xxx.hml file, where xxx is the same as that in the xxx.js file:
```js
<xcomponent id = 'Xcomponent'
if = "{{isFlush}}" // Refresh the surface ID. To enable automatic loading of the Xcomponent and obtain the new surface ID, assign **false** to **isFlush** and then assign **true** to **isFlush**.
type = 'surface'
onload = 'LoadXcomponent' // Default interface for loading the Xcomponent.
style = "width:720px;height:480px;border-color:red;border-width:5px;"> // Set the window width, height, and other attributes.
</xcomponent>
``` ```
# Audio Management # Audio Management
> **NOTE** > **NOTE**<br/>
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> API version 9 is a canary release for trial use. The APIs of this version may be unstable.
This module provides the following common audio-related functions: This module provides the following common audio-related functions:
- [AudioManager](#audiomanager): Audio management. - [AudioManager](#audiomanager): audio management.
- [AudioRenderer](#audiorenderer8): Audio rendering, used to play Pulse Code Modulation (PCM) audio data. - [AudioRenderer](#audiorenderer8): audio rendering, used to play Pulse Code Modulation (PCM) audio data.
- [AudioCapturer](#audiocapturer8): Audio capture, used to record PCM audio data. - [AudioCapturer](#audiocapturer8): audio capture, used to record PCM audio data.
## Modules to Import ## Modules to Import
...@@ -15,22 +17,21 @@ This module provides the following common audio-related functions: ...@@ -15,22 +17,21 @@ This module provides the following common audio-related functions:
import audio from '@ohos.multimedia.audio'; import audio from '@ohos.multimedia.audio';
``` ```
## audio.getAudioManager ## audio.getAudioManager
getAudioManager(): AudioManager getAudioManager(): AudioManager
Obtains an **AudioManager** instance. Obtains an **AudioManager** instance.
**System capability:** SystemCapability.Multimedia.Audio.Core **System capability**: SystemCapability.Multimedia.Audio.Core
**Return value:**
| Type | Description | **Return value**
| ----------------------------- | -------------------- | | Type | Description |
| [AudioManager](#audiomanager) | AudioManager object. | | ----------------------------- | ------------ |
| [AudioManager](#audiomanager) | **AudioManager** instance.|
**Example:**
**Example**
``` ```
var audioManager = audio.getAudioManager(); var audioManager = audio.getAudioManager();
``` ```
...@@ -39,17 +40,18 @@ var audioManager = audio.getAudioManager(); ...@@ -39,17 +40,18 @@ var audioManager = audio.getAudioManager();
createAudioRenderer(options: AudioRendererOptions, callback: AsyncCallback\<AudioRenderer>): void createAudioRenderer(options: AudioRendererOptions, callback: AsyncCallback\<AudioRenderer>): void
Obtains an **AudioRenderer** instance. This API uses an asynchronous callback to return the renderer instance. Obtains an **AudioRenderer** instance. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Audio.Renderer
**System capability:** SystemCapability.Multimedia.Audio.Renderer **Parameters**
**Parameters:** | Name | Type | Mandatory| Description |
| Name | Type | Mandatory | Description | | -------- | ----------------------------------------------- | ---- | ---------------- |
| :--------- | :---------------------------------------------- | :-------- | :--------------------------------------------------- | | options | [AudioRendererOptions](#audiorendereroptions8) | Yes | Renderer configurations. |
| options | [AudioRendererOptions](#audiorendereroptions8) | Yes | Renderer configurations. | | callback | AsyncCallback<[AudioRenderer](#audiorenderer8)> | Yes | Callback used to return the **AudioRenderer** instance.|
| callback | AsyncCallback<[AudioRenderer](#audiorenderer8)> | Yes | Callback used to return the audio renderer instance. |
**Example:** **Example**
``` ```
import audio from '@ohos.multimedia.audio'; import audio from '@ohos.multimedia.audio';
...@@ -81,26 +83,28 @@ audio.createAudioRenderer(audioRendererOptions,(err, data) => { ...@@ -81,26 +83,28 @@ audio.createAudioRenderer(audioRendererOptions,(err, data) => {
} }
}); });
``` ```
## audio.createAudioRenderer<sup>8+</sup> ## audio.createAudioRenderer<sup>8+</sup>
createAudioRenderer(options: AudioRendererOptions): Promise<AudioRenderer> createAudioRenderer(options: AudioRendererOptions): Promise<AudioRenderer\>
Obtains an **AudioRenderer** instance. This API uses a promise to return the result.
Obtains an **AudioRenderer** instance. This API uses a promise to return the renderer instance. **System capability**: SystemCapability.Multimedia.Audio.Renderer
**System capability:** SystemCapability.Multimedia.Audio.Renderer **Parameters**
**Parameters:** | Name | Type | Mandatory| Description |
| Name | Type | Mandatory | Description | | :------ | :--------------------------------------------- | :--- | :----------- |
| :--------- | :--------------------------------------------- | :-------- | :---------------------------| | options | [AudioRendererOptions](#audiorendereroptions8) | Yes | Renderer configurations.|
| options | [AudioRendererOptions](#audiorendereroptions8) | Yes | Renderer configurations. |
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ----------------------------------------- | --------------------------------------------------- | | ----------------------------------------- | ---------------- |
| Promise<[AudioRenderer](#audiorenderer8)> | Promise used to return the audio renderer instance. | | Promise<[AudioRenderer](#audiorenderer8)> | Promise used to return the **AudioRenderer** instance.|
**Example:** **Example**
``` ```
import audio from '@ohos.multimedia.audio'; import audio from '@ohos.multimedia.audio';
...@@ -136,17 +140,18 @@ audio.createAudioRenderer(audioRendererOptions).then((data) => { ...@@ -136,17 +140,18 @@ audio.createAudioRenderer(audioRendererOptions).then((data) => {
createAudioCapturer(options: AudioCapturerOptions, callback: AsyncCallback<AudioCapturer\>): void createAudioCapturer(options: AudioCapturerOptions, callback: AsyncCallback<AudioCapturer\>): void
Obtains an **AudioCapturer** instance. This API uses an asynchronous callback to return the capturer instance. Obtains an **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description |
| :--------- | :---------------------------------------------- | :-------- | :--------------------------------------------------- |
| options | [AudioCapturerOptions](#audiocaptureroptions8) | Yes | Capturer configurations. |
| callback | AsyncCallback<[AudioCapturer](#audiocapturer8)> | Yes | Callback used to return the audio capturer instance. |
**Example:** | Name | Type | Mandatory| Description |
| :------- | :---------------------------------------------- | :--- | :--------------- |
| options | [AudioCapturerOptions](#audiocaptureroptions8) | Yes | Capturer configurations.|
| callback | AsyncCallback<[AudioCapturer](#audiocapturer8)> | Yes | Callback used to return the **AudioCapturer** instance.|
**Example**
``` ```
import audio from '@ohos.multimedia.audio'; import audio from '@ohos.multimedia.audio';
...@@ -182,22 +187,23 @@ audio.createAudioCapturer(audioCapturerOptions,(err, data) => { ...@@ -182,22 +187,23 @@ audio.createAudioCapturer(audioCapturerOptions,(err, data) => {
createAudioCapturer(options: AudioCapturerOptions): Promise<AudioCapturer\> createAudioCapturer(options: AudioCapturerOptions): Promise<AudioCapturer\>
Obtains an **AudioCapturer** instance. This API uses a promise to return the capturer instance. Obtains an **AudioCapturer** instance. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Audio.Capturer
**System capability:** SystemCapability.Multimedia.Audio.Capturer **Parameters**
**Parameters:** | Name | Type | Mandatory| Description |
| Name | Type | Mandatory | Description | | :------ | :--------------------------------------------- | :--- | :--------------- |
| :--------- | :-------------------------------------------- | :-------- | :-------------------------- | | options | [AudioCapturerOptions](#audiocaptureroptions8) | Yes | Capturer configurations.|
| options | [AudioCapturerOptions](#audiocaptureroptions8) | Yes | Capturer configurations. |
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ----------------------------------------- | --------------------------------------------------- | | ----------------------------------------- | -------------- |
| Promise<[AudioCapturer](#audiocapturer8)> | Promise used to return the audio capturer instance. | | Promise<[AudioCapturer](#audiocapturer8)> | Promise used to return the **AudioCapturer** instance.|
**Example:** **Example**
``` ```
import audio from '@ohos.multimedia.audio'; import audio from '@ohos.multimedia.audio';
...@@ -230,422 +236,429 @@ audio.createAudioRenderer(audioCapturerOptions).then((data) => { ...@@ -230,422 +236,429 @@ audio.createAudioRenderer(audioCapturerOptions).then((data) => {
## AudioVolumeType ## AudioVolumeType
Enumerates audio stream types. Enumerates the audio stream types.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
| Name | Default Value| Description |
| ---------------------------- | ------ | ---------- |
| VOICE_CALL<sup>8+</sup> | 0 | Audio stream for voice calls.|
| RINGTONE | 2 | Audio stream for ringtones. |
| MEDIA | 3 | Audio stream for media purpose. |
| VOICE_ASSISTANT<sup>8+</sup> | 9 | Audio stream for voice assistant.|
| Name | Default Value | Description |
| ---------------------------- | -------------- | --------------------------------- |
| VOICE_CALL<sup>8+</sup> | 0 | Audio stream for voice calls. |
| RINGTONE | 2 | Audio stream for ringtones. |
| MEDIA | 3 | Audio stream for media purpose. |
| VOICE_ASSISTANT<sup>8+</sup> | 9 | Audio stream for voice assistant. |
## DeviceFlag ## DeviceFlag
Enumerates audio device flags. Enumerates the audio device flags.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
| Name | Default Value | Description | | Name | Default Value| Description |
| ------------------- | ------------- | -------------- | | ------------------- | ------ | ---------- |
| OUTPUT_DEVICES_FLAG | 1 | Output device. | | OUTPUT_DEVICES_FLAG | 1 | Output device.|
| INPUT_DEVICES_FLAG | 2 | Input device. | | INPUT_DEVICES_FLAG | 2 | Input device.|
| ALL_DEVICES_FLAG | 3 | All devices. | | ALL_DEVICES_FLAG | 3 | All devices.|
## DeviceRole ## DeviceRole
Enumerates audio device roles. Enumerates the audio device roles.
**System capability**: SystemCapability.Multimedia.Audio.Device
**System capability:** SystemCapability.Multimedia.Audio.Device | Name | Default Value| Description |
| ------------- | ------ | -------------- |
| INPUT_DEVICE | 1 | Input role.|
| OUTPUT_DEVICE | 2 | Output role.|
| Name | Default Value | Description |
| ------------- | ------------- | ------------ |
| INPUT_DEVICE | 1 | Input role. |
| OUTPUT_DEVICE | 2 | Output role. |
## DeviceType ## DeviceType
Enumerates audio device types. Enumerates the audio device types.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
| Name | Default Value | Description | | Name | Default Value| Description |
| ---------------- | ------------- | ------------------------------------------------------------------------ | | ---------------- | ------ | --------------------------------------------------------- |
| INVALID | 0 | Invalid device. | | INVALID | 0 | Invalid device. |
| EARPIECE | 1 | Earpiece. | | EARPIECE | 1 | Earpiece. |
| SPEAKER | 2 | Speaker. | | SPEAKER | 2 | Speaker. |
| WIRED_HEADSET | 3 | Wired headset. | | WIRED_HEADSET | 3 | Wired headset with a microphone. |
| WIRED_HEADPHONES | 4 | Wired headset without microphone. | | WIRED_HEADPHONES | 4 | Wired headset without microphone. |
| BLUETOOTH_SCO | 7 | Bluetooth device using Synchronous Connection Oriented (SCO) links. | | BLUETOOTH_SCO | 7 | Bluetooth device using Synchronous Connection Oriented (SCO) links. |
| BLUETOOTH_A2DP | 8 | Bluetooth device using Advanced Audio Distribution Profile (A2DP) links. | | BLUETOOTH_A2DP | 8 | Bluetooth device using Advanced Audio Distribution Profile (A2DP) links.|
| MIC | 15 | Microphone. | | MIC | 15 | Microphone. |
| USB_HEADSET | 22 | USB Type-C headset. | | USB_HEADSET | 22 | USB Type-C headset. |
## ActiveDeviceType ## ActiveDeviceType
Enumerates the active device types. Enumerates the active device types.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
| Name | Default Value | Description | | Name | Default Value| Description |
| ------------- | ------------- | ---------------------------------------------------------------------- | | ------------- | ------ | ---------------------------------------------------- |
| SPEAKER | 2 | Speaker. | | SPEAKER | 2 | Speaker. |
| BLUETOOTH_SCO | 7 | Bluetooth device using the SCO links. | | BLUETOOTH_SCO | 7 | Bluetooth device using the SCO links.|
## AudioRingMode ## AudioRingMode
Enumerates ringer modes. Enumerates the ringer modes.
**System capability:** SystemCapability.Multimedia.Audio.Communication **System capability**: SystemCapability.Multimedia.Audio.Communication
| Name | Default Value | Description | | Name | Default Value| Description |
| ------------------- | ------------- | ---------------- | | ------------------- | ------ | ---------- |
| RINGER_MODE_SILENT | 0 | Silent mode. | | RINGER_MODE_SILENT | 0 | Silent mode.|
| RINGER_MODE_VIBRATE | 1 | Vibration mode. | | RINGER_MODE_VIBRATE | 1 | Vibration mode.|
| RINGER_MODE_NORMAL | 2 | Normal mode. | | RINGER_MODE_NORMAL | 2 | Normal mode.|
## AudioSampleFormat<sup>8+</sup> ## AudioSampleFormat<sup>8+</sup>
Enumerates the audio sample formats. Enumerate the audio sample formats.
**System capability:** SystemCapability.Multimedia.Audio.Core **System capability**: SystemCapability.Multimedia.Audio.Core
| Name | Default Value | Description | | Name | Default Value| Description |
| :-------------------- | :------------ | :------------------------------------ | | --------------------- | ------ | -------------------------- |
| SAMPLE_FORMAT_INVALID | -1 | Invalid format. | | SAMPLE_FORMAT_INVALID | -1 | Invalid format. |
| SAMPLE_FORMAT_U8 | 0 | Unsigned 8 bit integer. | | SAMPLE_FORMAT_U8 | 0 | Unsigned 8-bit integer. |
| SAMPLE_FORMAT_S16LE | 1 | Signed 16 bit integer, little endian. | | SAMPLE_FORMAT_S16LE | 1 | Signed 16-bit integer, little endian.|
| SAMPLE_FORMAT_S24LE | 2 | Signed 24 bit integer, little endian. | | SAMPLE_FORMAT_S24LE | 2 | Signed 24-bit integer, little endian.|
| SAMPLE_FORMAT_S32LE | 3 | Signed 32 bit integer, little endian. | | SAMPLE_FORMAT_S32LE | 3 | Signed 32-bit integer, little endian.|
## AudioChannel<sup>8+</sup> ## AudioChannel<sup>8+</sup>
Enumerates the audio channels. Enumerates the audio channels.
**System capability:** SystemCapability.Multimedia.Audio.Core **System capability**: SystemCapability.Multimedia.Audio.Core
| Name | Default Value | Description | | Name | Default Value | Description |
| :-------- | :------------ | :--------------- | | --------- | -------- | -------- |
| CHANNEL_1 | 0x1 << 0 | Channel count 1. | | CHANNEL_1 | 0x1 << 0 | Mono.|
| CHANNEL_2 | 0x1 << 1 | Channel count 2. | | CHANNEL_2 | 0x1 << 1 | Dual-channel.|
## AudioSamplingRate<sup>8+</sup> ## AudioSamplingRate<sup>8+</sup>
Enumerates the audio sampling rates. Enumerates the audio sampling rates.
**System capability:** SystemCapability.Multimedia.Audio.Core **System capability**: SystemCapability.Multimedia.Audio.Core
| Name | Default Value | Description | | Name | Default Value| Description |
| :---------------- | :------------ | :------------------- | | ----------------- | ------ | --------------- |
| SAMPLE_RATE_8000 | 8000 | Sampling rate 8000. | | SAMPLE_RATE_8000 | 8000 | The sampling rate is 8000. |
| SAMPLE_RATE_11025 | 11025 | Sampling rate 11025. | | SAMPLE_RATE_11025 | 11025 | The sampling rate is 11025.|
| SAMPLE_RATE_12000 | 12000 | Sampling rate 12000. | | SAMPLE_RATE_12000 | 12000 | The sampling rate is 12000.|
| SAMPLE_RATE_16000 | 16000 | Sampling rate 16000. | | SAMPLE_RATE_16000 | 16000 | The sampling rate is 16000.|
| SAMPLE_RATE_22050 | 22050 | Sampling rate 22050. | | SAMPLE_RATE_22050 | 22050 | The sampling rate is 22050.|
| SAMPLE_RATE_24000 | 24000 | Sampling rate 24000. | | SAMPLE_RATE_24000 | 24000 | The sampling rate is 24000.|
| SAMPLE_RATE_32000 | 32000 | Sampling rate 32000. | | SAMPLE_RATE_32000 | 32000 | The sampling rate is 32000.|
| SAMPLE_RATE_44100 | 44100 | Sampling rate 44100. | | SAMPLE_RATE_44100 | 44100 | The sampling rate is 44100.|
| SAMPLE_RATE_48000 | 48000 | Sampling rate 48000. | | SAMPLE_RATE_48000 | 48000 | The sampling rate is 48000.|
| SAMPLE_RATE_64000 | 64000 | Sampling rate 64000. | | SAMPLE_RATE_64000 | 64000 | The sampling rate is 64000.|
| SAMPLE_RATE_96000 | 96000 | Sampling rate 96000. | | SAMPLE_RATE_96000 | 96000 | The sampling rate is 96000.|
## AudioEncodingType<sup>8+</sup> ## AudioEncodingType<sup>8+</sup>
Enumerates the audio encoding types. Enumerates the audio encoding types.
**System capability:** SystemCapability.Multimedia.Audio.Core **System capability**: SystemCapability.Multimedia.Audio.Core
| Name | Default Value | Description |
| :-------------------- | :------------- | :---------------- |
| ENCODING_TYPE_INVALID | -1 | Invalid. |
| ENCODING_TYPE_RAW | 0 | PCM encoding. |
| Name | Default Value| Description |
| --------------------- | ------ | --------- |
| ENCODING_TYPE_INVALID | -1 | Invalid. |
| ENCODING_TYPE_RAW | 0 | PCM encoding.|
## ContentType ## ContentType
Enumerates the content types. Enumerates the audio content types.
**System capability:** SystemCapability.Multimedia.Audio.Core
| Name | Default Value | Description | **System capability**: SystemCapability.Multimedia.Audio.Core
| :----------------------------------| :------------ | :---------------------- |
| CONTENT_TYPE_UNKNOWN | 0 | Unknown content. |
| CONTENT_TYPE_SPEECH | 1 | Speech content. |
| CONTENT_TYPE_MUSIC | 2 | Music content. |
| CONTENT_TYPE_MOVIE | 3 | Movie content. |
| CONTENT_TYPE_SONIFICATION | 4 | Sonification content. |
| CONTENT_TYPE_RINGTONE<sup>8+</sup> | 5 | Ringtone content. |
| Name | Default Value| Description |
| ---------------------------------- | ------ | ---------- |
| CONTENT_TYPE_UNKNOWN | 0 | Unknown content.|
| CONTENT_TYPE_SPEECH | 1 | Speech. |
| CONTENT_TYPE_MUSIC | 2 | Music. |
| CONTENT_TYPE_MOVIE | 3 | Movie. |
| CONTENT_TYPE_SONIFICATION | 4 | Sonification content.|
| CONTENT_TYPE_RINGTONE<sup>8+</sup> | 5 | Ringtone. |
## StreamUsage ## StreamUsage
Enumerates the stream usage. Enumerates the audio stream usage.
**System capability:** SystemCapability.Multimedia.Audio.Core
| Name | Default Value | Description | **System capability**: SystemCapability.Multimedia.Audio.Core
| :--------------------------------- | :------------ | :-------------------------------- |
| STREAM_USAGE_UNKNOWN | 0 | Unknown usage. |
| STREAM_USAGE_MEDIA | 1 | Media usage. |
| STREAM_USAGE_VOICE_COMMUNICATION | 2 | Voice communication usage. |
| STREAM_USAGE_NOTIFICATION_RINGTONE | 6 | Notification or ringtone usage. |
| Name | Default Value| Description |
| ---------------------------------- | ------ | ---------- |
| STREAM_USAGE_UNKNOWN | 0 | Unknown usage.|
| STREAM_USAGE_MEDIA | 1 | Used for media. |
| STREAM_USAGE_VOICE_COMMUNICATION | 2 | Used for voice communication.|
| STREAM_USAGE_NOTIFICATION_RINGTONE | 6 | Used for notification.|
## AudioState<sup>8+</sup> ## AudioState<sup>8+</sup>
Enumerates the audio states. Enumerates the audio states.
**System capability:** SystemCapability.Multimedia.Audio.Core **System capability**: SystemCapability.Multimedia.Audio.Core
| Name | Default Value | Description |
| :------------- | :------------ | :--------------------------- |
| STATE_INVALID | -1 | Invalid state. |
| STATE_NEW | 0 | Creating new instance state. |
| STATE_PREPARED | 1 | Prepared state. |
| STATE_RUNNING | 2 | Running state. |
| STATE_STOPPED | 3 | Stopped state. |
| STATE_RELEASED | 4 | Released state. |
| STATE_PAUSED | 5 | Paused state. |
| Name | Default Value| Description |
| -------------- | ------ | ---------------- |
| STATE_INVALID | -1 | Invalid state. |
| STATE_NEW | 0 | Creating instance state.|
| STATE_PREPARED | 1 | Prepared. |
| STATE_RUNNING | 2 | Running. |
| STATE_STOPPED | 3 | Stopped. |
| STATE_RELEASED | 4 | Released. |
| STATE_PAUSED | 5 | Paused. |
## AudioRendererRate<sup>8+</sup> ## AudioRendererRate<sup>8+</sup>
Enumerates the audio renderer rates. Enumerates the audio renderer rates.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
| Name | Default Value | Description | | Name | Default Value| Description |
| :----------------- | :------------ | :------------ | | ------------------ | ------ | ---------- |
| RENDER_RATE_NORMAL | 0 | Normal rate. | | RENDER_RATE_NORMAL | 0 | Normal rate.|
| RENDER_RATE_DOUBLE | 1 | Double rate. | | RENDER_RATE_DOUBLE | 1 | Double rate. |
| RENDER_RATE_HALF | 2 | Half rate. | | RENDER_RATE_HALF | 2 | Half rate. |
## InterruptType ## InterruptType
Enumerates the interrupt types. Enumerates the audio interruption types.
**System capability**: SystemCapability.Multimedia.Audio.Renderer
| Name | Default Value| Description |
| -------------------- | ------ | ---------------------- |
| INTERRUPT_TYPE_BEGIN | 1 | Audio interruption started.|
| INTERRUPT_TYPE_END | 2 | Audio interruption ended.|
## InterruptForceType<sup>9+</sup>
**System capability:** SystemCapability.Multimedia.Audio.Renderer Enumerates the types of force that causes audio interruption.
| Name | Default Value | Description | **System capability**: SystemCapability.Multimedia.Audio.Renderer
| :------------------- | :------------ | :----------------------------------- |
| INTERRUPT_TYPE_BEGIN | 1 | Audio playback interruption started. | | Name | Default Value| Description |
| INTERRUPT_TYPE_END | 2 | Audio playback interruption ended. | | --------------- | ------ | ------------------------------------ |
| INTERRUPT_FORCE | 0 | Forced action taken by the system. |
| INTERRUPT_SHARE | 1 | The application can choose to take action or ignore.|
## InterruptHint ## InterruptHint
Enumerates the interrupt hints. Enumerates the hints provided along with audio interruption.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
| Name | Default Value | Description | | Name | Default Value| Description |
| :--------------------------------- | :------------ | :--------------------------- | | ---------------------------------- | ------ | -------------------------------------------- |
| INTERRUPT_HINT_NONE<sup>8+</sup> | 0 | None. | | INTERRUPT_HINT_NONE<sup>8+</sup> | 0 | None. |
| INTERRUPT_HINT_RESUME | 1 | Resume the playback. | | INTERRUPT_HINT_RESUME | 1 | Resume the playback. |
| INTERRUPT_HINT_PAUSE | 2 | Paused/Pause the playback. | | INTERRUPT_HINT_PAUSE | 2 | Paused/Pause the playback. |
| INTERRUPT_HINT_STOP | 3 | Stopped/Stop the playback. | | INTERRUPT_HINT_STOP | 3 | Stopped/Stop the playback. |
| INTERRUPT_HINT_DUCK | 4 | Ducked the playback. | | INTERRUPT_HINT_DUCK | 4 | Ducked the playback. (In ducking, the audio volume is reduced, but not silenced.)|
| INTERRUPT_HINT_UNDUCK<sup>8+</sup> | 5 | Unducked the playback. | | INTERRUPT_HINT_UNDUCK<sup>8+</sup> | 5 | Unducked the playback. |
## InterruptActionType ## InterruptActionType
Enumerates the interrupt event return types. Enumerates the returned event types for audio interruption events.
This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR. This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
| Name | Default Value | Description | | Name | Default Value| Description |
| :------------- | :------------ | :---------------------------------------- | | -------------- | ------ | ------------------ |
| TYPE_ACTIVATED | 0 | Audio interrupt activated. | | TYPE_ACTIVATED | 0 | Focus gain event.|
| TYPE_INTERRUPT | 1 | Audio interrupted. | | TYPE_INTERRUPT | 1 | Audio interruption event.|
## AudioStreamInfo<sup>8+</sup> ## AudioStreamInfo<sup>8+</sup>
Describes audio stream information. Describes audio stream information.
**System capability:** SystemCapability.Multimedia.Audio.Core **System capability**: SystemCapability.Multimedia.Audio.Core
**Parameters:**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------------ | :---------------------------------------- | :-------- | :-------------------- | | ------------ | ---------------------------------------- | ---- | ------------------ |
| samplingRate | [AudioSamplingRate](#audiosamplingrate8) | Yes | Sampling rate. | | samplingRate | [AudioSamplingRate](#audiosamplingrate8) | Yes | Audio sampling rate.|
| channels | [AudioChannel](#audiochannel8) | Yes | Audio channels. | | channels | [AudioChannel](#audiochannel8) | Yes | Number of audio channels.|
| sampleFormat | [AudioSampleFormat](#audiosampleformat8) | Yes | Audio sample format. | | sampleFormat | [AudioSampleFormat](#audiosampleformat8) | Yes | Audio sample format. |
| encodingType | [AudioEncodingType](#audioencodingtype8) | Yes | Audio encoding type. | | encodingType | [AudioEncodingType](#audioencodingtype8) | Yes | Audio encoding type. |
## AudioRendererInfo<sup>8+</sup> ## AudioRendererInfo<sup>8+</sup>
Describes audio renderer information. Describes audio renderer information.
**System capability:** SystemCapability.Multimedia.Audio.Core **System capability**: SystemCapability.Multimedia.Audio.Core
**Parameters:** | Name | Type | Mandatory| Description |
| ------------- | --------------------------- | ---- | ---------------- |
| Name | Type | Mandatory | Description | | content | [ContentType](#contenttype) | Yes | Audio content type. |
| :------------ | :-------------------------- | :-------- | :-------------------- | | usage | [StreamUsage](#streamusage) | Yes | Audio stream usage.|
| contentType | [ContentType](#contenttype) | Yes | Content type. | | rendererFlags | number | Yes | Audio renderer flags.|
| usage | [StreamUsage](#streamusage) | Yes | Stream usage. |
| rendererFlags | number | Yes | Audio renderer flags. |
## AudioRendererOptions<sup>8+</sup> ## AudioRendererOptions<sup>8+</sup>
Describes audio renderer configuration options. Describes audio renderer configurations.
**System capability:** SystemCapability.Multimedia.Audio.Renderer
**Parameters:**
| Name | Type | Mandatory | Description |
| :------------ | :-----------------------------------------| :-------- | :-------------------- |
| streamInfo | [AudioStreamInfo](#audiostreaminfo8) | Yes | Stream information. |
| rendererInfo | [AudioRendererInfo](#audiorendererinfo8) | Yes | Renderer information. |
## AudioCapturerInfo<sup>8+</sup><a name="audiocapturerinfo"></a>
Describes audio capturer information.
**System capability:** SystemCapability.Multimedia.Audio.Core
**Parameters:** **System capability**: SystemCapability.Multimedia.Audio.Renderer
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :---------------| :------------------------- | :-------- | :-------------------- | | ------------ | ---------------------------------------- | ---- | ---------------- |
| source | [SourceType](#sourcetype) | Yes | Audio source type. | | streamInfo | [AudioStreamInfo](#audiostreaminfo8) | Yes | Audio stream information.|
| capturerFlags | number | Yes | Audio capturer flags. | | rendererInfo | [AudioRendererInfo](#audiorendererinfo8) | Yes | Audio renderer information.|
## AudioCapturerOptions<sup>8+</sup> ## InterruptEvent<sup>9+</sup>
Describes audio capturer configuration options.
**System capability:** SystemCapability.Multimedia.Audio.Capturer Describes the interruption event received by the application when playback is interrupted.
**Parameters:** **System capability**: SystemCapability.Multimedia.Audio.Renderer
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------------ | :-----------------------------------------| :-------- | :-------------------- | | --------- | ------------------------------------------ | ---- | ------------------------------------ |
| streamInfo | [AudioStreamInfo](#audiostreaminfo8) | Yes | Stream information. | | eventType | [InterruptType](#interrupttype) | Yes | Whether the interruption has started or ended. |
| capturerInfo | [AudioCapturerInfo](#audiocapturerinfo8) | Yes | Capturer information. | | forceType | [InterruptForceType](#interruptforcetype9) | Yes | Whether the interruption is taken by the system or to be taken by the application.|
| hintType | [InterruptHint](#interrupthint) | Yes | Hint provided along the interruption. |
## AudioInterrupt ## AudioInterrupt
The parameters passed in by the audio listener event. Describes input parameters of audio interruption events.
This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR. This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| --------------- | --------------------------- | ---- | ------------------------------------------------------------ | | --------------- | --------------------------- | ---- | ------------------------------------------------------------ |
| streamUsage | [StreamUsage](#streamusage) | Yes | Audio stream usage type. | | streamUsage | [StreamUsage](#streamusage) | Yes | Audio stream usage. |
| contentType | [ContentType](#contenttype) | Yes | Audio interrupt media type. | | contentType | [ContentType](#contenttype) | Yes | Audio content type. |
| pauseWhenDucked | boolean | Yes | Whether audio playback can be paused when audio is interrupted (true means audio playback can be paused during audio interruptions and false means the opposite). | | pauseWhenDucked | boolean | Yes | Whether audio playback can be paused during audio interruption. The value **true** means that audio playback can be paused during audio interruption, and **false** means the opposite.|
## InterruptAction ## InterruptAction
Callback method for the audio interrupt or audio interrupt activated event. Describes the callback invoked for audio interruption or focus gain events.
This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR. This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ------------------------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ | | ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ |
| actionType | [InterruptActionType](#interruptactiontype) | Yes | Event return type. TYPE_ACTIVATED is the audio interrupt activated event, and TYPE_INTERRUPT is the audio interrupt event. | | actionType | [InterruptActionType](#interruptactiontype) | Yes | Returned event type. The value **TYPE_ACTIVATED** means the focus gain event, and **TYPE_INTERRUPT** means the audio interruption event.|
| type | [InterruptType](#interrupttype) | No | Interrupt event type. | | type | [InterruptType](#interrupttype) | No | Type of the audio interruption event. |
| hint | [InterruptHint](#interrupthint) | No | Interrupt event prompts. | | hint | [InterruptHint](interrupthint) | No | Hint provided along with the audio interruption event. |
| activated | boolean | No | Acquire/release focus. true indicates that the focus acquisition/release is successful, and false indicates that the focus acquisition/release fails. | | activated | boolean | No | Whether the focus is gained or released. The value **true** means that the focus is gained or released, and **false** means that the focus fails to be gained or released.|
## VolumeEvent<sup>8+</sup> ## VolumeEvent<sup>8+</sup>
Describes the volume event received by the app when the volume is changed.
This is a system API and cannot be called by third-party applications. Describes the event received by the application when the volume is changed.
**System capability:** SystemCapability.Multimedia.Audio.Volume This is a system API and cannot be called by third-party applications.
**Parameters:** **System capability**: SystemCapability.Multimedia.Audio.Volume
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :--------- | :---------------------------------- | :-------- | :--------------------------------------- | | ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Volume type of the current stream. | | volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
| volume | number | Yes | Volume level. | | volume | number | Yes | Volume level. The value range can be obtained by calling **getMinVolume** and **getMaxVolume**.|
| updateUi | boolean | Yes | Whether to show the volume change in UI. | | updateUi | boolean | Yes | Whether to show the volume change in UI. |
## DeviceChangeAction ## DeviceChangeAction
Describes the device change type and device information. Describes the device connection status and device information.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description |
| :------------------ | :------------------------------------------------ | :-------- | :------------------ |
| type | [DeviceChangeType](#devicechangetype) | Yes | Device change type. |
| deviceDescriptors | [AudioDeviceDescriptors](#audiodevicedescriptors) | Yes | Device information. |
| Name | Type | Mandatory| Description |
| :---------------- | :------------------------------------------------ | :--- | :----------------- |
| type | [DeviceChangeType](#DeviceChangeType) | Yes | Device connection status.|
| deviceDescriptors | [AudioDeviceDescriptors](#AudioDeviceDescriptors) | Yes | Device information. |
## DeviceChangeType ## DeviceChangeType
Enumerates device change types. Enumerates the device connection statuses.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
| Name | Default Value | Description | | Name | Default Value| Description |
| :--------------------- | :------------ | :-------------------- | | :--------- | :----- | :------------- |
| CONNECT | 0 | Device connection. | | CONNECT | 0 | Connected. |
| DISCONNECT | 1 | Device disconnection. | | DISCONNECT | 1 | Disconnected.|
## SourceType<sup>8+</sup><a name="sourcetype"></a> ## AudioCapturerOptions<sup>8+</sup>
Describes audio capturer configurations.
**System capability**: SystemCapability.Multimedia.Audio.Capturer
| Name | Type | Mandatory| Description |
| ------------ | --------------------------------------- | ---- | ---------------- |
| streamInfo | [AudioStreamInfo](#audiostreaminfo8) | Yes | Audio stream information.|
| capturerInfo | [AudioCapturerInfo](#audiocapturerinfo) | Yes | Audio capturer information.|
## AudioCapturerInfo<sup>8+</sup><a name="audiocapturerinfo"></a>
Describes audio capturer information.
**System capability**: SystemCapability.Multimedia.Audio.Core
Enumerates source types. | Name | Type | Mandatory| Description |
| :------------ | :------------------------ | :--- | :--------------- |
| source | [SourceType](#sourcetype) | Yes | Audio source type. |
| capturerFlags | number | Yes | Audio capturer flags.|
**System capability:** SystemCapability.Multimedia.Audio.Core ## SourceType<sup>8+</sup><a name="sourcetype"></a>
Enumerates the audio source types.
| Name | Default Value | Description | **System capability**: SystemCapability.Multimedia.Audio.Core
| :----------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------ | :------------------------------- |
| SOURCE_TYPE_INVALID | -1 | Invalid source type. |
| SOURCE_TYPE_MIC | 0 | Mic source type. |
| SOURCE_TYPE_VOICE_COMMUNICATION(This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR) | 7 | Voice communication source type. |
| Name | Default Value| Description |
| :------------------------------ | :----- | :----------------------------------------------------------- |
| SOURCE_TYPE_INVALID | -1 | Invalid audio source. |
| SOURCE_TYPE_MIC | 0 | Mic source. |
| SOURCE_TYPE_VOICE_COMMUNICATION | 7 | Voice communication source.<br>This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.|
## AudioScene<sup>8+</sup><a name="audioscene"></a> ## AudioScene<sup>8+</sup><a name="audioscene"></a>
Enumerates audio scenes. Enumerates the audio scenes.
**System capability:** SystemCapability.Multimedia.Audio.Communication **System capability**: SystemCapability.Multimedia.Audio.Communication
| Name | Default Value | Description | | Name | Default Value| Description |
| :------------------------------------------------------------------------------------ | :------------ | :---------------------- | | :--------------------- | :----- | :-------------------------------------------- |
| AUDIO_SCENE_DEFAULT | 0 | Default audio scene. | | AUDIO_SCENE_DEFAULT | 0 | Default audio scene. |
| AUDIO_SCENE_RINGING(system API, not supported by third-party applications) | 1 | Ringing audio scene. | | AUDIO_SCENE_RINGING | 1 | Ringing audio scene.<br>This is a system API and cannot be called by third-party applications.|
| AUDIO_SCENE_PHONE_CALL(system API, not supported by third-party applications) | 2 | Phone call audio scene. | | AUDIO_SCENE_PHONE_CALL | 2 | Phone call audio scene.<br>This is a system API and cannot be called by third-party applications.|
| AUDIO_SCENE_VOICE_CHAT | 3 | Voice chat audio scene. | | AUDIO_SCENE_VOICE_CHAT | 3 | Voice chat audio scene. |
## AudioManager ## AudioManager
Implements audio volume and audio device management. Before calling the interface of AudioManager, you need to create an instance through [getAudioManager](#audiogetaudiomanager). Implements audio volume and audio device management. Before calling any API in **AudioManager**, you must use [getAudioManager](#audiogetaudiomanager) to create an **AudioManager** instance.
### setVolume ### setVolume
setVolume\(volumeType: AudioVolumeType, volume: number, callback: AsyncCallback<void\>\): void setVolume(volumeType: AudioVolumeType, volume: number, callback: AsyncCallback&lt;void&gt;): void
Sets the volume for a stream. This API uses an asynchronous callback to return the result. Sets the volume for a stream. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------- | --------- | ---------------------------------------------------------------------------------------- | | ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Volume stream type. | | volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
| volume | number | Yes | Volume to set. The value range can be obtained by calling getMinVolume and getMaxVolume. | | volume | number | Yes | Volume to set. The value range can be obtained by calling **getMinVolume** and **getMaxVolume**.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. |
**Example:** **Example**
``` ```
audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10, (err) => { audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10, (err) => {
...@@ -656,28 +669,29 @@ audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10, (err) => { ...@@ -656,28 +669,29 @@ audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10, (err) => {
console.log('Callback invoked to indicate a successful volume setting.'); console.log('Callback invoked to indicate a successful volume setting.');
}); });
``` ```
### setVolume ### setVolume
setVolume\(volumeType: AudioVolumeType, volume: number\): Promise<void\> setVolume(volumeType: AudioVolumeType, volume: number): Promise&lt;void&gt;
Sets the volume for a stream. This API uses a promise to return the result. Sets the volume for a stream. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------- | --------- | ---------------------------------------------------------------------------------------- | | ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Volume stream type. | | volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
| volume | number | Yes | Volume to set. The value range can be obtained by calling getMinVolume and getMaxVolume. | | volume | number | Yes | Volume to set. The value range can be obtained by calling **getMinVolume** and **getMaxVolume**.|
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ----------------------------------- | | ------------------- | ----------------------------- |
| Promise<void> | Promise used to return the result. | | Promise&lt;void&gt; | Promise used to return the result.|
**Example:** **Example**
``` ```
audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(() => { audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(() => {
...@@ -687,20 +701,20 @@ audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(() => { ...@@ -687,20 +701,20 @@ audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(() => {
### getVolume ### getVolume
getVolume\(volumeType: AudioVolumeType, callback: AsyncCallback<number\>\): void getVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
Obtains the volume of a stream. This API uses an asynchronous callback to return the query result. Obtains the volume of a stream. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------- | --------- | ------------------------------------ | | ---------- | ----------------------------------- | ---- | ------------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | | volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
| callback | AsyncCallback<number> | Yes | Callback used to return the volume. | | callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the volume.|
**Example:** **Example**
``` ```
audioManager.getVolume(audio.AudioVolumeType.MEDIA, (err, value) => { audioManager.getVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
...@@ -712,28 +726,27 @@ audioManager.getVolume(audio.AudioVolumeType.MEDIA, (err, value) => { ...@@ -712,28 +726,27 @@ audioManager.getVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
}); });
``` ```
### getVolume ### getVolume
getVolume\(volumeType: AudioVolumeType\): Promise<number\> getVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
Obtains the volume of a stream. This API uses a promise to return the query result. Obtains the volume of a stream. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------- | --------- | ------------------------------------ | | ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | | volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type.|
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ----------------------------------- | | --------------------- | ------------------------- |
| Promise<number> | Promise used to return the result. | | Promise&lt;number&gt; | Promise used to return the volume.|
**Example:** **Example**
``` ```
audioManager.getVolume(audio.AudioVolumeType.MEDIA).then((value) => { audioManager.getVolume(audio.AudioVolumeType.MEDIA).then((value) => {
...@@ -743,20 +756,20 @@ audioManager.getVolume(audio.AudioVolumeType.MEDIA).then((value) => { ...@@ -743,20 +756,20 @@ audioManager.getVolume(audio.AudioVolumeType.MEDIA).then((value) => {
### getMinVolume ### getMinVolume
getMinVolume\(volumeType: AudioVolumeType, callback: AsyncCallback<number\>\): void getMinVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
Obtains the minimum volume allowed for a stream. This API uses an asynchronous callback to return the query result. Obtains the minimum volume allowed for a stream. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------- | --------- | ------------------------------------ | | ---------- | ----------------------------------- | ---- | ------------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | | volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
| callback | AsyncCallback<number> | Yes | Callback used to return the volume. | | callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the minimum volume.|
**Example:** **Example**
``` ```
audioManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err, value) => { audioManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
...@@ -768,28 +781,27 @@ audioManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err, value) => { ...@@ -768,28 +781,27 @@ audioManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
}); });
``` ```
### getMinVolume ### getMinVolume
getMinVolume\(volumeType: AudioVolumeType\): Promise<number\><a name="section41556389511"></a> getMinVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
Obtains the minimum volume allowed for a stream. This API uses a promise to return the query result. Obtains the minimum volume allowed for a stream. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------- | --------- | ------------------------------------ | | ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | | volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type.|
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ----------------------------------- | | --------------------- | ------------------------- |
| Promise<number> | Promise used to return the result. | | Promise&lt;number&gt; | Promise used to return the minimum volume.|
**Example:** **Example**
``` ```
audioManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value) => { audioManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value) => {
...@@ -799,20 +811,20 @@ audioManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value) => { ...@@ -799,20 +811,20 @@ audioManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value) => {
### getMaxVolume ### getMaxVolume
getMaxVolume\(volumeType: AudioVolumeType, callback: AsyncCallback<number\>\): void getMaxVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
Obtains the maximum volume allowed for a stream. This API uses an asynchronous callback to return the query result. Obtains the maximum volume allowed for a stream. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------- | --------- | ------------------------------------ | | ---------- | ----------------------------------- | ---- | ---------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | | volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
| callback | AsyncCallback<number> | Yes | Callback used to return the volume. | | callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the maximum volume.|
**Example:** **Example**
``` ```
audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA, (err, value) => { audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
...@@ -824,28 +836,27 @@ audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA, (err, value) => { ...@@ -824,28 +836,27 @@ audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
}); });
``` ```
### getMaxVolume ### getMaxVolume
getMaxVolume\(volumeType: AudioVolumeType\): Promise<number\> getMaxVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
Obtains the maximum volume allowed for a stream. This API uses a promise to return the query result. Obtains the maximum volume allowed for a stream. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------- | --------- | ------------------------------------ | | ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | | volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type.|
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ----------------------------------- | | --------------------- | ----------------------------- |
| Promise<number> | Promise used to return the result. | | Promise&lt;number&gt; | Promise used to return the maximum volume.|
**Example:** **Example**
``` ```
audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data) => { audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data) => {
...@@ -855,21 +866,21 @@ audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data) => { ...@@ -855,21 +866,21 @@ audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data) => {
### mute ### mute
mute\(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback<void\>\): void mute(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback&lt;void&gt;): void
Mutes a stream. This API uses an asynchronous callback to return the result. Mutes or unmutes a stream. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------- | --------- | ------------------------------------------------------------------------------------------ | | ---------- | ----------------------------------- | ---- | ------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | | volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
| mute | boolean | Yes | Mute status to set. The value true means to mute the stream, and false means the opposite. | | mute | boolean | Yes | Mute status to set. The value **true** means to mute the stream, and **false** means the opposite.|
| callback | AsyncCallback<number> | Yes | Callback used to return the volume. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. |
**Example:** **Example**
``` ```
audioManager.mute(audio.AudioVolumeType.MEDIA, true, (err) => { audioManager.mute(audio.AudioVolumeType.MEDIA, true, (err) => {
...@@ -881,29 +892,29 @@ audioManager.mute(audio.AudioVolumeType.MEDIA, true, (err) => { ...@@ -881,29 +892,29 @@ audioManager.mute(audio.AudioVolumeType.MEDIA, true, (err) => {
}); });
``` ```
### mute ### mute
mute\(volumeType: AudioVolumeType, mute: boolean\): Promise<void\> mute(volumeType: AudioVolumeType, mute: boolean): Promise&lt;void&gt;
Mutes or unmutes a stream. This API uses a promise to return the result.
Mutes a stream. This API uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Audio.Volume
**System capability:** SystemCapability.Multimedia.Audio.Volume **Parameters**
**Parameters:** | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------- | ---- | ------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
| mute | boolean | Yes | Mute status to set. The value **true** means to mute the stream, and **false** means the opposite.|
| Name | Type | Mandatory | Description | **Return value**
| ---------- | ----------------------------------- | --------- | ------------------------------------------------------------------------------------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
| mute | boolean | Yes | Mute status to set. The value true means to mute the stream, and false means the opposite. |
**Return value:** | Type | Description |
| ------------------- | ----------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
| Type | Description | **Example**
| ------------------- | ----------------------------------- |
| Promise<void> | Promise used to return the result. |
**Example:**
``` ```
audioManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => { audioManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => {
...@@ -914,20 +925,20 @@ audioManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => { ...@@ -914,20 +925,20 @@ audioManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => {
### isMute ### isMute
isMute\(volumeType: AudioVolumeType, callback: AsyncCallback<boolean\>\): void isMute(volumeType: AudioVolumeType, callback: AsyncCallback&lt;boolean&gt;): void
Checks whether a stream is muted. This API uses an asynchronous callback to return the query result. Checks whether a stream is muted. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------- | | ---------- | ----------------------------------- | ---- | ----------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | | volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
| callback | AsyncCallback<boolean> | Yes | Callback used to return the mute status of the stream. The value true means that the stream is muted, and false means the opposite.| | callback | AsyncCallback&lt;boolean&gt; | Yes | Callback used to return the mute status of the stream. The value **true** means that the stream is muted, and **false** means the opposite.|
**Example:** **Example**
``` ```
audioManager.isMute(audio.AudioVolumeType.MEDIA, (err, value) => { audioManager.isMute(audio.AudioVolumeType.MEDIA, (err, value) => {
...@@ -942,25 +953,25 @@ audioManager.isMute(audio.AudioVolumeType.MEDIA, (err, value) => { ...@@ -942,25 +953,25 @@ audioManager.isMute(audio.AudioVolumeType.MEDIA, (err, value) => {
### isMute ### isMute
isMute\(volumeType: AudioVolumeType\): Promise<boolean\> isMute(volumeType: AudioVolumeType): Promise&lt;boolean&gt;
Checks whether a stream is muted. This API uses a promise to return the result. Checks whether a stream is muted. This method uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------- | --------- | ------------------- | | ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | | volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type.|
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ----------------------------------------------------------------------------------------------------------------------------------- | | ---------------------- | ------------------------------------------------------ |
| Promise<boolean> | Promise used to return the mute status of the stream. The value true means that the stream is muted, and false means the opposite. | | Promise&lt;boolean&gt; | Promise used to return the mute status of the stream. The value **true** means that the stream is muted, and **false** means the opposite.|
**Example:** **Example**
``` ```
audioManager.isMute(audio.AudioVolumeType.MEDIA).then((value) => { audioManager.isMute(audio.AudioVolumeType.MEDIA).then((value) => {
...@@ -970,20 +981,20 @@ audioManager.isMute(audio.AudioVolumeType.MEDIA).then((value) => { ...@@ -970,20 +981,20 @@ audioManager.isMute(audio.AudioVolumeType.MEDIA).then((value) => {
### isActive ### isActive
isActive\(volumeType: AudioVolumeType, callback: AsyncCallback<boolean\>\) isActive(volumeType: AudioVolumeType, callback: AsyncCallback&lt;boolean&gt;): void
Checks whether a stream is active. This API uses an asynchronous callback to return the query result. Checks whether a stream is active. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------- | | ---------- | ----------------------------------- | ---- | ------------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | | volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
| callback | AsyncCallback<boolean> | Yes | Callback used to return the active status of the stream. The value true means that the stream is active, and false means the opposite.| | callback | AsyncCallback&lt;boolean&gt; | Yes | Callback used to return the active status of the stream. The value **true** means that the stream is active, and **false** means the opposite.|
**Example:** **Example**
``` ```
audioManager.isActive(audio.AudioVolumeType.MEDIA, (err, value) => { audioManager.isActive(audio.AudioVolumeType.MEDIA, (err, value) => {
...@@ -995,28 +1006,27 @@ audioManager.isActive(audio.AudioVolumeType.MEDIA, (err, value) => { ...@@ -995,28 +1006,27 @@ audioManager.isActive(audio.AudioVolumeType.MEDIA, (err, value) => {
}); });
``` ```
### isActive ### isActive
isActive\(volumeType: AudioVolumeType\): Promise<boolean\> isActive(volumeType: AudioVolumeType): Promise&lt;boolean&gt;
Checks whether a stream is active. This API uses a promise to return the query result. Checks whether a stream is active. This method uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------- | --------- | ------------------ | | ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | | volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type.|
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- | | ---------------------- | -------------------------------------------------------- |
| Promise<boolean> | Promise used to return the active status of the stream. The value true means that the stream is active, and false means the opposite. | | Promise&lt;boolean&gt; | Promise used to return the active status of the stream. The value **true** means that the stream is active, and **false** means the opposite.|
**Example:** **Example**
``` ```
audioManager.isActive(audio.AudioVolumeType.MEDIA).then((value) => { audioManager.isActive(audio.AudioVolumeType.MEDIA).then((value) => {
...@@ -1024,23 +1034,22 @@ audioManager.isActive(audio.AudioVolumeType.MEDIA).then((value) => { ...@@ -1024,23 +1034,22 @@ audioManager.isActive(audio.AudioVolumeType.MEDIA).then((value) => {
}); });
``` ```
### setRingerMode ### setRingerMode
setRingerMode\(mode: AudioRingMode, callback: AsyncCallback<void\>\): void setRingerMode(mode: AudioRingMode, callback: AsyncCallback&lt;void&gt;): void
Sets the ringer mode. This API uses an asynchronous callback to return the result. Sets the ringer mode. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Communication **System capability**: SystemCapability.Multimedia.Audio.Communication
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------- | --------- | ----------------------------------- | | -------- | ------------------------------- | ---- | ------------------------ |
| mode | [AudioRingMode](#audioringmode) | Yes | Ringer mode. | | mode | [AudioRingMode](#audioringmode) | Yes | Ringer mode. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result.|
**Example:** **Example**
``` ```
audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL, (err) => { audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL, (err) => {
...@@ -1052,28 +1061,27 @@ audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL, (err) => { ...@@ -1052,28 +1061,27 @@ audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL, (err) => {
}); });
``` ```
### setRingerMode ### setRingerMode
setRingerMode\(mode: AudioRingMode\): Promise<void\> setRingerMode(mode: AudioRingMode): Promise&lt;void&gt;
Sets the ringer mode. This API uses a promise to return the result. Sets the ringer mode. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Communication **System capability**: SystemCapability.Multimedia.Audio.Communication
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| ---------- | ----------------------------------- | --------- | ----------------------------------- | | ------ | ------------------------------- | ---- | -------------- |
| mode | [AudioRingMode](#audioringmode) | Yes | Ringer mode. | | mode | [AudioRingMode](#audioringmode) | Yes | Ringer mode.|
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ----------------------------------- | | ------------------- | ------------------------------- |
| Promise<void> | Promise used to return the result. | | Promise&lt;void&gt; | Promise used to return the result.|
**Example:** **Example**
``` ```
audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() => { audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() => {
...@@ -1084,19 +1092,19 @@ audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() => { ...@@ -1084,19 +1092,19 @@ audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() => {
### getRingerMode ### getRingerMode
getRingerMode\(callback: AsyncCallback<AudioRingMode\>\): void getRingerMode(callback: AsyncCallback&lt;AudioRingMode&gt;): void
Obtains the ringer mode. This API uses an asynchronous callback to return the query result. Obtains the ringer mode. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Communication **System capability**: SystemCapability.Multimedia.Audio.Communication
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------------------- | --------- | ---------------------------------------- | | -------- | ---------------------------------------------------- | ---- | ------------------------ |
| callback | AsyncCallback<[AudioRingMode](#audioringmode)> | Yes | Callback used to return the ringer mode. | | callback | AsyncCallback&lt;[AudioRingMode](#audioringmode)&gt; | Yes | Callback used to return the ringer mode.|
**Example:** **Example**
``` ```
audioManager.getRingerMode((err, value) => { audioManager.getRingerMode((err, value) => {
...@@ -1111,19 +1119,19 @@ audioManager.getRingerMode((err, value) => { ...@@ -1111,19 +1119,19 @@ audioManager.getRingerMode((err, value) => {
### getRingerMode ### getRingerMode
getRingerMode\(\): Promise<AudioRingMode\> getRingerMode(): Promise&lt;AudioRingMode&gt;
Obtains the ringer mode. This API uses a promise to return the query result. Obtains the ringer mode. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Communication **System capability**: SystemCapability.Multimedia.Audio.Communication
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ---------------------------------------------- | --------------------------------------- | | ---------------------------------------------- | ------------------------------- |
| Promise<[AudioRingMode](#audioringmode)> | Promise used to return the ringer mode. | | Promise&lt;[AudioRingMode](#audioringmode)&gt; | Promise used to return the ringer mode.|
**Example:** **Example**
``` ```
audioManager.getRingerMode().then((value) => { audioManager.getRingerMode().then((value) => {
...@@ -1131,24 +1139,23 @@ audioManager.getRingerMode().then((value) => { ...@@ -1131,24 +1139,23 @@ audioManager.getRingerMode().then((value) => {
}); });
``` ```
### setAudioParameter ### setAudioParameter
setAudioParameter\(key: string, value: string, callback: AsyncCallback<void\>\): void setAudioParameter(key: string, value: string, callback: AsyncCallback&lt;void&gt;): void
Sets an audio parameter. This API uses an asynchronous callback to return the result. Sets an audio parameter. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Core **System capability**: SystemCapability.Multimedia.Audio.Core
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| --------- | ----------------------| --------- | ------------------------------------- | | -------- | ------------------------- | ---- | ------------------------ |
| key | string | Yes | Key of the audio parameter to set. | | key | string | Yes | Key of the audio parameter to set. |
| value | string | Yes | Value of the audio parameter to set. | | value | string | Yes | Value of the audio parameter to set. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result.|
**Example:** **Example**
``` ```
audioManager.setAudioParameter('PBits per sample', '8 bit', (err) => { audioManager.setAudioParameter('PBits per sample', '8 bit', (err) => {
...@@ -1160,29 +1167,28 @@ audioManager.setAudioParameter('PBits per sample', '8 bit', (err) => { ...@@ -1160,29 +1167,28 @@ audioManager.setAudioParameter('PBits per sample', '8 bit', (err) => {
}); });
``` ```
### setAudioParameter ### setAudioParameter
setAudioParameter\(key: string, value: string\): Promise<void\> setAudioParameter(key: string, value: string): Promise&lt;void&gt;
Sets an audio parameter. This API uses a promise to return the result. Sets an audio parameter. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Core **System capability**: SystemCapability.Multimedia.Audio.Core
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| --------- | ----------------------| --------- | ------------------------------------- | | ------ | ------ | ---- | ---------------------- |
| key | string | Yes | Key of the audio parameter to set. | | key | string | Yes | Key of the audio parameter to set.|
| value | string | Yes | Value of the audio parameter to set. | | value | string | Yes | Value of the audio parameter to set.|
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ----------------------------------- | | ------------------- | ------------------------------- |
| Promise<void> | Promise used to return the result. | | Promise&lt;void&gt; | Promise used to return the result.|
**Example:** **Example**
``` ```
audioManager.setAudioParameter('PBits per sample', '8 bit').then(() => { audioManager.setAudioParameter('PBits per sample', '8 bit').then(() => {
...@@ -1190,23 +1196,22 @@ audioManager.setAudioParameter('PBits per sample', '8 bit').then(() => { ...@@ -1190,23 +1196,22 @@ audioManager.setAudioParameter('PBits per sample', '8 bit').then(() => {
}); });
``` ```
### getAudioParameter ### getAudioParameter
getAudioParameter\(key: string, callback: AsyncCallback<string\>\) getAudioParameter(key: string, callback: AsyncCallback&lt;string&gt;): void
Obtains the value of an audio parameter. This API uses an asynchronous callback to return the query result. Obtains the value of an audio parameter. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Core **System capability**: SystemCapability.Multimedia.Audio.Core
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| --------- | ----------------------| --------- | ---------------------------------------------------------- | | -------- | --------------------------- | ---- | ---------------------------- |
| key | string | Yes | Key of the audio parameter whose value is to be obtained. | | key | string | Yes | Key of the audio parameter whose value is to be obtained. |
| callback | AsyncCallback<string> | Yes | Callback used to return the value of the audio parameter. | | callback | AsyncCallback&lt;string&gt; | Yes | Callback used to return the value of the audio parameter.|
**Example:** **Example**
``` ```
audioManager.getAudioParameter('PBits per sample', (err, value) => { audioManager.getAudioParameter('PBits per sample', (err, value) => {
...@@ -1218,28 +1223,27 @@ audioManager.getAudioParameter('PBits per sample', (err, value) => { ...@@ -1218,28 +1223,27 @@ audioManager.getAudioParameter('PBits per sample', (err, value) => {
}); });
``` ```
### getAudioParameter ### getAudioParameter
getAudioParameter\(key: string\): Promise<string\> getAudioParameter(key: string): Promise&lt;string&gt;
Obtains the value of an audio parameter. This API uses a promise to return the query result. Obtains the value of an audio parameter. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Core **System capability**: SystemCapability.Multimedia.Audio.Core
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| --------- | ----------------------| --------- | ----------------------------------------------------------- | | ------ | ------ | ---- | ---------------------- |
| key | string | Yes | Key of the audio parameter whose value is to be obtained. | | key | string | Yes | Key of the audio parameter whose value is to be obtained.|
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ----------------------------------- | | --------------------- | ----------------------------------- |
| Promise<string> | Promise used to return the value of the audio parameter. | | Promise&lt;string&gt; | Promise used to return the value of the audio parameter.|
**Example:** **Example**
``` ```
audioManager.getAudioParameter('PBits per sample').then((value) => { audioManager.getAudioParameter('PBits per sample').then((value) => {
...@@ -1247,24 +1251,22 @@ audioManager.getAudioParameter('PBits per sample').then((value) => { ...@@ -1247,24 +1251,22 @@ audioManager.getAudioParameter('PBits per sample').then((value) => {
}); });
``` ```
### getDevices ### getDevices
getDevices\(deviceFlag: DeviceFlag, callback: AsyncCallback<AudioDeviceDescriptors\>\): void getDevices(deviceFlag: DeviceFlag, callback: AsyncCallback&lt;AudioDeviceDescriptors&gt;): void
Obtains the audio devices with a specific flag. This API uses an asynchronous callback to return the query result.
**System capability:** SystemCapability.Multimedia.Audio.Device Obtains the audio devices with a specific flag. This API uses an asynchronous callback to return the result.
**Parameters:** **System capability**: SystemCapability.Multimedia.Audio.Device
| Name | Type | Mandatory | Description | **Parameters**
| --------- | ---------------------------------------------------------------- | --------- | ----------------------------------------- |
| deviceFlag | [DeviceFlag](#deviceflag) | Yes | Audio device flag. |
| callback | AsyncCallback<[AudioDeviceDescriptors](#audiodevicedescriptors)> | Yes | Callback used to return the device list. |
**Example:** | Name | Type | Mandatory| Description |
| ---------- | ------------------------------------------------------------ | ---- | -------------------- |
| deviceFlag | [DeviceFlag](#deviceflag) | Yes | Audio device flag. |
| callback | AsyncCallback&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | Yes | Callback used to return the device list.|
**Example**
``` ```
audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err, value) => { audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err, value) => {
if (err) { if (err) {
...@@ -1275,29 +1277,27 @@ audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err, value) => { ...@@ -1275,29 +1277,27 @@ audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err, value) => {
}); });
``` ```
### getDevices ### getDevices
getDevices\(deviceFlag: DeviceFlag\): Promise<AudioDeviceDescriptors\> getDevices(deviceFlag: DeviceFlag): Promise&lt;AudioDeviceDescriptors&gt;
Obtains the audio devices with a specific flag. This API uses a promise to return the query result. Obtains the audio devices with a specific flag. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| --------- | --------------------------- | --------- | ------------------- | | ---------- | ------------------------- | ---- | ---------------- |
| deviceFlag | [DeviceFlag](#deviceflag) | Yes | Audio device flag. | | deviceFlag | [DeviceFlag](#deviceflag) | Yes | Audio device flag.|
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ----------------------------------------------------------- | ---------------------------------------- | | ------------------------------------------------------------ | ------------------------- |
| Promise<[AudioDeviceDescriptors](#audiodevicedescriptors)> | Promise used to return the device list. | | Promise&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | Promise used to return the device list.|
**Example:** **Example**
``` ```
audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => { audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => {
...@@ -1307,21 +1307,21 @@ audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => { ...@@ -1307,21 +1307,21 @@ audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => {
### setDeviceActive ### setDeviceActive
setDeviceActive\(deviceType: DeviceType, active: boolean, callback: AsyncCallback<void\>\): void setDeviceActive(deviceType: ActiveDeviceType, active: boolean, callback: AsyncCallback&lt;void&gt;): void
Sets a device to the active state. This API uses an asynchronous callback to return the result. Sets a device to the active state. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| --------- | ---------------------------------------| --------- | ---------------------------------------------------------------------------------------------------------------- | | ---------- | ------------------------------------- | ---- | ------------------------ |
| deviceType | [ActiveDeviceType](#activedevicetype) | Yes | Audio device type. | | deviceType | [ActiveDeviceType](#activedevicetype) | Yes | Audio device type. |
| active | boolean | Yes | Active status to set. The value true means to set the device to the active status, and false means the opposite. | | active | boolean | Yes | Active state to set. The value **true** means to set the device to the active state, and **false** means the opposite. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result.|
**Example:** **Example**
``` ```
audioManager.setDeviceActive(audio.DeviceType.SPEAKER, true, (err) => { audioManager.setDeviceActive(audio.DeviceType.SPEAKER, true, (err) => {
...@@ -1333,31 +1333,29 @@ audioManager.setDeviceActive(audio.DeviceType.SPEAKER, true, (err) => { ...@@ -1333,31 +1333,29 @@ audioManager.setDeviceActive(audio.DeviceType.SPEAKER, true, (err) => {
}); });
``` ```
### setDeviceActive ### setDeviceActive
setDeviceActive\(deviceType: DeviceType, active: boolean\): Promise<void\> setDeviceActive(deviceType: ActiveDeviceType, active: boolean): Promise&lt;void&gt;
Sets a device to the active state. This API uses a promise to return the result. Sets a device to the active state. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| --------- | ---------------------------------------| --------- | ---------------------------------------------------------------------------------------------------------------- | | ---------- | ------------------------------------- | ---- | ------------------ |
| deviceType | [ActiveDeviceType](#activedevicetype) | Yes | Audio device type. | | deviceType | [ActiveDeviceType](#activedevicetype) | Yes | Audio device type.|
| active | boolean | Yes | Active status to set. The value true means to set the device to the active status, and false means the opposite. | | active | boolean | Yes | Active state to set. The value **true** means to set the device to the active state, and **false** means the opposite. |
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ----------------------------------- | | ------------------- | ------------------------------- |
| Promise<void> | Promise used to return the result. | | Promise&lt;void&gt; | Promise used to return the result.|
**Example**
**Example:**
``` ```
audioManager.setDeviceActive(audio.DeviceType.SPEAKER, true).then(() => { audioManager.setDeviceActive(audio.DeviceType.SPEAKER, true).then(() => {
...@@ -1365,23 +1363,22 @@ audioManager.setDeviceActive(audio.DeviceType.SPEAKER, true).then(() => { ...@@ -1365,23 +1363,22 @@ audioManager.setDeviceActive(audio.DeviceType.SPEAKER, true).then(() => {
}); });
``` ```
### isDeviceActive ### isDeviceActive
isDeviceActive\(deviceType: DeviceType, callback: AsyncCallback<boolean\>\): void isDeviceActive(deviceType: ActiveDeviceType, callback: AsyncCallback&lt;boolean&gt;): void
Checks whether a device is active. This API uses an asynchronous callback to return the query result. Checks whether a device is active. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| --------- | ---------------------------------------| --------- | -------------------------------------------------------- | | ---------- | ------------------------------------- | ---- | ------------------------ |
| deviceType | [ActiveDeviceType](#activedevicetype) | Yes | Audio device type. | | deviceType | [ActiveDeviceType](#activedevicetype) | Yes | Audio device type. |
| callback | AsyncCallback<boolean> | Yes | Callback used to return the active status of the device. | | callback | AsyncCallback&lt;boolean&gt; | Yes | Callback used to return the active state of the device.|
**Example:** **Example**
``` ```
audioManager.isDeviceActive(audio.DeviceType.SPEAKER, (err, value) => { audioManager.isDeviceActive(audio.DeviceType.SPEAKER, (err, value) => {
...@@ -1396,25 +1393,25 @@ audioManager.isDeviceActive(audio.DeviceType.SPEAKER, (err, value) => { ...@@ -1396,25 +1393,25 @@ audioManager.isDeviceActive(audio.DeviceType.SPEAKER, (err, value) => {
### isDeviceActive ### isDeviceActive
isDeviceActive\(deviceType: DeviceType\): Promise<boolean\> isDeviceActive(deviceType: ActiveDeviceType): Promise&lt;boolean&gt;
Checks whether a device is active. This API uses a promise to return the query result. Checks whether a device is active. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| --------- | ---------------------------------------| --------- | ----------------------------------------- | | ---------- | ------------------------------------- | ---- | ------------------ |
| deviceType | [ActiveDeviceType](#activedevicetype) | Yes | Audio device type. | | deviceType | [ActiveDeviceType](#activedevicetype) | Yes | Audio device type.|
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ----------------------------------- | | ---------------------- | ------------------------------- |
| Promise<boolean> | Promise used to return the active status of the device. | | Promise&lt;boolean&gt; | Promise used to return the active state of the device.|
**Example:** **Example**
``` ```
audioManager.isDeviceActive(audio.DeviceType.SPEAKER).then((value) => { audioManager.isDeviceActive(audio.DeviceType.SPEAKER).then((value) => {
...@@ -1422,23 +1419,22 @@ audioManager.isDeviceActive(audio.DeviceType.SPEAKER).then((value) => { ...@@ -1422,23 +1419,22 @@ audioManager.isDeviceActive(audio.DeviceType.SPEAKER).then((value) => {
}); });
``` ```
### setMicrophoneMute ### setMicrophoneMute
setMicrophoneMute\(mute: boolean, callback: AsyncCallback<void\>\): void setMicrophoneMute(mute: boolean, callback: AsyncCallback&lt;void&gt;): void
Mutes or unmutes the microphone. This API uses an asynchronous callback to return the result. Mutes or unmutes the microphone. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| --------- | -------------------- | --------- | ---------------------------------------------------------------------------------------------- | | -------- | ------------------------- | ---- | --------------------------------------------- |
| mute | boolean | Yes | Mute status to set. The value true means to mute the microphone, and false means the opposite. | | mute | boolean | Yes | Mute status to set. The value **true** means to mute the microphone, and **false** means the opposite.|
| callback | AsyncCallback<void> | Yes | Callback used to return the result. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. |
**Example:** **Example**
``` ```
audioManager.setMicrophoneMute(true, (err) => { audioManager.setMicrophoneMute(true, (err) => {
...@@ -1450,30 +1446,27 @@ audioManager.setMicrophoneMute(true, (err) => { ...@@ -1450,30 +1446,27 @@ audioManager.setMicrophoneMute(true, (err) => {
}); });
``` ```
### setMicrophoneMute ### setMicrophoneMute
setMicrophoneMute\(mute: boolean\): Promise<void\> setMicrophoneMute(mute: boolean): Promise&lt;void&gt;
Mutes or unmutes the microphone. This API uses a promise to return the result. Mutes or unmutes the microphone. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
**Parameters:**
| Name | Type | Mandatory | Description | **Parameters**
| --------- | -------------------- | --------- | ---------------------------------------------------------------------------------------------- |
| mute | boolean | Yes | Mute status to set. The value true means to mute the microphone, and false means the opposite. |
**Return value:** | Name| Type | Mandatory| Description |
| ------ | ------- | ---- | --------------------------------------------- |
| mute | boolean | Yes | Mute status to set. The value **true** means to mute the microphone, and **false** means the opposite.|
| Type | Description | **Return value**
| ------------------- | ----------------------------------- |
| Promise<void> | Promise used to return the result. |
</table> | Type | Description |
| ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
**Example:** **Example**
``` ```
audioManager.setMicrophoneMute(true).then(() => { audioManager.setMicrophoneMute(true).then(() => {
...@@ -1481,25 +1474,23 @@ audioManager.setMicrophoneMute(true).then(() => { ...@@ -1481,25 +1474,23 @@ audioManager.setMicrophoneMute(true).then(() => {
}); });
``` ```
### isMicrophoneMute ### isMicrophoneMute
isMicrophoneMute\(callback: AsyncCallback<boolean\>\): void isMicrophoneMute(callback: AsyncCallback&lt;boolean&gt;): void
Checks whether the microphone is muted. This API uses an asynchronous callback to return the query result. Checks whether the microphone is muted. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| --------- | -------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------- | | -------- | ---------------------------- | ---- | ------------------------------------------------------- |
| callback | AsyncCallback<boolean> | Yes | Callback used to return the mute status of the microphone. The value true means that the microphone is muted, and false means the opposite. | | callback | AsyncCallback&lt;boolean&gt; | Yes | Callback used to return the mute status of the microphone. The value **true** means that the microphone is muted, and **false** means the opposite.|
**Example:** **Example**
``` ```
var audioManager = audio.getAudioManager();
audioManager.isMicrophoneMute((err, value) => { audioManager.isMicrophoneMute((err, value) => {
if (err) { if (err) {
console.error('Failed to obtain the mute status of the microphone. ${err.message}'); console.error('Failed to obtain the mute status of the microphone. ${err.message}');
...@@ -1509,25 +1500,24 @@ audioManager.isMicrophoneMute((err, value) => { ...@@ -1509,25 +1500,24 @@ audioManager.isMicrophoneMute((err, value) => {
}); });
``` ```
### isMicrophoneMute ### isMicrophoneMute
isMicrophoneMute\(\): Promise<boolean\> isMicrophoneMute(): Promise&lt;boolean&gt;
Checks whether the microphone is muted. This API uses a promise to return the result.
Checks whether the microphone is muted. This API uses a promise to return the query result. **System capability**: SystemCapability.Multimedia.Audio.Device
**System capability:** SystemCapability.Multimedia.Audio.Device **Return value**
**Return value:** | Type | Description |
| ---------------------- | ------------------------------------------------------------ |
| Promise&lt;boolean&gt; | Promise used to return the mute status of the microphone. The value **true** means that the microphone is muted, and **false** means the opposite.|
| Type | Description | **Example**
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
| Promise<boolean> | Promise used to return the mute status of the microphone. The value true means that the microphone is muted, and false means the opposite. |
**Example:**
``` ```
var audioManager = audio.getAudioManager();
audioManager.isMicrophoneMute().then((value) => { audioManager.isMicrophoneMute().then((value) => {
console.log('Promise returned to indicate that the mute status of the microphone is obtained.', + value); console.log('Promise returned to indicate that the mute status of the microphone is obtained.', + value);
}); });
...@@ -1537,20 +1527,20 @@ audioManager.isMicrophoneMute().then((value) => { ...@@ -1537,20 +1527,20 @@ audioManager.isMicrophoneMute().then((value) => {
on(type: 'volumeChange', callback: Callback\<VolumeEvent>): void on(type: 'volumeChange', callback: Callback\<VolumeEvent>): void
Subscribes to system volume change events. This API uses a callback to get volume change events. Subscribes to system volume change events.
This is a system API and cannot be called by third-party applications. This is a system API and cannot be called by third-party applications.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :--------------------------------------| :-------------| :------------------------------------------------------------------------------------------------------------------------------------------------------------ | | -------- | -------------------------------------- | ---- | ------------------------------------------------------------ |
| type | string | Yes | Type of the event to subscribe to. The value 'volumeChange' means the system volume change event, which is triggered when a system volume change is detected. | | type | string | Yes | Type of event to subscribe to. The value **volumeChange** means the system volume change event, which is triggered when a system volume change is detected.|
| callback | Callback<[VolumeEvent](#volumeevent8)> | Yes | Callback used to get the system volume change event. | | callback | Callback<[VolumeEvent](#volumeevent8)> | Yes | Callback used to return the system volume change event. |
**Example:** **Example**
``` ```
audioManager.on('volumeChange', (volumeEvent) => { audioManager.on('volumeChange', (volumeEvent) => {
...@@ -1560,25 +1550,24 @@ audioManager.on('volumeChange', (volumeEvent) => { ...@@ -1560,25 +1550,24 @@ audioManager.on('volumeChange', (volumeEvent) => {
}); });
``` ```
### on('ringerModeChange')<sup>8+</sup> ### on('ringerModeChange')<sup>8+</sup>
on(type: 'ringerModeChange', callback: Callback\<AudioRingMode>): void on(type: 'ringerModeChange', callback: Callback\<AudioRingMode>): void
Subscribes to ringer mode change events. This API uses a callback to get ringer mode changes. Subscribes to ringer mode change events.
This is a system API and cannot be called by third-party applications. This is a system API and cannot be called by third-party applications.
**System capability:** SystemCapability.Multimedia.Audio.Communication **System capability**: SystemCapability.Multimedia.Audio.Communication
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :----------------------------------------- | :-------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------- | | -------- | ----------------------------------------- | ---- | ------------------------------------------------------------ |
| type | string | Yes | Type of the event to subscribe to. The value 'ringerModeChange' means the ringer mode change event, which is triggered when a ringer mode change is detected. | | type | string | Yes | Type of event to subscribe to. The value **ringerModeChange** means the ringer mode change event, which is triggered when a ringer mode change is detected.|
| callback | Callback<[AudioRingMode](#audioringmode)> | Yes | Callback used to get the updated ringer mode. | | callback | Callback<[AudioRingMode](#audioringmode)> | Yes | Callback used to return the updated ringer mode. |
**Example:** **Example**
``` ```
audioManager.on('ringerModeChange', (ringerMode) => { audioManager.on('ringerModeChange', (ringerMode) => {
...@@ -1590,18 +1579,18 @@ audioManager.on('ringerModeChange', (ringerMode) => { ...@@ -1590,18 +1579,18 @@ audioManager.on('ringerModeChange', (ringerMode) => {
on(type: 'deviceChange', callback: Callback<DeviceChangeAction\>): void on(type: 'deviceChange', callback: Callback<DeviceChangeAction\>): void
Subscribes to device change events. When a device is connected/disconnected, registered clients will receive the callback. Subscribes to device change events. When a device is connected or disconnected, registered clients will receive the callback.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :-------------------------------------------------- | :---------| :---------------------------------------------------------------------------------------------------------------------------------------------- | | :------- | :--------------------------------------------------- | :--- | :----------------------------------------- |
| type | string | Yes | Type of the event to subscribe to. The value 'deviceChange' means the device change event, which is triggered when a device change is detected. | | type | string | Yes | Type of event to subscribe to. The value **deviceChange** means the device change event, which is triggered when a device connection status change is detected.|
| callback | Callback<[DeviceChangeAction](#devicechangeaction)> | Yes | Callback used to obtain the device update details. | | callback | Callback<[DeviceChangeAction](#DeviceChangeAction)\> | Yes | Callback used to return the device update details. |
**Example:** **Example**
``` ```
audioManager.on('deviceChange', (deviceChanged) => { audioManager.on('deviceChange', (deviceChanged) => {
...@@ -1616,20 +1605,20 @@ audioManager.on('deviceChange', (deviceChanged) => { ...@@ -1616,20 +1605,20 @@ audioManager.on('deviceChange', (deviceChanged) => {
off(type: 'deviceChange', callback?: Callback<DeviceChangeAction\>): void off(type: 'deviceChange', callback?: Callback<DeviceChangeAction\>): void
Unsubscribes from audio device connection change events. Unsubscribes from device change events.
This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR. This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :-------------------------------------------------- | :---------| :-------------------------------------------------- | | -------- | --------------------------------------------------- | ---- | ------------------------------------------ |
| type | string | Yes | Type of the event to unsubscribe from. | | type | string | Yes | Type of event to unsubscribe from. The value **deviceChange** means the device change event, which is triggered when a device connection status change is detected.|
| callback | Callback<[DeviceChangeAction](#devicechangeaction)> | No | Callback used to obtain the device update details. | | callback | Callback<[DeviceChangeAction](#DeviceChangeAction)> | No | Callback used to return the device update details. |
**Example:** **Example**
``` ```
audioManager.off('deviceChange', (deviceChanged) => { audioManager.off('deviceChange', (deviceChanged) => {
...@@ -1637,26 +1626,25 @@ audioManager.off('deviceChange', (deviceChanged) => { ...@@ -1637,26 +1626,25 @@ audioManager.off('deviceChange', (deviceChanged) => {
}); });
``` ```
### on('interrupt') ### on('interrupt')
on(type: 'interrupt', interrupt: AudioInterrupt, callback: Callback\<InterruptAction>): void on(type: 'interrupt', interrupt: AudioInterrupt, callback: Callback\<InterruptAction>): void
Subscribes to audio interrupt events. When the application's audio is interrupted by another playback event, the application will receive the callback. Subscribes to audio interruption events. When the application's audio is interrupted by another playback event, the application will receive the callback.
This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR. This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| --------- | --------------------------------------------- | ---- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | --------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
| type | string | Yes | Type of event to subscribe to. The value 'interrupt' means the audio interrupt event, which is triggered when the audio playback of the current application is interrupted by another application.| | type | string | Yes | Type of event to subscribe to. The value **interrupt** means the audio interruption event, which is triggered when the audio playback of the current application is interrupted by another application.|
| interrupt | AudioInterrupt | Yes | Audio interrupt event type. | | interrupt | AudioInterrupt | Yes | Audio interruption event type. |
| callback | Callback<[InterruptAction](#interruptaction)> | Yes | Audio interrupt event callback method. | | callback | Callback<[InterruptAction](#interruptaction)> | Yes | Callback invoked for the audio interruption event. |
**Example:** **Example**
``` ```
var interAudioInterrupt = { var interAudioInterrupt = {
...@@ -1680,21 +1668,21 @@ this.audioManager.on('interrupt', interAudioInterrupt, (InterruptAction) => { ...@@ -1680,21 +1668,21 @@ this.audioManager.on('interrupt', interAudioInterrupt, (InterruptAction) => {
off(type: 'interrupt', interrupt: AudioInterrupt, callback?: Callback\<InterruptAction>): void off(type: 'interrupt', interrupt: AudioInterrupt, callback?: Callback\<InterruptAction>): void
Unsubscribes from audio interrupt events. Unsubscribes from audio interruption events.
This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR. This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| --------- | --------------------------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | --------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
| type | string | Yes | Type of event to unsubscribe from. The value 'interrupt' means the audio interrupt event, which is triggered when the audio playback of the current application is interrupted by another application. | | type | string | Yes | Type of event to subscribe to. The value **interrupt** means the audio interruption event, which is triggered when the audio playback of the current application is interrupted by another application.|
| interrupt | AudioInterrupt | Yes | Audio interrupt event type. | | interrupt | AudioInterrupt | Yes | Audio interruption event type. |
| callback | Callback<[InterruptAction](#interruptaction)> | No | Audio interrupt event callback method. | | callback | Callback<[InterruptAction](#interruptaction)> | No | Callback invoked for the audio interruption event. |
**Example:** **Example**
``` ```
var interAudioInterrupt = { var interAudioInterrupt = {
...@@ -1710,25 +1698,24 @@ this.audioManager.off('interrupt', interAudioInterrupt, (InterruptAction) => { ...@@ -1710,25 +1698,24 @@ this.audioManager.off('interrupt', interAudioInterrupt, (InterruptAction) => {
}); });
``` ```
### setAudioScene<sup>8+</sup> ### setAudioScene<sup>8+</sup>
setAudioScene\(scene: AudioScene, callback: AsyncCallback<void\>\): void setAudioScene\(scene: AudioScene, callback: AsyncCallback<void\>\): void
Sets the audio scene mode to change audio strategies. This API uses an asynchronous callback to return the result. Sets an audio scene. This API uses an asynchronous callback to return the result.
This is a system API and cannot be called by third-party applications. This is a system API and cannot be called by third-party applications.
**System capability:** SystemCapability.Multimedia.Audio.Communication **System capability**: SystemCapability.Multimedia.Audio.Communication
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :------------------------------------ | :-------- | :---------------------------------- | | :------- | :----------------------------------- | :--- | :------------------- |
| scene | <a href="#audioscene">AudioScene</a> | Yes | Audio scene mode. | | scene | <a href="#audioscene">AudioScene</a> | Yes | Audio scene to set. |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | | callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example:** **Example**
``` ```
audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL, (err) => { audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL, (err) => {
...@@ -1740,32 +1727,29 @@ audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL, (err) => { ...@@ -1740,32 +1727,29 @@ audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL, (err) => {
}); });
``` ```
### setAudioScene<sup>8+</sup> ### setAudioScene<sup>8+</sup>
setAudioScene\(scene: AudioScene\): Promise<void\> setAudioScene\(scene: AudioScene\): Promise<void\>
Sets the audio scene mode to change audio strategies. This API uses a promise to return the result. Sets an audio scene. This API uses a promise to return the result.
This is a system API and cannot be called by third-party applications. This is a system API and cannot be called by third-party applications.
**System capability:** SystemCapability.Multimedia.Audio.Communication **System capability**: SystemCapability.Multimedia.Audio.Communication
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| :------- | :-------------------------------------- | :-------- | :---------------- | | :----- | :----------------------------------- | :--- | :------------- |
| scene | <a href="#audioscene">AudioScene</a> | Yes | Audio scene mode. | | scene | <a href="#audioscene">AudioScene</a> | Yes | Audio scene to set.|
**Return value**
**Return value:** | Type | Description |
| :------------- | :------------------- |
| Promise<void\> | Promise used to return the result.|
| Type | Description | **Example**
| :------------- | :---------------------------------- |
| Promise<void\> | Promise used to return the result. |
**Example:**
``` ```
audioManager.setAudioScene(audio.AudioSceneMode.AUDIO_SCENE_PHONE_CALL).then(() => { audioManager.setAudioScene(audio.AudioSceneMode.AUDIO_SCENE_PHONE_CALL).then(() => {
...@@ -1775,22 +1759,21 @@ audioManager.setAudioScene(audio.AudioSceneMode.AUDIO_SCENE_PHONE_CALL).then(() ...@@ -1775,22 +1759,21 @@ audioManager.setAudioScene(audio.AudioSceneMode.AUDIO_SCENE_PHONE_CALL).then(()
}); });
``` ```
### getAudioScene<sup>8+</sup> ### getAudioScene<sup>8+</sup>
getAudioScene\(callback: AsyncCallback<AudioScene\>\): void getAudioScene\(callback: AsyncCallback<AudioScene\>\): void
Obtains the audio scene mode. This API uses an asynchronous callback to return the query result. Obtains the audio scene. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Communication **System capability**: SystemCapability.Multimedia.Audio.Communication
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :-------------------------------------------------- | :-------- | :-------------------------------------------- | | :------- | :-------------------------------------------------- | :--- | :--------------------------- |
| callback | AsyncCallback<<a href="#audioscene">AudioScene</a>> | Yes | Callback used to return the audio scene mode. | | callback | AsyncCallback<<a href="#audioscene">AudioScene</a>> | Yes | Callback used to return the audio scene.|
**Example:** **Example**
``` ```
audioManager.getAudioScene((err, value) => { audioManager.getAudioScene((err, value) => {
...@@ -1807,18 +1790,17 @@ audioManager.getAudioScene((err, value) => { ...@@ -1807,18 +1790,17 @@ audioManager.getAudioScene((err, value) => {
getAudioScene\(\): Promise<AudioScene\> getAudioScene\(\): Promise<AudioScene\>
Obtains the audio scene mode. This API uses a promise to return the query result. Obtains the audio scene. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Communication
**Return value:** **System capability**: SystemCapability.Multimedia.Audio.Communication
| Type | Description | **Return value**
| :-------------------------------------------- | :------------------------------------------- |
| Promise<<a href="#audioscene">AudioScene</a>> | Promise used to return the audio scene mode. |
| Type | Description |
| :-------------------------------------------- | :--------------------------- |
| Promise<<a href="#audioscene">AudioScene</a>> | Promise used to return the audio scene.|
**Example:** **Example**
``` ```
audioManager.getAudioScene().then((value) => { audioManager.getAudioScene().then((value) => {
...@@ -1832,20 +1814,18 @@ audioManager.getAudioScene().then((value) => { ...@@ -1832,20 +1814,18 @@ audioManager.getAudioScene().then((value) => {
Describes an audio device. Describes an audio device.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
| Name | Type | Readable | Writable | Description | | Name | Type | Readable| Writable| Description |
| ---------- | ------------------------- | -------- | -------- | ------------------ | | ---------- | ------------------------- | ---- | ---- | ---------- |
| deviceRole | [DeviceRole](#devicerole) | Yes | No | Audio device role. | | deviceRole | [DeviceRole](#devicerole) | Yes | No | Device role.|
| deviceType | [DeviceType](#devicetype) | Yes | No | Audio device type. | | deviceType | [DeviceType](#devicetype) | Yes | No | Device type.|
## AudioDeviceDescriptors ## AudioDeviceDescriptors
Array of [AudioDeviceDescriptor](#audiodevicedescriptor), which is read-only. Array of [AudioDeviceDescriptor](#audiodevicedescriptor), which is read-only.
**System capability:** SystemCapability.Multimedia.Audio.Device **Example**
**Example:**
``` ```
import audio from '@ohos.multimedia.audio'; import audio from '@ohos.multimedia.audio';
...@@ -1870,45 +1850,46 @@ promise.then(function (value) { ...@@ -1870,45 +1850,46 @@ promise.then(function (value) {
} }
}); });
``` ```
## AudioRenderer<sup>8+</sup> ## AudioRenderer<sup>8+</sup>
Provides related APIs for audio rendering. Before calling the AudioRenderer API, you need to create an instance through [createAudioRenderer](#audiocreateaudiorenderer8). Provides APIs for audio rendering. Before calling any API in **AudioRenderer**, you must use [createAudioRenderer](#audiocreateaudiorenderer8) to create an **AudioRenderer** instance.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
### state<sup>8+</sup> ### state<sup>8+</sup>
readonly state: AudioState Readonly state: AudioState
Defines the current render state. Defines the state of the audio renderer.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **Parameters**
| Name | Type | Readable | Writable | Description | | Name | Type | Readable| Writable| Description |
| :---- | :-------------------------- | :------- | :------- | :------------------ | | ----- | -------------------------- | ---- | ---- | ------------------ |
| state | [AudioState](#audiostate8) | Yes | No | Audio render state. | | state | [AudioState](#audiostate8) | Yes | No | Audio renderer state.|
**Example:** **Example**
``` ```
var state = audioRenderer.state; var state = audioRenderer.state;
``` ```
### getRendererInfo<sup>8+</sup> ### getRendererInfo<sup>8+</sup>
getRendererInfo(callback: AsyncCallback<AudioRendererInfo\>): void getRendererInfo(callback: AsyncCallback<AudioRendererInfo\>): void
Obtains the renderer information provided while creating a renderer instance. This API uses an asynchronous callback to return the result. Obtains the renderer information of this **AudioRenderer** instance. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :------------------------------------------------------- | :-------- | :------------------------------------------------ | | :------- | :------------------------------------------------------- | :--- | :--------------------- |
| callback | AsyncCallback<[AudioRendererInfo](#audiorendererinfo8)> | Yes | Callback used to return the renderer information. | | callback | AsyncCallback<[AudioRendererInfo](#audiorendererinfo8)\> | Yes | Callback used to return the renderer information.|
**Example:** **Example**
``` ```
audioRenderer.getRendererInfo((err, rendererInfo) => { audioRenderer.getRendererInfo((err, rendererInfo) => {
...@@ -1919,22 +1900,21 @@ audioRenderer.getRendererInfo((err, rendererInfo) => { ...@@ -1919,22 +1900,21 @@ audioRenderer.getRendererInfo((err, rendererInfo) => {
}); });
``` ```
### getRendererInfo<sup>8+</sup> ### getRendererInfo<sup>8+</sup>
getRendererInfo(): Promise<AudioRendererInfo\> getRendererInfo(): Promise<AudioRendererInfo\>
Obtains the renderer information provided while creating a renderer instance. This API uses a promise to return the result. Obtains the renderer information of this **AudioRenderer** instance. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :-------------------------------------------------- | :----------------------------------------------- | | -------------------------------------------------- | ------------------------------- |
| Promise<[AudioRendererInfo](#audiorendererinfo8)> | Promise used to return the renderer information. | | Promise<[AudioRendererInfo](#audiorendererinfo8)\> | Promise used to return the renderer information.|
**Example:** **Example**
``` ```
audioRenderer.getRendererInfo().then((rendererInfo) => { audioRenderer.getRendererInfo().then((rendererInfo) => {
...@@ -1946,24 +1926,23 @@ audioRenderer.getRendererInfo().then((rendererInfo) => { ...@@ -1946,24 +1926,23 @@ audioRenderer.getRendererInfo().then((rendererInfo) => {
console.log('AudioFrameworkRenderLog: RendererInfo :ERROR: '+err.message); console.log('AudioFrameworkRenderLog: RendererInfo :ERROR: '+err.message);
resultFlag = false; resultFlag = false;
}); });
``` ```
### getStreamInfo<sup>8+</sup> ### getStreamInfo<sup>8+</sup>
getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void
Obtains the renderer stream information. This API uses an asynchronous callback to return the result. Obtains the stream information of this **AudioRenderer** instance. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :------------------------------------------------------ | :-------- | :---------------------------------------------- | | :------- | :--------------------------------------------------- | :--- | :------------------- |
| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | Yes | Callback used to return the stream information. | | callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | Yes | Callback used to return the stream information.|
**Example:** **Example**
``` ```
audioRenderer.getStreamInfo((err, streamInfo) => { audioRenderer.getStreamInfo((err, streamInfo) => {
...@@ -1979,17 +1958,17 @@ audioRenderer.getStreamInfo((err, streamInfo) => { ...@@ -1979,17 +1958,17 @@ audioRenderer.getStreamInfo((err, streamInfo) => {
getStreamInfo(): Promise<AudioStreamInfo\> getStreamInfo(): Promise<AudioStreamInfo\>
Obtains the renderer stream information. This API uses a promise to return the result. Obtains the stream information of this **AudioRenderer** instance. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :------------------------------------------------- | :--------------------------------------------- | | :--------------------------------------------- | :--------------------- |
| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information. | | Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information.|
**Example:** **Example**
``` ```
audioRenderer.getStreamInfo().then((streamInfo) => { audioRenderer.getStreamInfo().then((streamInfo) => {
...@@ -2001,7 +1980,6 @@ audioRenderer.getStreamInfo().then((streamInfo) => { ...@@ -2001,7 +1980,6 @@ audioRenderer.getStreamInfo().then((streamInfo) => {
}).catch((err) => { }).catch((err) => {
console.log('ERROR: '+err.message); console.log('ERROR: '+err.message);
}); });
``` ```
### start<sup>8+</sup> ### start<sup>8+</sup>
...@@ -2010,16 +1988,15 @@ start(callback: AsyncCallback<void\>): void ...@@ -2010,16 +1988,15 @@ start(callback: AsyncCallback<void\>): void
Starts the renderer. This API uses an asynchronous callback to return the result. Starts the renderer. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :---------------------- | :-------- | :-------------------------------------- | | -------- | -------------------- | ---- | ---------- |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | | callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
| | | | |
**Example:** **Example**
``` ```
audioRenderer.start((err) => { audioRenderer.start((err) => {
...@@ -2037,15 +2014,15 @@ start(): Promise<void\> ...@@ -2037,15 +2014,15 @@ start(): Promise<void\>
Starts the renderer. This API uses a promise to return the result. Starts the renderer. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :------------- | :--------------------------------- | | -------------- | ------------------------- |
| Promise<void\> | Promise used to return the result. | | Promise\<void> | Promise used to return the result.|
**Example:** **Example**
``` ```
audioRenderer.start().then(() => { audioRenderer.start().then(() => {
...@@ -2055,23 +2032,21 @@ audioRenderer.start().then(() => { ...@@ -2055,23 +2032,21 @@ audioRenderer.start().then(() => {
}); });
``` ```
### pause<sup>8+</sup> ### pause<sup>8+</sup>
pause(callback: AsyncCallback\<void>): void pause(callback: AsyncCallback\<void>): void
Pauses rendering. This API uses an asynchronous callback to return the result. Pauses rendering. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :---------------------- | :-------- | :------------------------------------ | | -------- | -------------------- | ---- | ---------------- |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | | callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
| | | | |
**Example:** **Example**
``` ```
audioRenderer.pause((err) => { audioRenderer.pause((err) => {
...@@ -2089,15 +2064,15 @@ pause(): Promise\<void> ...@@ -2089,15 +2064,15 @@ pause(): Promise\<void>
Pauses rendering. This API uses a promise to return the result. Pauses rendering. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :------------- | :--------------------------------- | | -------------- | ------------------------- |
| Promise<void\> | Promise used to return the result. | | Promise\<void> | Promise used to return the result.|
**Example:** **Example**
``` ```
audioRenderer.pause().then(() => { audioRenderer.pause().then(() => {
...@@ -2113,16 +2088,15 @@ drain(callback: AsyncCallback\<void>): void ...@@ -2113,16 +2088,15 @@ drain(callback: AsyncCallback\<void>): void
Drains the playback buffer. This API uses an asynchronous callback to return the result. Drains the playback buffer. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :---------------------- | :-------- | :---------------------------------------| | -------- | -------------------- | ---- | ---------------- |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | | callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
| | | | |
**Example:** **Example**
``` ```
audioRenderer.drain((err) => { audioRenderer.drain((err) => {
...@@ -2140,15 +2114,15 @@ drain(): Promise\<void> ...@@ -2140,15 +2114,15 @@ drain(): Promise\<void>
Drains the playback buffer. This API uses a promise to return the result. Drains the playback buffer. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :------------- | :--------------------------------- | | -------------- | ------------------------- |
| Promise<void\> | Promise used to return the result. | | Promise\<void> | Promise used to return the result.|
**Example:** **Example**
``` ```
audioRenderer.drain().then(() => { audioRenderer.drain().then(() => {
...@@ -2158,22 +2132,21 @@ audioRenderer.drain().then(() => { ...@@ -2158,22 +2132,21 @@ audioRenderer.drain().then(() => {
}); });
``` ```
### stop<sup>8+</sup> ### stop<sup>8+</sup>
stop(callback: AsyncCallback\<void>): void stop(callback: AsyncCallback\<void>): void
Stops rendering. This API uses an asynchronous callback to return the result. Stops rendering. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :---------------------- | :-------- | :------------------------------------- | | -------- | -------------------- | ---- | ---------------- |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | | callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example:** **Example**
``` ```
audioRenderer.stop((err) => { audioRenderer.stop((err) => {
...@@ -2191,15 +2164,15 @@ stop(): Promise\<void> ...@@ -2191,15 +2164,15 @@ stop(): Promise\<void>
Stops rendering. This API uses a promise to return the result. Stops rendering. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :------------- | :--------------------------------- | | -------------- | ------------------------- |
| Promise<void\> | Promise used to return the result. | | Promise\<void> | Promise used to return the result.|
**Example:** **Example**
``` ```
audioRenderer.stop().then(() => { audioRenderer.stop().then(() => {
...@@ -2209,22 +2182,21 @@ audioRenderer.stop().then(() => { ...@@ -2209,22 +2182,21 @@ audioRenderer.stop().then(() => {
}); });
``` ```
### release<sup>8+</sup> ### release<sup>8+</sup>
release(callback: AsyncCallback\<void>): void release(callback: AsyncCallback\<void>): void
Releases the renderer. This API uses an asynchronous callback to return the result. Releases the renderer. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :---------------------- | :-------- | :------------------------------------- | | -------- | -------------------- | ---- | ---------------- |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | | callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example:** **Example**
``` ```
audioRenderer.release((err) => { audioRenderer.release((err) => {
...@@ -2242,15 +2214,15 @@ release(): Promise\<void> ...@@ -2242,15 +2214,15 @@ release(): Promise\<void>
Releases the renderer. This API uses a promise to return the result. Releases the renderer. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :------------- | :--------------------------------- | | -------------- | ------------------------- |
| Promise<void\> | Promise used to return the result. | | Promise\<void> | Promise used to return the result.|
**Example:** **Example**
``` ```
audioRenderer.release().then(() => { audioRenderer.release().then(() => {
...@@ -2266,16 +2238,16 @@ write(buffer: ArrayBuffer, callback: AsyncCallback\<number>): void ...@@ -2266,16 +2238,16 @@ write(buffer: ArrayBuffer, callback: AsyncCallback\<number>): void
Writes the buffer. This API uses an asynchronous callback to return the result. Writes the buffer. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :---------------------- | :-------- | :--------------------------------------------------------------------------------------------------- | | -------- | ---------------------- | ---- | --------------------------------------------------- |
| buffer | ArrayBuffer | Yes | Buffer to be written. | | buffer | ArrayBuffer | Yes | Buffer to be written. |
| callback | AsyncCallback<boolean\> | Yes | Returns the number of bytes written if the operation is successful; returns an error code otherwise. | | callback | AsyncCallback\<number> | Yes | Returns the number of bytes written if the operation is successful; returns an error code otherwise.|
**Example:** **Example**
``` ```
import audio from '@ohos.multimedia.audio'; import audio from '@ohos.multimedia.audio';
...@@ -2293,22 +2265,21 @@ audioRenderer.write(buf, (err, writtenbytes) => { ...@@ -2293,22 +2265,21 @@ audioRenderer.write(buf, (err, writtenbytes) => {
}); });
``` ```
### write<sup>8+</sup> ### write<sup>8+</sup>
write(buffer: ArrayBuffer): Promise\<number> write(buffer: ArrayBuffer): Promise\<number>
Writes the buffer. This API uses a promise to return the result. Writes the buffer. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :--------------- | :--------------------------------------------------------------------------------------------------- | | ---------------- | ------------------------------------------------------------ |
| Promise<number\> | Returns the number of bytes written if the operation is successful; returns an error code otherwise. | | Promise\<number> | Returns the number of bytes written if the operation is successful; returns an error code otherwise.|
**Example:** **Example**
``` ```
import audio from '@ohos.multimedia.audio'; import audio from '@ohos.multimedia.audio';
...@@ -2333,17 +2304,17 @@ audioRenderer.write(buf).then((writtenbytes) => { ...@@ -2333,17 +2304,17 @@ audioRenderer.write(buf).then((writtenbytes) => {
getAudioTime(callback: AsyncCallback\<number>): void getAudioTime(callback: AsyncCallback\<number>): void
Obtains the timestamp in Unix epoch time (starts from January 1, 1970), in nanoseconds. This API uses an asynchronous callback to return the result. Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :--------------------- | :-------- | :------------------------------------- | | -------- | ---------------------- | ---- | ---------------- |
| callback | AsyncCallback<number\> | Yes | Callback used to return the timestamp. | | callback | AsyncCallback\<number> | Yes | Callback used to return the timestamp.|
**Example:** **Example**
``` ```
audioRenderer.getAudioTime((err, timestamp) => { audioRenderer.getAudioTime((err, timestamp) => {
...@@ -2351,22 +2322,21 @@ audioRenderer.getAudioTime((err, timestamp) => { ...@@ -2351,22 +2322,21 @@ audioRenderer.getAudioTime((err, timestamp) => {
}); });
``` ```
### getAudioTime<sup>8+</sup> ### getAudioTime<sup>8+</sup>
getAudioTime(): Promise\<number> getAudioTime(): Promise\<number>
Obtains the timestamp in Unix epoch time (starts from January 1, 1970), in nanoseconds. This API uses a promise to return the result. Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :--------------- | :------------------------------------ | | ---------------- | ----------------------- |
| Promise<number\> | Promise used to return the timestamp. | | Promise\<number> | Promise used to return the timestamp.|
**Example:** **Example**
``` ```
audioRenderer.getAudioTime().then((timestamp) => { audioRenderer.getAudioTime().then((timestamp) => {
...@@ -2376,22 +2346,21 @@ audioRenderer.getAudioTime().then((timestamp) => { ...@@ -2376,22 +2346,21 @@ audioRenderer.getAudioTime().then((timestamp) => {
}); });
``` ```
### getBufferSize<sup>8+</sup> ### getBufferSize<sup>8+</sup>
getBufferSize(callback: AsyncCallback\<number>): void getBufferSize(callback: AsyncCallback\<number>): void
Obtains a reasonable minimum buffer size in bytes for rendering. This API uses an asynchronous callback to return the result. Obtains a reasonable minimum buffer size in bytes for rendering. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :--------------------- | :-------- | :--------------------------------------- | | -------- | ---------------------- | ---- | -------------------- |
| callback | AsyncCallback<number\> | Yes | Callback used to return the buffer size. | | callback | AsyncCallback\<number> | Yes | Callback used to return the buffer size.|
**Example:** **Example**
``` ```
audioRenderer.getBufferSize((err, bufferSize) => { audioRenderer.getBufferSize((err, bufferSize) => {
...@@ -2403,22 +2372,21 @@ let buf = new ArrayBuffer(bufferSize); ...@@ -2403,22 +2372,21 @@ let buf = new ArrayBuffer(bufferSize);
ss.readSync(buf); ss.readSync(buf);
``` ```
### getBufferSize<sup>8+</sup> ### getBufferSize<sup>8+</sup>
getBufferSize(): Promise\<number> getBufferSize(): Promise\<number>
Obtains a reasonable minimum buffer size in bytes for rendering. This API uses a promise to return the result. Obtains a reasonable minimum buffer size in bytes for rendering. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :--------------- | :-------------------------------------- | | ---------------- | --------------------------- |
| Promise<number\> | Promise used to return the buffer size. | | Promise\<number> | Promise used to return the buffer size.|
**Example:** **Example**
``` ```
audioRenderer.getBufferSize().then((bufferSize) => { audioRenderer.getBufferSize().then((bufferSize) => {
...@@ -2435,16 +2403,16 @@ setRenderRate(rate: AudioRendererRate, callback: AsyncCallback\<void>): void ...@@ -2435,16 +2403,16 @@ setRenderRate(rate: AudioRendererRate, callback: AsyncCallback\<void>): void
Sets the render rate. This API uses an asynchronous callback to return the result. Sets the render rate. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :------------------------------------------ | :-------- | :---------------------------------- | | -------- | ---------------------------------------- | ---- | ------------------------ |
| rate | [AudioRendererRate](#audiorendererrate8) | Yes | Audio render rate. | | rate | [AudioRendererRate](#audiorendererrate8) | Yes | Audio render rate. |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | | callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example:** **Example**
``` ```
audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL, (err) => { audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL, (err) => {
...@@ -2456,28 +2424,27 @@ audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL, (err) => ...@@ -2456,28 +2424,27 @@ audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL, (err) =>
}); });
``` ```
### setRenderRate<sup>8+</sup> ### setRenderRate<sup>8+</sup>
setRenderRate(rate: AudioRendererRate): Promise\<void> setRenderRate(rate: AudioRendererRate): Promise\<void>
Sets the render rate. This API uses a promise to return the result. Sets the render rate. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| :--- | :--------------------------------------- | :-------- | :----------------- | | ------ | ---------------------------------------- | ---- | ------------ |
| rate | [AudioRendererRate](#audiorendererrate8) | Yes | Audio render rate. | | rate | [AudioRendererRate](#audiorendererrate8) | Yes | Audio render rate.|
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :------------- | :--------------------------------- | | -------------- | ------------------------- |
| Promise<void\> | Promise used to return the result. | | Promise\<void> | Promise used to return the result.|
**Example:** **Example**
``` ```
audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL).then(() => { audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL).then(() => {
...@@ -2493,15 +2460,15 @@ getRenderRate(callback: AsyncCallback\<AudioRendererRate>): void ...@@ -2493,15 +2460,15 @@ getRenderRate(callback: AsyncCallback\<AudioRendererRate>): void
Obtains the current render rate. This API uses an asynchronous callback to return the result. Obtains the current render rate. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :------------------------------------------------------- | :-------- | :--------------------------------------------- | | -------- | ------------------------------------------------------- | ---- | ------------------ |
| callback | AsyncCallback<[AudioRendererRate](#audiorendererrate8)\> | Yes | Callback used to return the audio render rate. | | callback | AsyncCallback<[AudioRendererRate](#audiorendererrate8)> | Yes | Callback used to return the audio render rate.|
**Example:** **Example**
``` ```
audioRenderer.getRenderRate((err, renderrate) => { audioRenderer.getRenderRate((err, renderrate) => {
...@@ -2509,22 +2476,21 @@ audioRenderer.getRenderRate((err, renderrate) => { ...@@ -2509,22 +2476,21 @@ audioRenderer.getRenderRate((err, renderrate) => {
}); });
``` ```
### getRenderRate<sup>8+</sup> ### getRenderRate<sup>8+</sup>
getRenderRate(): Promise\<AudioRendererRate> getRenderRate(): Promise\<AudioRendererRate>
Obtains the current render rate. This API uses a promise to return the result. Obtains the current render rate. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :-------------------------------------------------- | :-------------------------------------------- | | ------------------------------------------------- | ------------------------- |
| Promise<<[AudioRendererRate](#audiorendererrate8)\> | Promise used to return the audio render rate. | | Promise<[AudioRendererRate](#audiorendererrate8)> | Promise used to return the audio render rate.|
**Example:** **Example**
``` ```
audioRenderer.getRenderRate().then((renderRate) => { audioRenderer.getRenderRate().then((renderRate) => {
...@@ -2534,23 +2500,68 @@ audioRenderer.getRenderRate().then((renderRate) => { ...@@ -2534,23 +2500,68 @@ audioRenderer.getRenderRate().then((renderRate) => {
}); });
``` ```
### on('interrupt')<sup>9+</sup>
on(type: 'interrupt', callback: Callback\<InterruptEvent>): void
Subscribes to audio interruption events. This API uses a callback to get interrupt events.
**System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------------------------------- | ---- | ------------------------------------------------------------ |
| type | string | Yes | Type of event to subscribe to. The value **interrupt** means the audio interruption event, which is triggered when audio playback is interrupted.|
| callback | Callback<[InterruptEvent](#interruptevent9)> | Yes | Callback used to return the audio interruption event. |
**Example**
```
audioRenderer.on('interrupt', (interruptEvent) => {
if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_FORCE) {
switch (interruptEvent.hintType) {
case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
console.log('Force paused. Stop writing');
isPlay = false;
break;
case audio.InterruptHint.INTERRUPT_HINT_STOP:
console.log('Force stopped. Stop writing');
isPlay = false;
break;
}
} else if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_SHARE) {
switch (interruptEvent.hintType) {
case audio.InterruptHint.INTERRUPT_HINT_RESUME:
console.log('Resume force paused renderer or ignore');
startRenderer();
break;
case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
console.log('Choose to pause or ignore');
pauseRenderer();
break;
}
}
});
```
### on('markReach')<sup>8+</sup> ### on('markReach')<sup>8+</sup>
on(type: 'markReach', frame: number, callback: (position: number) => {}): void on(type: 'markReach', frame: number, callback: (position: number) => {}): void
Subscribes to mark reached events. When the number of frames rendered reaches the value of the frame parameter, the callback is invoked. Subscribes to mark reached events. When the number of frames rendered reaches the value of the **frame** parameter, the callback is invoked.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :------------------------ | :-------- | :----------------------------------------------------------------------- | | :------- | :----------------------- | :--- | :---------------------------------------- |
| type | string | Yes | Type of the renderer event to subscribe to. | | type | string | Yes | Type of event to subscribe to. The value **markReach** means the mark reached event, which is triggered when the number of frames captured reaches the value of the **frame** parameter.|
| frame | number | Yes | Number of frames to trigger the event. The value must be greater than 0. | | frame | number | Yes | Number of frames to trigger the event. The value must be greater than **0**. |
| callback | (position: number) => {} | Yes | Callback invoked when the event is triggered. | | callback | (position: number) => {} | Yes | Callback invoked when the event is triggered. |
**Example:** **Example**
``` ```
audioRenderer.on('markReach', 1000, (position) => { audioRenderer.on('markReach', 1000, (position) => {
...@@ -2567,15 +2578,15 @@ off(type: 'markReach'): void ...@@ -2567,15 +2578,15 @@ off(type: 'markReach'): void
Unsubscribes from mark reached events. Unsubscribes from mark reached events.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| :------- | :------------------------ | :-------- | :----------------------------------------------- | | :----- | :----- | :--- | :------------------------------------------------ |
| type | string | Yes | Type of the renderer event to unsubscribe from. | | type | string | Yes | Type of event to unsubscribe from. The value is fixed at **markReach**.|
**Example:** **Example**
``` ```
audioRenderer.off('markReach'); audioRenderer.off('markReach');
...@@ -2585,19 +2596,19 @@ audioRenderer.off('markReach'); ...@@ -2585,19 +2596,19 @@ audioRenderer.off('markReach');
on(type: "periodReach", frame: number, callback: (position: number) => {}): void on(type: "periodReach", frame: number, callback: (position: number) => {}): void
Subscribes to period reached events. When the period of frame rendering reaches the value of frame parameter, the callback is invoked. Subscribes to period reached events. When the period of frame rendering reaches the value of the **frame** parameter, the callback is invoked.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :------------------------ | :-------- | :--------------------------------------------------------------------------------- | | :------- | :----------------------- | :--- | :------------------------------------------ |
| type | string | Yes | Type of the renderer event to subscribe to. | | type | string | Yes | Type of event to subscribe to. The value **periodReach** means the period reached event, which is triggered when the period of frame rendering reaches the value of the **frame** parameter.|
| frame | number | Yes | Period during which frame rendering is listened. The value must be greater than 0. | | frame | number | Yes | Period during which frame rendering is listened. The value must be greater than **0**. |
| callback | (position: number) => {} | Yes | Callback invoked when the event is triggered. | | callback | (position: number) => {} | Yes | Callback invoked when the event is triggered. |
**Example:** **Example**
``` ```
audioRenderer.on('periodReach', 1000, (position) => { audioRenderer.on('periodReach', 1000, (position) => {
...@@ -2613,15 +2624,15 @@ off(type: 'periodReach'): void ...@@ -2613,15 +2624,15 @@ off(type: 'periodReach'): void
Unsubscribes from period reached events. Unsubscribes from period reached events.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| :------- | :------------------------ | :-------- | :----------------------------------------------- | | :----- | :----- | :--- | :-------------------------------------------------- |
| type | string | Yes | Type of the renderer event to unsubscribe from. | | type | string | Yes | Type of event to unsubscribe from. The value is fixed at **periodReach**.|
**Example:** **Example**
``` ```
audioRenderer.off('periodReach') audioRenderer.off('periodReach')
...@@ -2633,16 +2644,16 @@ on(type: 'stateChange', callback: Callback<AudioState\>): void ...@@ -2633,16 +2644,16 @@ on(type: 'stateChange', callback: Callback<AudioState\>): void
Subscribes to state change events. Subscribes to state change events.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :------------------------- | :-------- | :--------------------------------------------------------------------------------------- | | :------- | :------------------------- | :--- | :------------------------------------------ |
| type | string | Yes | Type of the event to subscribe to. The value 'stateChange' means the state change event. | | type | string | Yes | Type of event to subscribe to. The value **stateChange** means the state change event.|
| callback | [AudioState](#audiostate8) | Yes | Callback used to return the state change. | | callback | [AudioState](#audiostate8) | Yes | Callback used to return the state change. |
**Example:** **Example**
``` ```
audioRenderer.on('stateChange', (state) => { audioRenderer.on('stateChange', (state) => {
...@@ -2657,42 +2668,41 @@ audioRenderer.on('stateChange', (state) => { ...@@ -2657,42 +2668,41 @@ audioRenderer.on('stateChange', (state) => {
## AudioCapturer<sup>8+</sup> ## AudioCapturer<sup>8+</sup>
Provides related APIs for audio capture. Before calling the API of AudioCapturer, you need to create an instance through [createAudioCapturer](#audiocreateaudiocapturer8). Provides APIs for audio capture. Before calling any API in **AudioCapturer**, you must use [createAudioCapturer](#audiocreateaudiocapturer8) to create an **AudioCapturer** instance.
### state<sup>8+</sup> ### state<sup>8+</sup>
readonly state: AudioState Readonly state: AudioState
Defines the current capture state. Defines the audio capturer state.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
| Name | Type | Readable | Writable | Description | | Name | Type | Readable| Writable| Description |
| :---- | :------------------------- | :------- | :------- | :------------------- | | :---- | :------------------------- | :--- | :--- | :--------------- |
| state | [AudioState](#audiostate8) | Yes | No | Audio capture state. | | state | [AudioState](#audiostate8) | Yes | No | Audio capturer state.|
**Example:** **Example**
``` ```
var state = audioCapturer.state; var state = audioCapturer.state;
``` ```
### getCapturerInfo<sup>8+</sup> ### getCapturerInfo<sup>8+</sup>
getCapturerInfo(callback: AsyncCallback<AudioCapturerInfo\>): void getCapturerInfo(callback: AsyncCallback<AudioCapturerInfo\>): void
Obtains the capturer information provided while creating a capturer instance. This API uses an asynchronous callback to return the result. Obtains the capturer information of this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :------------------------------------------------------- | :-------- | :------------------------------------------------ | | :------- | :-------------------------------- | :--- | :----------------------------------- |
| callback | AsyncCallback<[AudioCapturerInfo](#audiocapturerinfo)\> | Yes | Callback used to return the capturer information. | | callback | AsyncCallback<AudioCapturerInfo\> | Yes | Callback used to return the capturer information.|
**Example:** **Example**
``` ```
audioCapturer.getCapturerInfo((err, capturerInfo) => { audioCapturer.getCapturerInfo((err, capturerInfo) => {
...@@ -2711,17 +2721,17 @@ audioCapturer.getCapturerInfo((err, capturerInfo) => { ...@@ -2711,17 +2721,17 @@ audioCapturer.getCapturerInfo((err, capturerInfo) => {
getCapturerInfo(): Promise<AudioCapturerInfo\> getCapturerInfo(): Promise<AudioCapturerInfo\>
Obtains the capturer information provided while creating a capturer instance. This API uses a promise to return the result. Obtains the capturer information of this **AudioCapturer** instance. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :-------------------------------------------------- | :----------------------------------------------- | | :------------------------------------------------ | :---------------------------------- |
| Promise<[AudioCapturerInfo](#audiocapturerinfo)\> | Promise used to return the capturer information. | | Promise<[AudioCapturerInfo](#audiocapturerinfo)\> | Promise used to return the capturer information.|
**Example:** **Example**
``` ```
audioCapturer.getCapturerInfo().then((audioParamsGet) => { audioCapturer.getCapturerInfo().then((audioParamsGet) => {
...@@ -2736,24 +2746,23 @@ audioCapturer.getCapturerInfo().then((audioParamsGet) => { ...@@ -2736,24 +2746,23 @@ audioCapturer.getCapturerInfo().then((audioParamsGet) => {
}).catch((err) => { }).catch((err) => {
console.log('AudioFrameworkRecLog: CapturerInfo :ERROR: '+err.message); console.log('AudioFrameworkRecLog: CapturerInfo :ERROR: '+err.message);
}); });
``` ```
### getStreamInfo<sup>8+</sup> ### getStreamInfo<sup>8+</sup>
getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void
Obtains the capturer stream information. This API uses an asynchronous callback to return the result. Obtains the stream information of this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :----------------------------------------------------------- | :-------- | :---------------------------------------------- | | :------- | :--------------------------------------------------- | :--- | :------------------------------- |
| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | Yes | Callback used to return the stream information. | | callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | Yes | Callback used to return the stream information.|
**Example:** **Example**
``` ```
audioCapturer.getStreamInfo((err, streamInfo) => { audioCapturer.getStreamInfo((err, streamInfo) => {
...@@ -2773,17 +2782,17 @@ audioCapturer.getStreamInfo((err, streamInfo) => { ...@@ -2773,17 +2782,17 @@ audioCapturer.getStreamInfo((err, streamInfo) => {
getStreamInfo(): Promise<AudioStreamInfo\> getStreamInfo(): Promise<AudioStreamInfo\>
Obtains the capturer stream information. This API uses a promise to return the result. Obtains the stream information of this **AudioCapturer** instance. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :---------------------------------------------------- | :----------------------------------------------- | | :--------------------------------------------- | :------------------------------ |
| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information. | | Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information.|
**Example:** **Example**
``` ```
audioCapturer.getStreamInfo().then((audioParamsGet) => { audioCapturer.getStreamInfo().then((audioParamsGet) => {
...@@ -2795,7 +2804,6 @@ audioCapturer.getStreamInfo().then((audioParamsGet) => { ...@@ -2795,7 +2804,6 @@ audioCapturer.getStreamInfo().then((audioParamsGet) => {
}).catch((err) => { }).catch((err) => {
console.log('getStreamInfo :ERROR: ' + err.message); console.log('getStreamInfo :ERROR: ' + err.message);
}); });
``` ```
### start<sup>8+</sup> ### start<sup>8+</sup>
...@@ -2804,15 +2812,15 @@ start(callback: AsyncCallback<void\>): void ...@@ -2804,15 +2812,15 @@ start(callback: AsyncCallback<void\>): void
Starts capturing. This API uses an asynchronous callback to return the result. Starts capturing. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :---------------------- | :-------- | :-------------------------------------- | | :------- | :------------------- | :--- | :----------------------------- |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | | callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example:** **Example**
``` ```
audioCapturer.start((err) => { audioCapturer.start((err) => {
...@@ -2831,15 +2839,15 @@ start(): Promise<void\> ...@@ -2831,15 +2839,15 @@ start(): Promise<void\>
Starts capturing. This API uses a promise to return the result. Starts capturing. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :------------- | :--------------------------------- | | :------------- | :---------------------------- |
| Promise<void\> | Promise used to return the result. | | Promise<void\> | Promise used to return the result.|
**Example:** **Example**
``` ```
audioCapturer.start().then(() => { audioCapturer.start().then(() => {
...@@ -2862,15 +2870,15 @@ stop(callback: AsyncCallback<void\>): void ...@@ -2862,15 +2870,15 @@ stop(callback: AsyncCallback<void\>): void
Stops capturing. This API uses an asynchronous callback to return the result. Stops capturing. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :---------------------- | :-------- | :------------------------------------- | | :------- | :------------------- | :--- | :----------------------------- |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | | callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example:** **Example**
``` ```
audioCapturer.stop((err) => { audioCapturer.stop((err) => {
...@@ -2889,15 +2897,15 @@ stop(): Promise<void\> ...@@ -2889,15 +2897,15 @@ stop(): Promise<void\>
Stops capturing. This API uses a promise to return the result. Stops capturing. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :------------- | :--------------------------------- | | :------------- | :---------------------------- |
| Promise<void\> | Promise used to return the result. | | Promise<void\> | Promise used to return the result.|
**Example:** **Example**
``` ```
audioCapturer.stop().then(() => { audioCapturer.stop().then(() => {
...@@ -2913,22 +2921,21 @@ audioCapturer.stop().then(() => { ...@@ -2913,22 +2921,21 @@ audioCapturer.stop().then(() => {
}); });
``` ```
### release<sup>8+</sup> ### release<sup>8+</sup>
release(callback: AsyncCallback<void\>): void release(callback: AsyncCallback<void\>): void
Releases the capturer. This API uses an asynchronous callback to return the result. Releases this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :---------------------- | :-------- | :------------------------------------- | | :------- | :------------------- | :--- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | | callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Example:** **Example**
``` ```
audioCapturer.release((err) => { audioCapturer.release((err) => {
...@@ -2945,20 +2952,19 @@ audioCapturer.release((err) => { ...@@ -2945,20 +2952,19 @@ audioCapturer.release((err) => {
release(): Promise<void\> release(): Promise<void\>
Releases the capturer. This API uses a promise to return the result. Releases this **AudioCapturer** instance. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :------------- | :--------------------------------- | | :------------- | :---------------------------- |
| Promise<void\> | Promise used to return the result. | | Promise<void\> | Promise used to return the result.|
**Example:** **Example**
``` ```
audioCapturer.release().then(() => { audioCapturer.release().then(() => {
console.info('AudioFrameworkRecLog: ---------RELEASE RECORD---------'); console.info('AudioFrameworkRecLog: ---------RELEASE RECORD---------');
console.info('AudioFrameworkRecLog: Capturer release : SUCCESS'); console.info('AudioFrameworkRecLog: Capturer release : SUCCESS');
...@@ -2971,7 +2977,6 @@ audioCapturer.release().then(() => { ...@@ -2971,7 +2977,6 @@ audioCapturer.release().then(() => {
console.info('AudioFrameworkRecLog: Capturer stop:ERROR : '+err.message); console.info('AudioFrameworkRecLog: Capturer stop:ERROR : '+err.message);
stateFlag=false stateFlag=false
}); });
``` ```
...@@ -2979,19 +2984,19 @@ audioCapturer.release().then(() => { ...@@ -2979,19 +2984,19 @@ audioCapturer.release().then(() => {
read(size: number, isBlockingRead: boolean, callback: AsyncCallback<ArrayBuffer\>): void read(size: number, isBlockingRead: boolean, callback: AsyncCallback<ArrayBuffer\>): void
Reads the buffer from the audio capturer. This API uses an asynchronous callback to return the result. Reads the buffer. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------------- | :-------------------------- | :-------- | :-------------------------------------------- | | :------------- | :-------------------------- | :--- | :------------------------------- |
| size | number | Yes | Number of bytes to read. | | size | number | Yes | Number of bytes to read. |
| isBlockingRead | boolean | Yes | Whether the read operation should be blocked. | | isBlockingRead | boolean | Yes | Whether to block the read operation. |
| callback | AsyncCallback<ArrayBuffer\> | Yes | Callback used to return the buffer. | | callback | AsyncCallback<ArrayBuffer\> | Yes | Callback used to return the buffer.|
**Example:** **Example**
``` ```
audioCapturer.read(bufferSize, true, async(err, buffer) => { audioCapturer.read(bufferSize, true, async(err, buffer) => {
...@@ -3006,24 +3011,24 @@ audioCapturer.read(bufferSize, true, async(err, buffer) => { ...@@ -3006,24 +3011,24 @@ audioCapturer.read(bufferSize, true, async(err, buffer) => {
read(size: number, isBlockingRead: boolean): Promise<ArrayBuffer\> read(size: number, isBlockingRead: boolean): Promise<ArrayBuffer\>
Reads the buffer from the audio capturer. This API uses a promise to return the result. Reads the buffer. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------------- | :--------- | :-------- | :-------------------------------------------- | | :------------- | :------ | :--- | :--------------- |
| size | number | Yes | Number of bytes to read. | | size | number | Yes | Number of bytes to read. |
| isBlockingRead | boolean | Yes | Whether the read operation should be blocked. | | isBlockingRead | boolean | Yes | Whether to block the read operation.|
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :-------------------- | :----------------------------------------------------------------------------------------------- | | :-------------------- | :----------------------------------------------------- |
| Promise<ArrayBuffer\> | Returns the buffer data read if the operation is successful; returns an error code otherwise. | | Promise<ArrayBuffer\> | Returns the buffer data read if the operation is successful; returns an error code otherwise.|
**Example:** **Example**
``` ```
audioCapturer.read(bufferSize, true).then((buffer) => { audioCapturer.read(bufferSize, true).then((buffer) => {
...@@ -3038,18 +3043,17 @@ audioCapturer.read(bufferSize, true).then((buffer) => { ...@@ -3038,18 +3043,17 @@ audioCapturer.read(bufferSize, true).then((buffer) => {
getAudioTime(callback: AsyncCallback<number\>): void getAudioTime(callback: AsyncCallback<number\>): void
Obtains the timestamp in Unix epoch time (starts from January 1, 1970), in nanoseconds. This API uses an asynchronous callback to return the result. Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :--------------------- | :-------- | :------------------------------------- | | :------- | :--------------------- | :--- | :----------------------------- |
| callback | AsyncCallback<number\> | Yes | Callback used to return the timestamp. | | callback | AsyncCallback<number\> | Yes | Callback used to return the timestamp.|
| | | | |
**Example:** **Example**
``` ```
audioCapturer.getAudioTime((err, timestamp) => { audioCapturer.getAudioTime((err, timestamp) => {
...@@ -3062,17 +3066,17 @@ audioCapturer.getAudioTime((err, timestamp) => { ...@@ -3062,17 +3066,17 @@ audioCapturer.getAudioTime((err, timestamp) => {
getAudioTime(): Promise<number\> getAudioTime(): Promise<number\>
Obtains the timestamp in Unix epoch time (starts from January 1, 1970), in nanoseconds. This API uses a promise to return the result. Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :--------------- | :------------------------------------ | | :--------------- | :---------------------------- |
| Promise<number\> | Promise used to return the timestamp. | | Promise<number\> | Promise used to return the timestamp.|
**Example:** **Example**
``` ```
audioCapturer.getAudioTime().then((audioTime) => { audioCapturer.getAudioTime().then((audioTime) => {
...@@ -3080,7 +3084,6 @@ audioCapturer.getAudioTime().then((audioTime) => { ...@@ -3080,7 +3084,6 @@ audioCapturer.getAudioTime().then((audioTime) => {
}).catch((err) => { }).catch((err) => {
console.info('AudioFrameworkRecLog: AudioCapturer Created : ERROR : '+err.message); console.info('AudioFrameworkRecLog: AudioCapturer Created : ERROR : '+err.message);
}); });
``` ```
...@@ -3090,16 +3093,15 @@ getBufferSize(callback: AsyncCallback<number\>): void ...@@ -3090,16 +3093,15 @@ getBufferSize(callback: AsyncCallback<number\>): void
Obtains a reasonable minimum buffer size in bytes for capturing. This API uses an asynchronous callback to return the result. Obtains a reasonable minimum buffer size in bytes for capturing. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :--------------------- | :-------- | :--------------------------------------- | | :------- | :--------------------- | :--- | :----------------------------------- |
| callback | AsyncCallback<number\> | Yes | Callback used to return the buffer size. | | callback | AsyncCallback<number\> | Yes | Callback used to return the buffer size.|
| | | | |
**Example:** **Example**
``` ```
audioCapturer.getBufferSize((err, bufferSize) => { audioCapturer.getBufferSize((err, bufferSize) => {
...@@ -3114,21 +3116,22 @@ audioCapturer.getBufferSize((err, bufferSize) => { ...@@ -3114,21 +3116,22 @@ audioCapturer.getBufferSize((err, bufferSize) => {
}); });
``` ```
### getBufferSize<sup>8+</sup> ### getBufferSize<sup>8+</sup>
getBufferSize(): Promise<number\> getBufferSize(): Promise<number\>
Obtains a reasonable minimum buffer size in bytes for capturing. This API uses a promise to return the result. Obtains a reasonable minimum buffer size in bytes for capturing. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :--------------- | :-------------------------------------- | | :--------------- | :---------------------------------- |
| Promise<number\> | Promise used to return the buffer size. | | Promise<number\> | Promise used to return the buffer size.|
**Example:** **Example**
``` ```
audioCapturer.getBufferSize().then((bufferSize) => { audioCapturer.getBufferSize().then((bufferSize) => {
...@@ -3143,23 +3146,24 @@ audioCapturer.getBufferSize().then((bufferSize) => { ...@@ -3143,23 +3146,24 @@ audioCapturer.getBufferSize().then((bufferSize) => {
}); });
``` ```
### on('markReach')<sup>8+</sup> ### on('markReach')<sup>8+</sup>
on(type: 'markReach', frame: number, callback: (position: number) => {}): void on(type: 'markReach', frame: number, callback: (position: number) => {}): void
Subscribes to mark reached events. When the number of frames captured reaches the value of the frame parameter, the callback is invoked. Subscribes to mark reached events. When the number of frames captured reaches the value of the **frame** parameter, the callback is invoked.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :------------------------ | :-------- | :----------------------------------------------------------------------- | | :------- | :---------------------- | :--- | :----------------------------------------- |
| type | string | Yes | Type of the capturer event to subscribe to. | | type | string | Yes | Type of event to subscribe to. The value **markReach** means the mark reached event, which is triggered when the number of frames captured reaches the value of the **frame** parameter. |
| frame | number | Yes | Number of frames to trigger the event. The value must be greater than 0. | | frame | number | Yes | Number of frames to trigger the event. The value must be greater than **0**. |
| callback | position: number) => {} | Yes | Callback invoked when the event is triggered. | | callback | position: number) => {} | Yes | Callback invoked when the event is triggered.|
**Example:** **Example**
``` ```
audioCapturer.on('markReach', 1000, (position) => { audioCapturer.on('markReach', 1000, (position) => {
...@@ -3169,22 +3173,21 @@ audioCapturer.on('markReach', 1000, (position) => { ...@@ -3169,22 +3173,21 @@ audioCapturer.on('markReach', 1000, (position) => {
}); });
``` ```
### off('markReach')<sup>8+</sup> ### off('markReach')<sup>8+</sup>
off(type: 'markReach'): void off(type: 'markReach'): void
Unsubscribes from the mark reached events. Unsubscribes from mark reached events.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| :------- | :------------------------ | :-------- | :---------------------------------------------- | | :----- | :----- | :--- | :-------------------------------------------- |
| type | string | Yes | Type of the capturer event to unsubscribe from. | | type | string | Yes | Type of event to unsubscribe from. The value **markReach** means the mark reached event, which is triggered when the number of frames captured reaches the value of the **frame** parameter.|
**Example:** **Example**
``` ```
audioCapturer.off('markReach'); audioCapturer.off('markReach');
...@@ -3194,19 +3197,19 @@ audioCapturer.off('markReach'); ...@@ -3194,19 +3197,19 @@ audioCapturer.off('markReach');
on(type: "periodReach", frame: number, callback: (position: number) => {}): void on(type: "periodReach", frame: number, callback: (position: number) => {}): void
Subscribes to period reached events. When the period of frame capturing reaches the value of frame parameter, the callback is invoked. Subscribes to mark reached events. When the period of frame capturing reaches the value of the **frame** parameter, the callback is invoked.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :------------------------ | :-------- | :--------------------------------------------------------------------------------- | | :------- | :----------------------- | :--- | :------------------------------------------ |
| type | string | Yes | Type of the capturer event to subscribe to. | | type | string | Yes | Type of event to subscribe to. The value **periodReach** means the period reached event, which is triggered when the period of frame capturing reaches the value of the **frame** parameter.|
| frame | number | Yes | Period during which frame capturing is listened. The value must be greater than 0. | | frame | number | Yes | Number of frames to trigger the event. The value must be greater than **0**. |
| callback | (position: number) => {} | Yes | Callback invoked when the event is triggered. | | callback | (position: number) => {} | Yes | Callback invoked when the event is triggered. |
**Example:** **Example**
``` ```
audioCapturer.on('periodReach', 1000, (position) => { audioCapturer.on('periodReach', 1000, (position) => {
...@@ -3222,15 +3225,15 @@ off(type: 'periodReach'): void ...@@ -3222,15 +3225,15 @@ off(type: 'periodReach'): void
Unsubscribes from period reached events. Unsubscribes from period reached events.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| :------- | :------------------------ | :-------- | :---------------------------------------------- | | :----- | :----- | :--- | :---------------------------------------------- |
| type | string | Yes | Type of the capturer event to unsubscribe from. | | type | string | Yes | Type of event to unsubscribe from. The value **periodReach** means the period reached event, which is triggered when the period of frame capturing reaches the value of the **frame** parameter.|
**Example:** **Example**
``` ```
audioCapturer.off('periodReach') audioCapturer.off('periodReach')
...@@ -3242,16 +3245,16 @@ on(type: 'stateChange', callback: Callback<AudioState\>): void ...@@ -3242,16 +3245,16 @@ on(type: 'stateChange', callback: Callback<AudioState\>): void
Subscribes to state change events. Subscribes to state change events.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :------------------------- | :-------- | :--------------------------------------------------------------------------------------- | | :------- | :------------------------- | :--- | :------------------------------------------ |
| type | string | Yes | Type of the event to subscribe to. The value 'stateChange' means the state change event. | | type | string | Yes | Type of event to subscribe to. The value **stateChange** means the state change event.|
| callback | [AudioState](#audiostate8) | Yes | Callback used to return the state change. | | callback | [AudioState](#audiostate8) | Yes | Callback used to return the state change. |
**Example:** **Example**
``` ```
audioCapturer.on('stateChange', (state) => { audioCapturer.on('stateChange', (state) => {
......
# Camera<a name="EN-US_TOPIC_0000001149807881"></a> # Camera Management
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** > **NOTE**<br/>
> > The initial APIs of this module are supported since API version 9. API version 9 is a canary release for trial use. The APIs of this version may be unstable.
> The initial APIs of this module are supported since API version 9. The APIs of API version 9 is of the Canary version and are for trial use only. The API call may be unstable.
## Modules to Import ## Modules to Import
...@@ -12,25 +11,22 @@ import camera from '@ohos.multimedia.camera'; ...@@ -12,25 +11,22 @@ import camera from '@ohos.multimedia.camera';
## Required Permissions ## Required Permissions
```
ohos.permission.CAMERA ohos.permission.CAMERA
```
## getCameraManager(context: Context, callback: AsyncCallback<CameraManager\>): void;
**System Capabilities:** ## camera.getCameraManager
SystemCapability.Multimedia.Camera.Core getCameraManager(context: Context, callback: AsyncCallback<CameraManager\>): void
**Description** Obtains a **CameraManager** instance. This API uses an asynchronous callback to return the result.
Gets a **CameraManager** instance. This method uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|----------|-------------------------------|-----------|-----------------------------------------------------| | -------- | ----------------------------------------------- | ---- | ---------------------------------- |
| context | Context | Yes | Application context | | context | Context | Yes | Application context. |
| callback | AsyncCallback<CameraManager\> | Yes | Callback used to return the CameraManager instance | | callback | AsyncCallback<[CameraManager](#cameramanager)\> | Yes | Callback used to return the **CameraManager** instance.|
**Example** **Example**
...@@ -44,116 +40,105 @@ camera.getCameraManager(context, (err, cameraManager) => { ...@@ -44,116 +40,105 @@ camera.getCameraManager(context, (err, cameraManager) => {
}); });
``` ```
## getCameraManager(context: Context): Promise<CameraManager\>; ## camera.getCameraManager
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core getCameraManager(context: Context): Promise<CameraManager\>
**Description** Obtains a **CameraManager** instance. This API uses a promise to return the result.
Gets a **CameraManager** instance. This method uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|----------|----------------------|-----------|----------------------------| | ------- | ------- | ---- | ------------ |
| context | Context | Yes | Application context | | context | Context | Yes | Application context.|
**Return values** **Return value**
| Type | Description | | Type | Description |
|-------------------------|--------------------------------------------------------| | ----------------------------------------- | ----------------------------------------- |
| Promise<CameraManager\> | Promise used to return the **CameraManager** instance | | Promise<[CameraManager](#cameramanager)\> | Promise used to return the **CameraManager** instance.|
**Example** **Example**
``` ```
camera.getCameraManager(context).then((cameraManger) => { camera.getCameraManager(context).then((cameraManager) => {
console.log('Promise returned with the CameraManager instance.'); console.log('Promise returned with the CameraManager instance.');
}) })
``` ```
## CameraStatus<a name="section_camera_status"></a> ## CameraStatus
Enumerates camera status types. Enumerates the camera statuses.
**System Capabilities:** **System capability**: SystemCapability.Multimedia.Camera.Core
SystemCapability.Multimedia.Camera.Core | Name | Default Value| Description |
| ------------------------- | ------ | ------------ |
| CAMERA_STATUS_APPEAR | 0 | The camera exists. |
| CAMERA_STATUS_DISAPPEAR | 1 | The camera does not exist.|
| CAMERA_STATUS_AVAILABLE | 2 | The camera is ready. |
| CAMERA_STATUS_UNAVAILABLE | 3 | The camera is not ready.|
| Name | Default Value | Description |
|---------------------------|---------------|--------------------|
| CAMERA_STATUS_APPEAR | 0 | Camera appear |
| CAMERA_STATUS_DISAPPEAR | 1 | Camera disappear |
| CAMERA_STATUS_AVAILABLE | 2 | Camera available |
| CAMERA_STATUS_UNAVAILABLE | 3 | Camera unavailable |
## CameraPosition
## CameraPosition<a name="section_camera_position"></a>
Enumerates the camera positions. Enumerates the camera positions.
**System Capabilities:** **System capability**: SystemCapability.Multimedia.Camera.Core
SystemCapability.Multimedia.Camera.Core
| Name | Default value | Description | | Name | Default Value| Description |
|-----------------------------|---------------|-----------------------| | --------------------------- | ------ | ---------------- |
| CAMERA_POSITION_UNSPECIFIED | 0 | Unspecified position | | CAMERA_POSITION_UNSPECIFIED | 0 | Unspecified position.|
| CAMERA_POSITION_BACK | 1 | Rear camera | | CAMERA_POSITION_BACK | 1 | Rear camera. |
| CAMERA_POSITION_FRONT | 2 | Front camera | | CAMERA_POSITION_FRONT | 2 | Front camera. |
## CameraType<a name="section_camera_type"></a> ## CameraType
Enumerates the camera types. Enumerates the camera types.
**System Capabilities:** **System capability**: SystemCapability.Multimedia.Camera.Core
SystemCapability.Multimedia.Camera.Core | Name | Default Value| Description |
| ----------------------- | ------ | ---------------- |
| CAMERA_TYPE_UNSPECIFIED | 0 | Unspecified camera type.|
| CAMERA_TYPE_WIDE_ANGLE | 1 | Wide camera. |
| CAMERA_TYPE_ULTRA_WIDE | 2 | Ultra wide camera. |
| CAMERA_TYPE_TELEPHOTO | 3 | Telephoto camera. |
| CAMERA_TYPE_TRUE_DEPTH | 4 | True depth camera. |
| Name | Default value | Description |
|-------------------------|---------------|-------------------------|
| CAMERA_TYPE_UNSPECIFIED | 0 | Unspecified camera type |
| CAMERA_TYPE_WIDE_ANGLE | 1 | Wide camera |
| CAMERA_TYPE_ULTRA_WIDE | 2 | Ultra wide camera |
| CAMERA_TYPE_TELEPHOTO | 3 | Telephoto camera |
| CAMERA_TYPE_TRUE_DEPTH | 4 | True depth camera |
## ConnectionType
## ConnectionType<a name="section_ConnectionType"></a> Enumerates the camera connection types.
Enumerates camera connection types. **System capability**: SystemCapability.Multimedia.Camera.Core
**System Capabilities:** | Name | Default Value| Description |
| ---------------------------- | ------ | ------------- |
| CAMERA_CONNECTION_BUILT_IN | 0 | Built-in camera. |
| CAMERA_CONNECTION_USB_PLUGIN | 1 | Camera connected using USB.|
| CAMERA_CONNECTION_REMOTE | 2 | Remote camera. |
SystemCapability.Multimedia.Camera.Core
| Name | Default value | Description | ## CameraManager
|------------------------------|---------------|----------------------------|
| CAMERA_CONNECTION_BUILT_IN | 0 | Built-in camera |
| CAMERA_CONNECTION_USB_PLUGIN | 1 | Camera connected using USB |
| CAMERA_CONNECTION_REMOTE | 2 | Remote camera |
## CameraManager<a name="section_CameraManager"></a> Implements camera management. Before calling any API in **CameraManager**, you must use **getCameraManager** to obtain a **CameraManager** instance.
Implements camera management, including getting supported cameras and creating **CameraInput** instances. ### getCameras
### getCameras(callback: AsyncCallback<Array<Camera\>\>): void; getCameras(callback: AsyncCallback<Array<Camera\>\>): void
**System Capabilities:** Obtains all cameras supported by the device. This API uses an asynchronous callback to return the array of supported cameras.
SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Description**
Gets all cameras supported by the device. This method uses an asynchronous callback to return the array of supported cameras.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|----------|--------------------------------|-----------|---------------------------------------------------------| | -------- | ----------------------------------------- | ---- | ------------------------------------ |
| callback | AsyncCallback<Array<Camera\>\> | Yes | Callback used to return the array of supported cameras. | | callback | AsyncCallback<Array<[Camera](#camera)\>\> | Yes | Callback used to return the array of supported cameras.|
**Example** **Example**
...@@ -167,21 +152,19 @@ cameraManager.getCameras((err, cameras) => { ...@@ -167,21 +152,19 @@ cameraManager.getCameras((err, cameras) => {
}) })
``` ```
### getCameras(): Promise<Array<Camera\>\>; ### getCameras
**System Capabilities:** getCameras(): Promise<Array<Camera\>\>
SystemCapability.Multimedia.Camera.Core Obtains all cameras supported by the device. This API uses a promise to return the array of supported cameras.
**Description** **System capability**: SystemCapability.Multimedia.Camera.Core
Gets all cameras supported by the device. This method uses a promise to return the array of supported cameras. **Return value**
**Return values** | Type | Description |
| ----------------------------------- | ----------------------------- |
| Type | Description | | Promise<Array<[Camera](#camera)\>\> | Promise used to return the array of supported cameras.|
|------------------------|--------------------------------------------------------|
| Promise<Array<Camera\>\> | Promise used to return an array of supported cameras |
**Example** **Example**
...@@ -192,22 +175,20 @@ cameraManager.getCameras().then((cameraArray) => { ...@@ -192,22 +175,20 @@ cameraManager.getCameras().then((cameraArray) => {
}) })
``` ```
### createCameraInput(cameraId: string, callback: AsyncCallback<CameraInput\>): void; ### createCameraInput
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core createCameraInput(cameraId: string, callback: AsyncCallback<CameraInput\>): void
**Description** Creates a **CameraInput** instance with the specified camera ID. This API uses an asynchronous callback to return the instance.
Creates a **CameraInput** instance with the specified camera ID. This method uses an asynchronous callback to return the instance. **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Default value | Mandatory | Description | | Name | Default Value | Mandatory| Description |
|----------|------------------------------|-----------|--------------------------------------------------| | -------- | ------------------------------------------- | ---- | ----------------------------------- |
| cameraId | string | Yes | Camera ID used to create the instance | | cameraId | string | Yes | Camera ID used to create the instance. |
| callback | AsyncCallback<CameraInput\> | Yes | Callback used to return the CameraInput instance | | callback | AsyncCallback<[CameraInput](#camerainput)\> | Yes | Callback used to return the **CameraInput** instance.|
**Example** **Example**
...@@ -221,27 +202,25 @@ cameraManager.createCameraInput(cameraId, (err, cameraInput) => { ...@@ -221,27 +202,25 @@ cameraManager.createCameraInput(cameraId, (err, cameraInput) => {
}) })
``` ```
### createCameraInput(cameraId: string): Promise<CameraInput\>; ### createCameraInput
**System Capabilities:** createCameraInput(cameraId: string): Promise<CameraInput\>
SystemCapability.Multimedia.Camera.Core Creates a **CameraInput** instance with the specified camera ID. This API uses a promise to return the instance.
**Description** **System capability**: SystemCapability.Multimedia.Camera.Core
Creates a **CameraInput** instance with the specified camera ID. This method uses a promise to return the instance.
**Parameters** **Parameters**
| Name | Default value | Mandatory | Description | | Name | Default Value| Mandatory| Description |
|----------|-----------------------------|-----------|------------------------------------------| | -------- | ------ | ---- | ------------ |
| cameraId | string | Yes | Camera ID used to create the instance | | cameraId | string | Yes | Camera ID used to create the instance.|
**Return values** **Return value**
| Type | Description | | Type | Description |
|-------------------------|-------------------------------------------------| | ------------------------------------- | ---------------------------------------- |
| Promise<CameraInput\> | Promise used to return the CameraInput instance | | Promise<[CameraInput](#camerainput)\> | Promise used to return the **CameraInput** instance.|
**Example** **Example**
...@@ -251,23 +230,21 @@ cameraManager.createCameraInput(cameraId).then((cameraInput) => { ...@@ -251,23 +230,21 @@ cameraManager.createCameraInput(cameraId).then((cameraInput) => {
}) })
``` ```
### createCameraInput(position: CameraPosition, type: CameraType, callback: AsyncCallback<CameraInput\>): void; ### createCameraInput
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core createCameraInput(position: CameraPosition, type: CameraType, callback: AsyncCallback<CameraInput\>): void
**Description** Creates a **CameraInput** instance with the specified camera position and camera type. This API uses an asynchronous callback to return the instance.
Creates a **CameraInput** instance with the specified camera position and camera type. This method uses an asynchronous callback to return the instance. **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|----------|-----------------------------|-----------|---------------------------------------------------| | -------- | ------------------------------------------- | ---- | ----------------------------------- |
| position | CameraPosition | Yes | Camera position | | position | [CameraPosition](#cameraposition) | Yes | Camera position. |
| type | CameraType | Yes | Camera type | | type | [CameraType](#cameratype) | Yes | Camera type. |
| callback | AsyncCallback<CameraInput\> | Yes | Callback used to return the CameraInput instance | | callback | AsyncCallback<[CameraInput](#camerainput)\> | Yes | Callback used to return the **CameraInput** instance.|
**Example** **Example**
...@@ -281,28 +258,26 @@ cameraManager.createCameraInput(cameraPosition, cameraType, (err, cameraInput) = ...@@ -281,28 +258,26 @@ cameraManager.createCameraInput(cameraPosition, cameraType, (err, cameraInput) =
}) })
``` ```
### createCameraInput(position: CameraPosition, type: CameraType): Promise<CameraInput\>; ### createCameraInput
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core createCameraInput(position: CameraPosition, type: CameraType): Promise<CameraInput\>
**Description** Creates a **CameraInput** instance with the specified camera position and camera type. This API uses a promise to return the instance.
Creates a **CameraInput** instance with the specified camera position and camera type. This method uses a promise to return the instance. **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|----------|----------------------------|-----------|----------------------------------------| | -------- | --------------------------------- | ---- | ---------- |
| position | CameraPosition | Yes | Camera position | | position | [CameraPosition](#cameraposition) | Yes | Camera position.|
| type | CameraType | Yes | Camera type | | type | [CameraType](#cameratype) | Yes | Camera type.|
**Return values** **Return value**
| Type | Description | | Type | Description |
|-------------------------|-------------------------------------------------| | ------------------------------------- | ---------------------------------------- |
| Promise<CameraInput\> | Promise used to return the CameraInput instance | | Promise<[CameraInput](#camerainput)\> | Promise used to return the **CameraInput** instance.|
**Example** **Example**
...@@ -312,22 +287,20 @@ cameraManager.createCameraInput(cameraPosition, cameraType).then((cameraInput) = ...@@ -312,22 +287,20 @@ cameraManager.createCameraInput(cameraPosition, cameraType).then((cameraInput) =
}) })
``` ```
### on(type: 'cameraStatus', callback: Callback<CameraStatusInfo\>): void; ### on('cameraStatus')
**System Capabilities:** on(type: 'cameraStatus', callback: AsyncCallback<CameraStatusInfo\>): void
SystemCapability.Multimedia.Camera.Core Listens for camera status changes. This API uses a callback to return the camera status changes.
**Description** **System capability**: SystemCapability.Multimedia.Camera.Core
Listens for camera status changes. This method uses a callback to get camera status changes.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :--------------------- | :-------- | :--------------------------------------------------- | | :------- | :---------------------------------------------------- | :--- | :--------------------------------------------------- |
| type | string | Yes | Camera status event. | | type | string | Yes | Type of event to listen for. The value is fixed at **cameraStatus**, indicating the camera status change event.|
| callback | Callback<CameraStatusInfo\> | Yes | Callback used to get the camera status change. | | callback | AsyncCallback<[CameraStatusInfo](#camerastatusinfo)\> | Yes | Callback used to return the camera status change. |
**Example** **Example**
...@@ -338,22 +311,20 @@ cameraManager.on('cameraStatus', (cameraStatusInfo) => { ...@@ -338,22 +311,20 @@ cameraManager.on('cameraStatus', (cameraStatusInfo) => {
}) })
``` ```
## Camera<a name="section_Camera"></a> ## Camera
when we call *cameraManager.getCameras()* API, then it will return the **Camera** class which will have all camera-related metadata such as *cameraId, cameraPosition, cameraType & connectionType*.
**System Capabilities:** After **[camera.getCameraManager](#cameragetcameramanager)** is called, a camera instance is returned, including camera-related metadata such as **cameraId**, **cameraPosition**, **cameraType**, and **connectionType**.
SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Fields** | Name | Type | Read only| Description |
| -------------- | --------------------------------- | ---- | -------------- |
| cameraId | string | Yes | Camera ID. |
| cameraPosition | [CameraPosition](#cameraposition) | Yes | Camera position. |
| cameraType | [CameraType](#cameratype) | Yes | Camera type. |
| connectionType | [ConnectionType](#connectiontype) | Yes | Camera connection type.|
| Name | Type | Access | Description | **Example**
|----------------|----------------|----------|------------------------|
| cameraId | string | readonly | Camera ID |
| cameraPosition | cameraPosition | readonly | Camera position |
| cameraType | cameraType | readonly | Camera type |
| connectionType | connectionType | readonly | Camera connection type |
``` ```
async function getCameraInfo() { async function getCameraInfo() {
...@@ -368,41 +339,37 @@ async function getCameraInfo() { ...@@ -368,41 +339,37 @@ async function getCameraInfo() {
``` ```
## CameraStatusInfo<a name="section_Camera"></a> ## CameraStatusInfo
This interface is a CameraManager callback API return. **CameraStatusInfo** will have *Camera* class & *CameraStatus* predefine constants.From *Camera* class, we can have all camera-related metadata & from *CameraStatus* constants, we will have information such as *APPEAR, DISAPPEAR, AVAILABLE & UNAVAILABLE*.
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
**Fields** Describes the camera status information.
| Name | Type | Description | **System capability**: SystemCapability.Multimedia.Camera.Core
|----------------|----------------|------------------|
| camera | Camera | Camera object |
| status | CameraStatus | Camera status |
| Name | Type | Description |
| ------ | ----------------------------- | ---------- |
| camera | [Camera](#camera) | Camera object. |
| status | [CameraStatus](#camerastatus) | Camera status. |
## CameraInput<a name="section_CameraInput"></a>
Implements a **CameraInput** instance. ## CameraInput
### getCameraId(callback: AsyncCallback<string\>\): void; Implements a **CameraInput** instance. Before calling any API in **CameraInput**, you must create a **CameraInput** instance.
**System Capabilities:** ### getCameraId
SystemCapability.Multimedia.Camera.Core getCameraId(callback: AsyncCallback<string\>\): void
**Description** Obtains the camera ID based on which this **CameraInput** instance is created. This API uses an asynchronous callback to return the camera ID.
Gets the camera ID based on which this **CameraInput** instance is created. This method uses an asynchronous callback to return the camera ID. **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
|----------|------------------------|-----------|---------------------------------------| | -------- | ---------------------- | ---- | -------------------------- |
| callback | AsyncCallback<string\> | Yes | Callback used to return the camera ID | | callback | AsyncCallback<string\> | Yes | Callback used to return the camera ID. |
**Example**
``` ```
cameraInput.getCameraId((err, cameraId) => { cameraInput.getCameraId((err, cameraId) => {
...@@ -414,21 +381,19 @@ cameraInput.getCameraId((err, cameraId) => { ...@@ -414,21 +381,19 @@ cameraInput.getCameraId((err, cameraId) => {
}) })
``` ```
### getCameraId(): Promise<string\>; ### getCameraId
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core getCameraId(): Promise<string\>
**Description** Obtains the camera ID based on which this **CameraInput** instance is created. This API uses a promise to return the camera ID.
Gets the camera ID based on which this **CameraInput** instance is created. This method uses a promise to return the camera ID. **System capability**: SystemCapability.Multimedia.Camera.Core
**Return values** **Return value**
| Type | Description | | Type | Description |
|------------------------|--------------------------------------| | ---------------- | ----------------------------- |
| Promise<string\> | Promise used to return the camera ID | | Promise<string\> | Promise used to return the camera ID.|
**Example** **Example**
...@@ -438,21 +403,20 @@ cameraInput.getCameraId().then((cameraId) => { ...@@ -438,21 +403,20 @@ cameraInput.getCameraId().then((cameraId) => {
}) })
``` ```
### hasFlash(callback: AsyncCallback<boolean\>): void; <a name="sec_hasFlash"></a>
**System Capabilities:** ### hasFlash
SystemCapability.Multimedia.Camera.Core hasFlash(callback: AsyncCallback<boolean\>): void
**Description** Checks whether the device has flash light. This API uses an asynchronous callback to return the result.
Checks whether the device has flash light. This method uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|----------|-------------------------|-----------|----------------------------------------------------| | -------- | ----------------------- | ---- | -------------------------------------- |
| callback | AsyncCallback<boolean\> | Yes | Callback used to return the flash light support status | | callback | AsyncCallback<boolean\> | Yes | Callback used to return the flash light support status. The value **true** means that the device has flash light.|
**Example** **Example**
...@@ -466,21 +430,19 @@ cameraInput.hasFlash((err, status) => { ...@@ -466,21 +430,19 @@ cameraInput.hasFlash((err, status) => {
}) })
``` ```
### hasFlash(): Promise<boolean\>; ### hasFlash
**System Capabilities:** hasFlash(): Promise<boolean\>
SystemCapability.Multimedia.Camera.Core Checks whether the device has flash light. This API uses a promise to return the result.
**Description** **System capability**: SystemCapability.Multimedia.Camera.Core
Checks whether the device has flash light. This method uses a promise to return the result. **Return value**
**Return values** | Type | Description |
| ----------------- | ------------------------------------------------------- |
| Type | Description | | Promise<boolean\> | Promise used to return the flash light support status. The value **true** means that the device has flash light.|
|-----------------------|--------------------------------------------------------|
| Promise<boolean\> | Promise used to return the flash light support status |
**Example** **Example**
...@@ -490,22 +452,20 @@ cameraInput.hasFlash().then((status) => { ...@@ -490,22 +452,20 @@ cameraInput.hasFlash().then((status) => {
}) })
``` ```
### isFlashModeSupported(flashMode: FlashMode, callback: AsyncCallback<boolean\>): void; <a name="sec_isFlashModeSupported"></a> ### isFlashModeSupported
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core isFlashModeSupported(flashMode: FlashMode, callback: AsyncCallback<boolean\>): void
**Description** Checks whether a specified flash mode is supported. This API uses an asynchronous callback to return the result.
Checks whether a specified flash mode is supported. This method uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|-----------|------------------------|-----------|----------------------------------------------------| | --------- | ----------------------- | ---- | ---------------------------------------- |
| flashMode | <a href="#sec_FlashMode">FlashMode</a> | Yes | Flash mode | | flashMode | [FlashMode](#flashmode) | Yes | Flash mode. |
| callback | AsyncCallback<boolean\> | Yes | Callback used to return the device flash support status | | callback | AsyncCallback<boolean\> | Yes | Callback used to return the flash mode support status. The value **true** means that the specified flash mode is supported.|
**Example** **Example**
...@@ -519,27 +479,25 @@ cameraInput.isFlashModeSupported(flashMode, (err, status) => { ...@@ -519,27 +479,25 @@ cameraInput.isFlashModeSupported(flashMode, (err, status) => {
}) })
``` ```
### isFlashModeSupported(flashMode: FlashMode): Promise<boolean\>; ### isFlashModeSupported
**System Capabilities:** isFlashModeSupported(flashMode: FlashMode): Promise<boolean\>
SystemCapability.Multimedia.Camera.Core Checks whether a specified flash mode is supported. This API uses a promise to return the result.
**Description** **System capability**: SystemCapability.Multimedia.Camera.Core
Checks whether a specified flash mode is supported. This method uses a promise to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|-----------|------------------------|-----------|----------------------------------------------------| | --------- | ----------------------- | ---- | ---------------- |
| flashMode | <a href="#sec_FlashMode">FlashMode</a> | Yes | Flash mode | | flashMode | [FlashMode](#flashmode) | Yes | Flash mode.|
**Return values** **Return value**
| Type | Description | | Type | Description |
|-----------------------|---------------------------------------------------| | ----------------- | ------------------------------------------------------------ |
| Promise<boolean\> | Promise used to return flash mode support status. | | Promise<boolean\> | Promise used to return the flash mode support status. The value **true** means that the specified flash mode is supported.|
**Example** **Example**
...@@ -549,24 +507,25 @@ cameraInput.isFlashModeSupported(flashMode).then((status) => { ...@@ -549,24 +507,25 @@ cameraInput.isFlashModeSupported(flashMode).then((status) => {
}) })
``` ```
### setFlashMode(flashMode: FlashMode, callback: AsyncCallback<void\>): void; ### setFlashMode
**System Capabilities:** setFlashMode(flashMode: FlashMode, callback: AsyncCallback<void\>): void
SystemCapability.Multimedia.Camera.Core Sets the flash mode. This API uses an asynchronous callback to return the result.
**Description** Before setting the parameters, do the following checks:
Sets flash mode. This method uses an asynchronous callback to return the result. 1. Use [hasFlash](#hasflash) to check whether the device has flash light.
2. Use [isFlashModeSupported](#isflashmodesupported) to check whether the device supports a specified flash mode.
Note: Before setting the flash mode, check the support for the flash light (<a href="#sec_hasFlash">hasFlash</a> method) and flash mode support (<a href="#sec_isFlashModeSupported">isFlashModeSupported</a> method); **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|-----------|------------------------|-----------|----------------------------------------------------| | --------- | ----------------------- | ---- | ------------------------ |
| flashMode | <a href="#sec_FlashMode">FlashMode</a> | Yes | Flash mode | | flashMode | [FlashMode](#flashmode) | Yes | Flash mode. |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result | | callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example** **Example**
...@@ -580,29 +539,30 @@ cameraInput.setFlashMode(flashMode, (err) => { ...@@ -580,29 +539,30 @@ cameraInput.setFlashMode(flashMode, (err) => {
}) })
``` ```
### setFlashMode(flashMode: FlashMode): Promise<void\>; ### setFlashMode
**System Capabilities:** setFlashMode(flashMode: FlashMode): Promise<void\>
SystemCapability.Multimedia.Camera.Core Sets the flash mode. This API uses a promise to return the result.
**Description** Before setting the parameters, do the following checks:
Sets flash mode. This method uses a promise to return the result. 1. Use [hasFlash](#hasflash) to check whether the device has flash light.
2. Use [isFlashModeSupported](#isflashmodesupported) to check whether the device supports a specified flash mode.
Note: Before setting the flash mode, check the support for the flash light (<a href="#sec_hasFlash">hasFlash</a> method) and flash mode support (<a href="#sec_isFlashModeSupported">isFlashModeSupported</a> method); **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|-----------|------------------------|-----------|----------------------------------------------------| | --------- | ----------------------- | ---- | ---------------- |
| flashMode | <a href="#sec_FlashMode">FlashMode</a> | Yes | Flash mode | | flashMode | [FlashMode](#flashmode) | Yes | Flash mode.|
**Return values** **Return value**
| Type | Description | | Type | Description |
|-----------------------|-----------------------------------------| | -------------- | --------------------------- |
| Promise<void\> | Promise used to return the result | | Promise<void\> | Promise used to return the result.|
**Example** **Example**
...@@ -612,21 +572,19 @@ cameraInput.setFlashMode(flashMode).then(() => { ...@@ -612,21 +572,19 @@ cameraInput.setFlashMode(flashMode).then(() => {
}) })
``` ```
### getFlashMode(callback: AsyncCallback<FlashMode\>): void; ### getFlashMode
**System Capabilities:** getFlashMode(callback: AsyncCallback<FlashMode\>): void
SystemCapability.Multimedia.Camera.Core Obtains the current flash mode. This API uses an asynchronous callback to return the result.
**Description** **System capability**: SystemCapability.Multimedia.Camera.Core
Gets current flash mode. This method uses an asynchronous callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|-----------|---------------------------|-----------|------------------------------------------------| | -------- | --------------------------------------- | ---- | ---------------------------------------- |
| callback | AsyncCallback<FlashMode\> | Yes | Callback used to return the current flash mode | | callback | AsyncCallback<[FlashMode](#flashmode)\> | Yes | Callback used to return the current flash mode.|
**Example** **Example**
...@@ -640,21 +598,19 @@ cameraInput.getFlashMode((err, flashMode) => { ...@@ -640,21 +598,19 @@ cameraInput.getFlashMode((err, flashMode) => {
}) })
``` ```
### getFlashMode(): Promise<FlashMode\>; ### getFlashMode
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core getFlashMode(): Promise<FlashMode\>
**Description** Obtains the current flash mode. This API uses a promise to return the result.
Gets current flash mode. This method uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core
**Return values** **Return value**
| Type | Description | | Type | Description |
|-----------------------|---------------------------------------------------| | --------------------------------- | --------------------------------------- |
| Promise<FlashMode\> | Promise used to return the flash mode | | Promise<[FlashMode](#flashmode)\> | Promise used to return the current flash mode.|
**Example** **Example**
...@@ -664,22 +620,20 @@ cameraInput.getFlashMode().then((flashMode) => { ...@@ -664,22 +620,20 @@ cameraInput.getFlashMode().then((flashMode) => {
}) })
``` ```
### isFocusModeSupported(afMode: FocusMode, callback: AsyncCallback<boolean\>): void; <a name="sec_isFocusModeSupported"></a> ### isFocusModeSupported
**System Capabilities:** isFocusModeSupported(afMode: FocusMode, callback: AsyncCallback<boolean\>): void
SystemCapability.Multimedia.Camera.Core Checks whether a specified focus mode is supported. This API uses an asynchronous callback to return the result.
**Description** **System capability**: SystemCapability.Multimedia.Camera.Core
Checks whether a specified focus mode is supported. This method uses an asynchronous callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|-----------|------------------------|-----------|----------------------------------------------------| | -------- | ----------------------- | ---- | -------------------------------------- |
| afMode | <a href="#sec_FocusMode">FocusMode</a> | Yes | Focus mode | | afMode | [FocusMode](#focusmode) | Yes | Focus mode. |
| callback | AsyncCallback<boolean\> | Yes | Callback used to return the device focus support status | | callback | AsyncCallback<boolean\> | Yes | Callback used to return the focus mode support status. The value **true** means that the specified focus mode is supported.|
**Example** **Example**
...@@ -693,27 +647,25 @@ cameraInput.isFocusModeSupported(afMode, (err, status) => { ...@@ -693,27 +647,25 @@ cameraInput.isFocusModeSupported(afMode, (err, status) => {
}) })
``` ```
### isFocusModeSupported(afMode: FocusMode): Promise<boolean\>; ### isFocusModeSupported
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core isFocusModeSupported(afMode: FocusMode): Promise<boolean\>
**Description** Checks whether a specified focus mode is supported. This API uses a promise to return the result.
Checks whether a specified focus mode is supported. This method uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|-----------|----------------------------------------|-----------|-------------| | ------ | ----------------------- | ---- | ---------------- |
| afMode | <a href="#sec_FocusMode">FocusMode</a> | Yes | Focus mode | | afMode | [FocusMode](#focusmode) | Yes | Focus mode.|
**Return values** **Return value**
| Type | Description | | Type | Description |
|-----------------------|---------------------------------------------------| | ----------------- | ----------------------------------------------------------- |
| Promise<boolean\> | Promise used to return the focus mode support status. | | Promise<boolean\> | Promise used to return the flash mode support status. The value **true** means that the specified focus mode is supported.|
**Example** **Example**
...@@ -723,24 +675,22 @@ cameraInput.isFocusModeSupported(afMode).then((status) => { ...@@ -723,24 +675,22 @@ cameraInput.isFocusModeSupported(afMode).then((status) => {
}) })
``` ```
### setFocusMode(afMode: FocusMode, callback: AsyncCallback<void\>): void; ### setFocusMode
**System Capabilities:** setFocusMode(afMode: FocusMode, callback: AsyncCallback<void\>): void
SystemCapability.Multimedia.Camera.Core Sets the focus mode. This API uses an asynchronous callback to return the result.
**Description** Before setting the focus mode, use **[isFocusModeSupported](#isfocusmodesupported)** to check whether the focus mode is supported.
Sets focus mode. This method uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core
Note: Before setting the focus mode, check focus mode support (<a href="#sec_isFocusModeSupported">isFocusModeSupported</a> method);
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|-----------|------------------------|-----------|------------------------------------| | -------- | ----------------------- | ---- | ------------------------ |
| afMode | <a href="#sec_FocusMode">FocusMode</a> | Yes | Focus mode | | afMode | [FocusMode](#focusmode) | Yes | Focus mode. |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result | | callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example** **Example**
...@@ -754,29 +704,27 @@ cameraInput.setFocusMode(afMode, (err) => { ...@@ -754,29 +704,27 @@ cameraInput.setFocusMode(afMode, (err) => {
}) })
``` ```
### setFocusMode(afMode: FocusMode): Promise<void\>; ### setFocusMode
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core setFocusMode(afMode: FocusMode): Promise<void\>
**Description** Sets the focus mode. This API uses a promise to return the result.
Sets focus mode. This method uses a promise to return the result. Before setting the focus mode, use **[isFocusModeSupported](#isfocusmodesupported)** to check whether the focus mode is supported.
Note: Before setting the focus mode, check focus mode support (<a href="#sec_isFocusModeSupported">isFocusModeSupported</a> method); **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|-----------|-----------------------------------------|-----------|-------------| | ------ | ----------------------- | ---- | ---------------- |
| afMode | <a href="#sec_FocusMode">FocusMode</a> | Yes | Focus mode | | afMode | [FocusMode](#focusmode) | Yes | Focus mode.|
**Return values** **Return value**
| Type | Description | | Type | Description |
|-----------------------|-----------------------------------------| | -------------- | --------------------------- |
| Promise<void\> | Promise used to return the result | | Promise<void\> | Promise used to return the result.|
**Example** **Example**
...@@ -786,21 +734,19 @@ cameraInput.setFocusMode(afMode).then(() => { ...@@ -786,21 +734,19 @@ cameraInput.setFocusMode(afMode).then(() => {
}) })
``` ```
### getFocusMode(callback: AsyncCallback<FocusMode\>): void; ### getFocusMode
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core getFocusMode(callback: AsyncCallback<FocusMode\>): void
**Description** Obtains the current focus mode. This API uses an asynchronous callback to return the result.
Gets the current focus mode. This method uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|-----------|---------------------------|-----------|------------------------------------------------| | -------- | --------------------------------------- | ---- | -------------------------------------- |
| callback | AsyncCallback<FocusMode\> | Yes | Callback used to return the current focus mode | | callback | AsyncCallback<[FocusMode](#focusmode)\> | Yes | Callback used to return the current focus mode.|
**Example** **Example**
...@@ -814,21 +760,19 @@ cameraInput.getFocusMode((err, afMode) => { ...@@ -814,21 +760,19 @@ cameraInput.getFocusMode((err, afMode) => {
}) })
``` ```
### getFocusMode(): Promise<FocusMode\>; ### getFocusMode
**System Capabilities:** getFocusMode(): Promise<FocusMode\>
SystemCapability.Multimedia.Camera.Core Obtains the current focus mode. This API uses a promise to return the result.
**Description** **System capability**: SystemCapability.Multimedia.Camera.Core
Gets the current focus mode. This method uses a promise to return the result. **Return value**
**Return values** | Type | Description |
| ------------------- | ------------------------------------- |
| Type | Description | | Promise<FocusMode\> | Promise used to return the current focus mode.|
|-----------------------|---------------------------------------------------|
| Promise<FocusMode\> | Promise used to return the focus mode |
**Example** **Example**
...@@ -838,21 +782,19 @@ cameraInput.getFocusMode().then((afMode) => { ...@@ -838,21 +782,19 @@ cameraInput.getFocusMode().then((afMode) => {
}) })
``` ```
### getZoomRatioRange\(callback: AsyncCallback<Array<number\>\>\): void; ### getZoomRatioRange
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core getZoomRatioRange\(callback: AsyncCallback<Array<number\>\>\): void
**Description** Obtains the zoom ratio range. This API uses an asynchronous callback to return the result.
Gets the zoom ratios of all zoom values. This method uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|----------|--------------------------------|-----------|-------------------------------------------------| | -------- | ------------------------------ | ---- | ------------------------ |
| callback | AsyncCallback<Array<number\>\> | Yes | Callback used to return the zoom ratio range | | callback | AsyncCallback<Array<number\>\> | Yes | Callback used to return the zoom ratio range.|
**Example** **Example**
...@@ -866,21 +808,19 @@ cameraInput.getZoomRatioRange((err, zoomRatioRange) => { ...@@ -866,21 +808,19 @@ cameraInput.getZoomRatioRange((err, zoomRatioRange) => {
}) })
``` ```
### getZoomRatioRange\(\): Promise<Array<number\>\>; ### getZoomRatioRange
**System Capabilities:** getZoomRatioRange\(\): Promise<Array<number\>\>
SystemCapability.Multimedia.Camera.Core Obtains the zoom ratio range. This API uses a promise to return the result.
**Description** **System capability**: SystemCapability.Multimedia.Camera.Core
Gets the zoom ratios of all zoom values. This method uses a promise to return the result. **Return value**
**Return values** | Type | Description |
| ------------------------ | ------------------------------------------- |
| Type | Description | | Promise<Array<number\>\> | Promise used to return the zoom ratio range.|
|------------------------|---------------------------------------------|
| Promise<Array<number\>\> | Promise used to return the zoom ratio range |
**Example** **Example**
...@@ -890,22 +830,20 @@ cameraInput.getZoomRatioRange().then((zoomRatioRange) => { ...@@ -890,22 +830,20 @@ cameraInput.getZoomRatioRange().then((zoomRatioRange) => {
}) })
``` ```
### setZoomRatio(zoomRatio: number, callback: AsyncCallback<void\>): void; ### setZoomRatio
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core setZoomRatio(zoomRatio: number, callback: AsyncCallback<void\>): void
**Description** Sets a zoom ratio. This API uses an asynchronous callback to return the result.
Sets a zoom ratio. This method uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|-----------|------------------------|-----------|------------------------------------| | --------- | -------------------- | ---- | ------------------------ |
| zoomRatio | number | Yes | Zoom ratio | | zoomRatio | number | Yes | Zoom ratio to set. |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result | | callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example** **Example**
...@@ -919,27 +857,25 @@ cameraInput.setZoomRatio(zoomRatio, (err) => { ...@@ -919,27 +857,25 @@ cameraInput.setZoomRatio(zoomRatio, (err) => {
}) })
``` ```
### setZoomRatio(zoomRatio: number): Promise<void\>; ### setZoomRatio
**System Capabilities:** setZoomRatio(zoomRatio: number): Promise<void\>
SystemCapability.Multimedia.Camera.Core Sets a zoom ratio. This API uses a promise to return the result.
**Description** **System capability**: SystemCapability.Multimedia.Camera.Core
Sets a zoom ratio. This method uses a promise to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|-----------|----------|-----------|-------------| | --------- | ------ | ---- | ------------ |
| zoomRatio | number | Yes | zoom ratio | | zoomRatio | number | Yes | Zoom ratio to set.|
**Return values** **Return value**
| Type | Description | | Type | Description |
|-----------------------|-----------------------------------------| | -------------- | --------------------------- |
| Promise<void\> | Promise used to return the result | | Promise<void\> | Promise used to return the result.|
**Example** **Example**
...@@ -949,21 +885,19 @@ cameraInput.setZoomRatio(zoomRatio).then(() => { ...@@ -949,21 +885,19 @@ cameraInput.setZoomRatio(zoomRatio).then(() => {
}) })
``` ```
### getZoomRatio(callback: AsyncCallback<number\>): void; ### getZoomRatio
**System Capabilities:** getZoomRatio(callback: AsyncCallback<number\>): void
SystemCapability.Multimedia.Camera.Core Obtains the current zoom ratio. This API uses an asynchronous callback to return the result.
**Description** **System capability**: SystemCapability.Multimedia.Camera.Core
Gets current zoom ratio value. This method uses an asynchronous callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|-----------|---------------------------|-----------|------------------------------------------------------| | -------- | ---------------------- | ---- | ------------------------ |
| callback | AsyncCallback<number\> | Yes | Callback used to return the current zoom ratio value | | callback | AsyncCallback<number\> | Yes | Callback used to return the current zoom ratio.|
**Example** **Example**
...@@ -977,21 +911,19 @@ cameraInput.getZoomRatio((err, zoomRatio) => { ...@@ -977,21 +911,19 @@ cameraInput.getZoomRatio((err, zoomRatio) => {
}) })
``` ```
### getZoomRatio(): Promise<number\>; ### getZoomRatio
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core getZoomRatio(): Promise<number\>
**Description** Obtains the current zoom ratio. This API uses a promise to return the result.
Gets current zoom ratio value. This method uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core
**Return values** **Return value**
| Type | Description | | Type | Description |
|-----------------------|---------------------------------------------------| | ---------------- | --------------------------- |
| Promise<number\> | Promise used to return the zoom ratio vaule | | Promise<number\> | Promise used to return the current zoom ratio.|
**Example** **Example**
...@@ -1001,26 +933,24 @@ cameraInput.getZoomRatio().then((zoomRatio) => { ...@@ -1001,26 +933,24 @@ cameraInput.getZoomRatio().then((zoomRatio) => {
}) })
``` ```
### release\(callback: AsyncCallback<void\>\): void; ### release
**System Capabilities:** release\(callback: AsyncCallback<void\>\): void
SystemCapability.Multimedia.Camera.Core Releases this **CameraInput** instance. This API uses an asynchronous callback to return the result.
**Description** **System capability**: SystemCapability.Multimedia.Camera.Core
Releases this **CameraInput** instance. This method uses an asynchronous callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|----------|----------------------|-----------|------------------------------------| | -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result | | callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example** **Example**
``` ```
cameraInput.release((err) => { camera.release((err) => {
if (err) { if (err) {
console.error('Failed to release the CameraInput instance ${err.message}'); console.error('Failed to release the CameraInput instance ${err.message}');
return; return;
...@@ -1029,21 +959,19 @@ cameraInput.release((err) => { ...@@ -1029,21 +959,19 @@ cameraInput.release((err) => {
}); });
``` ```
### release(): Promise<void\>; ### release
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core release(): Promise<void\>
**Description** Releases this **CameraInput** instance. This API uses a promise to return the result.
Releases this **CameraInput** instance. This method uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core
**Return values** **Return value**
| Type | Description | | Type | Description |
|----------------|---------------------------------------------| | -------------- | --------------------------- |
| Promise<void\> | Promise used to return the result | | Promise<void\> | Promise used to return the result.|
**Example** **Example**
...@@ -1053,22 +981,20 @@ cameraInput.release().then(() => { ...@@ -1053,22 +981,20 @@ cameraInput.release().then(() => {
}) })
``` ```
### on(type: 'focusStateChange', callback: Callback<FocusState\>): void; ### on('focusStateChange')
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core on(type: 'focusStateChange', callback: AsyncCallback<FocusState\>): void
**Description** Listens for focus state changes. This API uses a callback to return the focus state changes.
Listens for focus state changes. This method uses a callback to get focus state changes. **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :--------------------- | :-------- | :-----------------------------------------------| | :------- | :---------------------------------------- | :--- | :------------------------------------------------------- |
| type | string | Yes | Name of the event to listen for. | | type | string | Yes | Type of event to listen for. The value is fixed at **focusStateChange**, indicating the focus state change event.|
| callback | Callback<FocusState\> | Yes | Callback used to get the focus state change. | | callback | AsyncCallback<[FocusState](#focusstate)\> | Yes | Callback used to return the focus state change. |
**Example** **Example**
...@@ -1078,22 +1004,20 @@ cameraInput.on('focusStateChange', (focusState) => { ...@@ -1078,22 +1004,20 @@ cameraInput.on('focusStateChange', (focusState) => {
}) })
``` ```
### on(type: 'error', callback: Callback<CameraInputError\>): void; ### on('error')
**System Capabilities:** on(type: 'error', callback: ErrorCallback<CameraInputError\>): void
SystemCapability.Multimedia.Camera.Core Listens for **CameraInput** errors. This API uses a callback to return the errors.
**Description** **System capability**: SystemCapability.Multimedia.Camera.Core
Listens for **CameraInput** errors. This method uses a callback to get errors.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :--------------------- | :-------- | :-----------------------------------------------| | :------- | :------------------------------- | :--- | :---------------------------------------------- |
| type | string | Yes | Camera input error event. | | type | string | Yes | Type of event to listen for. The value is fixed at **error**, indicating the camera input error event.|
| callback | Callback<CameraInputError\> | Yes | Callback used to get the camera input errors. | | callback | ErrorCallback<CameraInputError\> | Yes | Callback used to return the result. |
**Example** **Example**
...@@ -1103,57 +1027,64 @@ cameraInput.on('error', (cameraInputError) => { ...@@ -1103,57 +1027,64 @@ cameraInput.on('error', (cameraInputError) => {
}) })
``` ```
## FlashMode <a name="sec_FlashMode"></a>
Enumerates the flash modes. ## FlashMode
**System Capabilities:** Enumerates the flash modes.
SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Default value | Description | | Name | Default Value| Description |
|------------------------|---------------|------------------------| | ---------------------- | ------ | ------------ |
| FLASH_MODE_CLOSE | 0 | Flash mode close | | FLASH_MODE_CLOSE | 0 | The flash is off.|
| FLASH_MODE_OPEN | 1 | Flash mode open | | FLASH_MODE_OPEN | 1 | The flash is on.|
| FLASH_MODE_AUTO | 2 | Flash mode auto | | FLASH_MODE_AUTO | 2 | The flash mode is auto, indicating that the flash fires automatically depending on the shooting conditions.|
| FLASH_MODE_ALWAYS_OPEN | 3 | Flash mode always open | | FLASH_MODE_ALWAYS_OPEN | 3 | The flash is steady on.|
## FocusMode <a name="sec_FocusMode"></a> ## FocusMode
Enumerates the focus modes. Enumerates the focus modes.
**System Capabilities:** **System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Default Value| Description |
| -------------------------- | ------ | ------------------ |
| FOCUS_MODE_MANUAL | 0 | Manual focus. |
| FOCUS_MODE_CONTINUOUS_AUTO | 1 | Continuous auto focus.|
| FOCUS_MODE_AUTO | 2 | Auto focus. |
| FOCUS_MODE_LOCKED | 3 | Locked focus. |
SystemCapability.Multimedia.Camera.Core ## FocusState
| Name | Default value | Description | Enumerates the focus states.
|----------------------------|---------------|----------------------------|
| FOCUS_MODE_MANUAL | 0 | Focus mode manual |
| FOCUS_MODE_CONTINUOUS_AUTO | 1 | Focus mode continuous auto |
| FOCUS_MODE_AUTO | 2 | Focus mode auto |
| FOCUS_MODE_LOCKED | 3 | Focus mode locked |
## createCaptureSession\(context: Context, callback: AsyncCallback<CaptureSession\>\): void; **System capability**: SystemCapability.Multimedia.Camera.Core
**System Capabilities:** | Name | Default Value| Description |
| --------------------- | ------ | ------------ |
| FOCUS_STATE_SCAN | 0 | Scanning. |
| FOCUS_STATE_FOCUSED | 1 | Focused.|
| FOCUS_STATE_UNFOCUSED | 2 | Unfocused.|
SystemCapability.Multimedia.Camera.Core ## camera.createCaptureSession
**Description** createCaptureSession\(context: Context, callback: AsyncCallback<CaptureSession\>\): void
Creates a **CaptureSession** instance. This method uses an asynchronous callback to return the instance. Creates a **CaptureSession** instance. This API uses an asynchronous callback to return the instance.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|----------|--------------------------------|-----------|-----------------------------------------------------| | -------- | ------------------------------------------------- | ---- | -------------------------------------- |
| context | Context | Yes | Application context | | context | Context | Yes | Application context. |
| callback | AsyncCallback<CaptureSession\> | Yes | Callback used to return the CaptureSession instance | | callback | AsyncCallback<[CaptureSession](#capturesession)\> | Yes | Callback used to return the **CaptureSession** instance.|
**Example** **Example**
``` ```
captureSession.createCaptureSession((context), (err, captureSession) => { camera.createCaptureSession((context), (err, captureSession) => {
if (err) { if (err) {
console.error('Failed to create the CaptureSession instance. ${err.message}'); console.error('Failed to create the CaptureSession instance. ${err.message}');
return; return;
...@@ -1162,55 +1093,51 @@ captureSession.createCaptureSession((context), (err, captureSession) => { ...@@ -1162,55 +1093,51 @@ captureSession.createCaptureSession((context), (err, captureSession) => {
}); });
``` ```
## createCaptureSession(context: Context\): Promise<CaptureSession\>; ## camera.createCaptureSession
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core createCaptureSession(context: Context\): Promise<CaptureSession\>;
**Description** Creates a **CaptureSession** instance. This API uses a promise to return the instance.
Creates a **CaptureSession** instance. This method uses a promise to return the instance. **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|----------|-------------------------------|-----------|-----------------------------------------------------| | ------- | ------- | ---- | ------------ |
| context | Context | Yes | Application context | | context | Context | Yes | Application context.|
**Return values** **Return value**
| Type | Description | | Type | Description |
|---------------------------|---------------------------------------------------| | ------------------------------------------- | ----------------------------------------- |
| Promise<CaptureSession\> | Promise used to return the CaptureSession instance. | | Promise<[CaptureSession](#capturesession)\> | Promise used to return the **CaptureSession** instance.|
**Example** **Example**
``` ```
captureSession.createCaptureSession(context).then((captureSession) => { camera.createCaptureSession(context).then((captureSession) => {
console.log('Promise returned with the CaptureSession instance'); console.log('Promise returned with the CaptureSession instance');
}) })
``` ```
## CaptureSession<a name="sec_CaptureSession"></a> ## CaptureSession
Implements session capture. Implements session capture.
### beginConfig\(callback: AsyncCallback<void\>\): void;<a name="section84581011418"></a> ### beginConfig
**System Capabilities:** beginConfig\(callback: AsyncCallback<void\>\): void
SystemCapability.Multimedia.Camera.Core Starts configuration for this **CaptureSession** instance. This API uses an asynchronous callback to return the result.
**Description** **System capability**: SystemCapability.Multimedia.Camera.Core
Starts configuration for this CaptureSession instance. This method uses an asynchronous callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|----------|----------------------|-----------|----------------------------------------------| | -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result | | callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example** **Example**
...@@ -1224,21 +1151,19 @@ captureSession.beginConfig((err) => { ...@@ -1224,21 +1151,19 @@ captureSession.beginConfig((err) => {
}); });
``` ```
### beginConfig\(\): Promise<void\>; ### beginConfig
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core beginConfig\(\): Promise<void\>
**Description** Starts configuration for this **CaptureSession** instance. This API uses a promise to return the result.
Starts configuration for this CaptureSession instance. This method uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core
**Return values** **Return value**
| Type | Description | | Type | Description |
|---------------|---------------------------------------------| | -------------- | --------------------------- |
| Promise<void\> | Promise used to return the result | | Promise<void\> | Promise used to return the result.|
**Example** **Example**
...@@ -1249,21 +1174,19 @@ captureSession.beginConfig().then(() => { ...@@ -1249,21 +1174,19 @@ captureSession.beginConfig().then(() => {
}) })
``` ```
### commitConfig\(callback: AsyncCallback<void\>\): void;<a name="section84581011418"></a> ### commitConfig
**System Capabilities:** commitConfig\(callback: AsyncCallback<void\>\): void
SystemCapability.Multimedia.Camera.Core Commits the configuration for this **CaptureSession** instance. This API uses an asynchronous callback to return the result.
**Description** **System capability**: SystemCapability.Multimedia.Camera.Core
Commits the configuration for this CaptureSession instance. This method uses an asynchronous callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|----------|---------------------|-----------|----------------------------------------------| | -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result | | callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example** **Example**
...@@ -1277,21 +1200,19 @@ captureSession.commitConfig((err) => { ...@@ -1277,21 +1200,19 @@ captureSession.commitConfig((err) => {
}); });
``` ```
### commitConfig\(\): Promise<void\>;<a name="section189141826104616"></a> ### commitConfig
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core commitConfig\(\): Promise<void\>
**Description** Commits the configuration for this **CaptureSession** instance. This API uses a promise to return the result.
Commits the configuration for this CaptureSession instance. This method uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core
**Return values** **Return value**
| Type | Description | | Type | Description |
|---------------|---------------------------------------------| | -------------- | --------------------------- |
| Promise<void\> | Promise used to return the result | | Promise<void\> | Promise used to return the result.|
**Example** **Example**
...@@ -1301,22 +1222,20 @@ captureSession.commitConfig().then(() => { ...@@ -1301,22 +1222,20 @@ captureSession.commitConfig().then(() => {
}) })
``` ```
### addInput\(cameraInput: CameraInput, callback: AsyncCallback<void\>\): void; ### addInput
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core addInput\(cameraInput: CameraInput, callback: AsyncCallback<void\>\): void
**Description** Adds a **CameraInput** instance to this **CaptureSession** instance. This API uses an asynchronous callback to return the result.
Add a CameraInput instance to this CaptureSession instance. This method uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|-------------|----------------------|-----------|---------------------------------------------| | ----------- | --------------------------- | ---- | --------------------------- |
| cameraInput | CameraInput | Yes | CameraInput instance to add | | cameraInput | [CameraInput](#camerainput) | Yes | **CameraInput** instance to add.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result | | callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Example** **Example**
...@@ -1330,27 +1249,25 @@ captureSession.addInput(cameraInput, (err) => { ...@@ -1330,27 +1249,25 @@ captureSession.addInput(cameraInput, (err) => {
}); });
``` ```
### addInput\(cameraInput: CameraInput\): Promise<void\>;<a name="section189141826104616"></a> ### addInput
**System Capabilities:** addInput\(cameraInput: CameraInput\): Promise<void\>
SystemCapability.Multimedia.Camera.Core Adds a **CameraInput** instance to this **CaptureSession** instance. This API uses a promise to return the result.
**Description** **System capability**: SystemCapability.Multimedia.Camera.Core
Add a CameraInput instance to this CaptureSession instance. This method uses a promise to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|-------------|---------------------|-----------|-------------------------------| | ----------- | --------------------------- | ---- | --------------------------- |
| cameraInput | CameraInput | Yes | CameraInput instance to add | | cameraInput | [CameraInput](#camerainput) | Yes | **CameraInput** instance to add.|
**Return values** **Return value**
| Type | Description | | Type | Description |
|----------------|------------------------------------| | -------------- | --------------------------- |
| Promise<void\> | Promise used to return the result | | Promise<void\> | Promise used to return the result.|
**Example** **Example**
...@@ -1360,22 +1277,20 @@ captureSession.addInput(cameraInput).then(() => { ...@@ -1360,22 +1277,20 @@ captureSession.addInput(cameraInput).then(() => {
}) })
``` ```
### addOutput\(previewOutput: PreviewOutput, callback: AsyncCallback<void\>\): void;<a name="section84581011418"></a> ### addOutput
**System Capabilities:** addOutput\(previewOutput: PreviewOutput, callback: AsyncCallback<void\>\): void
SystemCapability.Multimedia.Camera.Core Adds a **PreviewOutput** instance to this **CaptureSession** instance. This API uses an asynchronous callback to return the result.
**Description** **System capability**: SystemCapability.Multimedia.Camera.Core
Add a PreviewOutput instance to this CaptureSession instance. This method uses an asynchronous callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|---------------|----------------------|-----------|-------------------------------------| | ------------- | ------------------------------- | ---- | ----------------------------- |
| previewOutput | PreviewOutput | Yes | PreviewOutput instance to add | | previewOutput | [PreviewOutput](#previewoutput) | Yes | **PreviewOutput** instance to add.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result | | callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Example** **Example**
...@@ -1389,27 +1304,25 @@ captureSession.addOutput(previewOutput, (err) => { ...@@ -1389,27 +1304,25 @@ captureSession.addOutput(previewOutput, (err) => {
}); });
``` ```
### addOutput\(previewOutput: PreviewOutput\): Promise<void\>;<a name="section189141826104616"></a> ### addOutput
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core addOutput\(previewOutput: PreviewOutput\): Promise<void\>
**Description** Adds a **PreviewOutput** instance to this **CaptureSession** instance. This API uses a promise to return the result.
Add a PreviewOutput instance to this CaptureSession instance. This method uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|---------------|---------------------|-----------|--------------------------------| | ------------- | ------------------------------- | ---- | ----------------------------- |
| previewOutput | PreviewOutput | Yes | PreviewOutput instance to add | | previewOutput | [PreviewOutput](#previewoutput) | Yes | **PreviewOutput** instance to add.|
**Return values** **Return value**
| Type | Description | | Type | Description |
|----------------|-----------------------------------| | -------------- | --------------------------- |
| Promise<void\> | Promise used to return the result | | Promise<void\> | Promise used to return the result.|
**Example** **Example**
...@@ -1419,22 +1332,20 @@ captureSession.addOutput(previewOutput).then(() => { ...@@ -1419,22 +1332,20 @@ captureSession.addOutput(previewOutput).then(() => {
}) })
``` ```
### addOutput\(photoOutput: PhotoOutput, callback: AsyncCallback<void\>\): void;<a name="section84581011418"></a> ### addOutput
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core addOutput\(photoOutput: PhotoOutput, callback: AsyncCallback<void\>\): void
**Description** Adds a **PhotoOutput** instance to this **CaptureSession** instance. This API uses an asynchronous callback to return the result.
Add a PhotoOutput instance to this CaptureSession instance. This method uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|---------------|---------------------|-----------|-------------------------------------| | ----------- | --------------------------- | ---- | --------------------------- |
| photoOutput | PhotoOutput | Yes | PhotoOutput instance to add | | photoOutput | [PhotoOutput](#photooutput) | Yes | **PhotoOutput** instance to add.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result | | callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Example** **Example**
...@@ -1448,27 +1359,25 @@ captureSession.addOutput(photoOutput, (err) => { ...@@ -1448,27 +1359,25 @@ captureSession.addOutput(photoOutput, (err) => {
}); });
``` ```
### addOutput\(photoOutput: PhotoOutput\): Promise<void\>;<a name="section189141826104616"></a> ### addOutput
**System Capabilities:** addOutput\(photoOutput: PhotoOutput\): Promise<void\>
SystemCapability.Multimedia.Camera.Core Adds a **PhotoOutput** instance to this **CaptureSession** instance. This API uses a promise to return the result.
**Description** **System capability**: SystemCapability.Multimedia.Camera.Core
Add a PhotoOutput instance to this CaptureSession instance. This method uses a promise to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|---------------|---------------------|-----------|--------------------------------| | ----------- | --------------------------- | ---- | --------------------------- |
| photoOutput | PhotoOutput | Yes | PhotoOutput instance to add | | photoOutput | [PhotoOutput](#photooutput) | Yes | **PhotoOutput** instance to add.|
**Return values** **Return value**
| Type | Description | | Type | Description |
|---------------|-----------------------------------| | -------------- | --------------------------- |
| Promise<void> | Promise used to return the result | | Promise\<void> | Promise used to return the result.|
**Example** **Example**
...@@ -1478,22 +1387,20 @@ captureSession.addOutput(photoOutput).then(() => { ...@@ -1478,22 +1387,20 @@ captureSession.addOutput(photoOutput).then(() => {
}) })
``` ```
### addOutput\(videoOutput: VideoOutput, callback: AsyncCallback<void\>\): void; ### addOutput
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core addOutput\(videoOutput: VideoOutput, callback: AsyncCallback<void\>\): void
**Description** Adds a **VideoOutput** instance to this **CaptureSession** instance. This API uses an asynchronous callback to return the result.
Add a VideoOutput instance to this CaptureSession instance. This method uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|---------------|---------------------|-----------|-------------------------------------| | ----------- | --------------------------- | ---- | --------------------------- |
| videoOutput | VideoOutput | Yes | VideoOutput instance to add | | videoOutput | [VideoOutput](#videooutput) | Yes | **VideoOutput** instance to add.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result | | callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Example** **Example**
...@@ -1507,27 +1414,25 @@ captureSession.addOutput(videoOutput, (err) => { ...@@ -1507,27 +1414,25 @@ captureSession.addOutput(videoOutput, (err) => {
}); });
``` ```
### addOutput\(videoOutput: VideoOutput\): Promise<void\>; ### addOutput
**System Capabilities:** addOutput\(videoOutput: VideoOutput\): Promise<void\>
SystemCapability.Multimedia.Camera.Core Adds a **VideoOutput** instance to this **CaptureSession** instance. This API uses a promise to return the result.
**Description** **System capability**: SystemCapability.Multimedia.Camera.Core
Add a VideoOutput instance to this CaptureSession instance. This method uses a promise to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|---------------|---------------------|-----------|--------------------------------| | ----------- | --------------------------- | ---- | --------------------------- |
| videoOutput | VideoOutput | Yes | VideoOutput instance to add | | videoOutput | [VideoOutput](#videooutput) | Yes | **VideoOutput** instance to add.|
**Return values** **Return value**
| Type | Description | | Type | Description |
|----------------|-----------------------------------| | -------------- | --------------------------- |
| Promise<void\> | Promise used to return the result | | Promise\<void> | Promise used to return the result.|
**Example** **Example**
...@@ -1537,22 +1442,20 @@ captureSession.addOutput(videoOutput).then(() => { ...@@ -1537,22 +1442,20 @@ captureSession.addOutput(videoOutput).then(() => {
}) })
``` ```
### removeInput\(cameraInput: CameraInput, callback: AsyncCallback<void\>\): void;<a name="section84581011418"></a> ### removeInput
**System Capabilities:** removeInput\(cameraInput: CameraInput, callback: AsyncCallback<void\>\): void
SystemCapability.Multimedia.Camera.Core Removes a **CameraInput** instance from this **CaptureSession** instance. This API uses an asynchronous callback to return the result.
**Description** **System capability**: SystemCapability.Multimedia.Camera.Core
Removes a **CameraInput** instance from this **CaptureSession** instance. This method uses an asynchronous callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|-------------|----------------------|-----------|------------------------------------| | ----------- | --------------------------- | ---- | --------------------------- |
| cameraInput | CameraInput | Yes | CameraInput instance to remove | | cameraInput | [CameraInput](#camerainput) | Yes | **CameraInput** instance to remove.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result | | callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Example** **Example**
...@@ -1566,27 +1469,25 @@ captureSession.removeInput(cameraInput, (err) => { ...@@ -1566,27 +1469,25 @@ captureSession.removeInput(cameraInput, (err) => {
}); });
``` ```
### removeInput\(cameraInput: CameraInput\): Promise<void\>;<a name="section189141826104616"></a> ### removeInput
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core removeInput\(cameraInput: CameraInput\): Promise<void\>
**Description** Removes a **CameraInput** instance from this **CaptureSession** instance. This API uses a promise to return the result.
Removes a **CameraInput** instance from this **CaptureSession** instance. This method uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|-------------|---------------------|-----------|---------------------------------| | ----------- | --------------------------- | ---- | --------------------------- |
| cameraInput | CameraInput | Yes | CameraInput instance to remove | | cameraInput | [CameraInput](#camerainput) | Yes | **CameraInput** instance to remove.|
**Return values** **Return value**
| Type | Description | | Type | Description |
|----------------|-----------------------------------| | -------------- | --------------------------- |
| Promise<void\> | Promise used to return the result | | Promise\<void> | Promise used to return the result.|
**Example** **Example**
...@@ -1596,22 +1497,20 @@ captureSession.removeInput(cameraInput).then(() => { ...@@ -1596,22 +1497,20 @@ captureSession.removeInput(cameraInput).then(() => {
}) })
``` ```
### removeOutput\(previewOutput: PreviewOutput, callback: AsyncCallback<void\>\): void;<a name="section84581011418"></a> ### removeOutput
**System Capabilities:** removeOutput\(previewOutput: PreviewOutput, callback: AsyncCallback<void\>\): void
SystemCapability.Multimedia.Camera.Core Removes a **PreviewOutput** instance from this **CaptureSession** instance. This API uses an asynchronous callback to return the result.
**Description** **System capability**: SystemCapability.Multimedia.Camera.Core
Removes a **PreviewOutput** instance from this **CaptureSession** instance. This method uses an asynchronous callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|---------------|----------------------|-----------|------------------------------------| | ------------- | ------------------------------- | ---- | ----------------------------- |
| previewOutput | PreviewOutput | Yes | PreviewOutput instance to remove | | previewOutput | [PreviewOutput](#previewoutput) | Yes | **PreviewOutput** instance to remove.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result | | callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Example** **Example**
...@@ -1625,28 +1524,26 @@ captureSession.removeOutput(previewOutput, (err) => { ...@@ -1625,28 +1524,26 @@ captureSession.removeOutput(previewOutput, (err) => {
}); });
``` ```
### removeOutput(previewOutput: PreviewOutput): Promise<void\>; ### removeOutput
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core removeOutput(previewOutput: PreviewOutput): Promise<void\>
**Description** Removes a **PreviewOutput** instance from this **CaptureSession** instance. This API uses a promise to return the result.
Removes a **PreviewOutput** instance from this **CaptureSession** instance. This method uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|---------------|---------------------|-----------|-----------------------------------| | ------------- | ------------------------------- | ---- | ----------------------------- |
| previewOutput | PreviewOutput | Yes | PreviewOutput instance to remove | | previewOutput | [PreviewOutput](#previewoutput) | Yes | **PreviewOutput** instance to remove.|
**Return values** **Return value**
| Type | Description | | Type | Description |
|---------------|---------------------------------------------| | -------------- | --------------------------- |
| Promise<void\> | Promise used to return the result | | Promise<void\> | Promise used to return the result.|
**Example** **Example**
...@@ -1657,22 +1554,20 @@ captureSession.removeOutput(previewOutput).then(() => { ...@@ -1657,22 +1554,20 @@ captureSession.removeOutput(previewOutput).then(() => {
}) })
``` ```
### removeOutput(photoOutput: PhotoOutput, callback: AsyncCallback<void\>): void; ### removeOutput
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core removeOutput(photoOutput: PhotoOutput, callback: AsyncCallback<void\>): void
**Description** Removes a **PhotoOutput** instance from this **CaptureSession** instance. This API uses an asynchronous callback to return the result.
Removes a **PhotoOutput** instance from this **CaptureSession** instance. This method uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|---------------|----------------------|-----------|------------------------------------| | ----------- | --------------------------- | ---- | --------------------------- |
| photoOutput | PhotoOutput | Yes | PhotoOutput instance to remove | | photoOutput | [PhotoOutput](#photooutput) | Yes | **PhotoOutput** instance to remove.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result | | callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Example** **Example**
...@@ -1686,28 +1581,26 @@ captureSession.removeOutput(photoOutput, (err) => { ...@@ -1686,28 +1581,26 @@ captureSession.removeOutput(photoOutput, (err) => {
}); });
``` ```
### removeOutput(photoOutput: PhotoOutput): Promise<void\>; ### removeOutput
**System Capabilities:** removeOutput(photoOutput: PhotoOutput): Promise<void\>
SystemCapability.Multimedia.Camera.Core Removes a **PhotoOutput** instance from this **CaptureSession** instance. This API uses a promise to return the result.
**Description** **System capability**: SystemCapability.Multimedia.Camera.Core
Removes a **PhotoOutput** instance from this **CaptureSession** instance. This method uses a promise to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|---------------|---------------------|-----------|---------------------------------| | ----------- | --------------------------- | ---- | --------------------------- |
| photoOutput | PhotoOutput | Yes | PhotoOutput instance to remove | | photoOutput | [PhotoOutput](#photooutput) | Yes | **PhotoOutput** instance to remove.|
**Return values** **Return value**
| Type | Description | | Type | Description |
|---------------|------------------------------------| | -------------- | --------------------------- |
| Promise<void\> | Promise used to return the result | | Promise<void\> | Promise used to return the result.|
**Example** **Example**
...@@ -1718,22 +1611,20 @@ captureSession.removeOutput(photoOutput).then(() => { ...@@ -1718,22 +1611,20 @@ captureSession.removeOutput(photoOutput).then(() => {
}) })
``` ```
### removeOutput(videoOutput: VideoOutput, callback: AsyncCallback<void\>): void; ### removeOutput
**System Capabilities:** removeOutput(videoOutput: VideoOutput, callback: AsyncCallback<void\>): void
SystemCapability.Multimedia.Camera.Core Removes a **VideoOutput** instance from this **CaptureSession** instance. This API uses an asynchronous callback to return the result.
**Description** **System capability**: SystemCapability.Multimedia.Camera.Core
Removes a **VideoOutput** instance from this **CaptureSession** instance. This method uses an asynchronous callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|---------------|----------------------|-----------|------------------------------------| | ----------- | --------------------------- | ---- | --------------------------- |
| videoOutput | VideoOutput | Yes | VideoOutput instance to remove | | videoOutput | [VideoOutput](#videooutput) | Yes | **VideoOutput** instance to remove.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result | | callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Example** **Example**
...@@ -1747,28 +1638,26 @@ captureSession.removeOutput(videoOutput, (err) => { ...@@ -1747,28 +1638,26 @@ captureSession.removeOutput(videoOutput, (err) => {
}); });
``` ```
### removeOutput(videoOutput: VideoOutput): Promise<void\>; ### removeOutput
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core removeOutput(videoOutput: VideoOutput): Promise<void\>
**Description** Removes a **VideoOutput** instance from this **CaptureSession** instance. This API uses a promise to return the result.
Removes a **VideoOutput** instance from this **CaptureSession** instance. This method uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|---------------|---------------------|-----------|---------------------------------| | ----------- | --------------------------- | ---- | --------------------------- |
| videoOutput | VideoOutput | Yes | VideoOutput instance to remove | | videoOutput | [VideoOutput](#videooutput) | Yes | **VideoOutput** instance to remove.|
**Return values** **Return value**
| Type | Description | | Type | Description |
|----------------|---------------------------------------------| | -------------- | --------------------------- |
| Promise<void\> | Promise used to return the result | | Promise<void\> | Promise used to return the result.|
**Example** **Example**
...@@ -1779,21 +1668,19 @@ captureSession.removeOutput(videoOutput).then(() => { ...@@ -1779,21 +1668,19 @@ captureSession.removeOutput(videoOutput).then(() => {
}) })
``` ```
### start\(callback: AsyncCallback<void\>\): void; ### start
**System Capabilities:** start\(callback: AsyncCallback<void\>\): void
SystemCapability.Multimedia.Camera.Core Starts this **CaptureSession** instance. This API uses an asynchronous callback to return the result.
**Description** **System capability**: SystemCapability.Multimedia.Camera.Core
Starts this **CaptureSession** instance. This method uses an asynchronous callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|----------|----------------------|-----------|----------------------------------------------| | -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result | | callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example** **Example**
...@@ -1807,21 +1694,19 @@ captureSession.start((err) => { ...@@ -1807,21 +1694,19 @@ captureSession.start((err) => {
}); });
``` ```
### start\(\): Promise<void\>;<a name="section189141826104616"></a> ### start
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core start\(\): Promise<void\>
**Description** Starts this **CaptureSession** instance. This API uses a promise to return the result.
Starts this **CaptureSession** instance. This method uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core
**Return values** **Return value**
| Type | Description | | Type | Description |
|----------------|-----------------------------------| | -------------- | --------------------------- |
| Promise<void\> | Promise used to return the result | | Promise<void\> | Promise used to return the result.|
**Example** **Example**
...@@ -1831,22 +1716,20 @@ captureSession.start().then(() => { ...@@ -1831,22 +1716,20 @@ captureSession.start().then(() => {
}) })
``` ```
### stop\(callback: AsyncCallback<void\>\): void;<a name="section84581011418"></a> ### stop
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core stop\(callback: AsyncCallback<void\>\): void
**Description** Stops this **CaptureSession** instance. This API uses an asynchronous callback to return the result.
Stops this **CaptureSession** instance. This method uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|----------|----------------------|-----------|------------------------------------| | -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result | | callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example** **Example**
...@@ -1860,21 +1743,19 @@ captureSession.stop((err) => { ...@@ -1860,21 +1743,19 @@ captureSession.stop((err) => {
}); });
``` ```
### stop(): Promise<void\>; ### stop
**System Capabilities:** stop(): Promise<void\>
SystemCapability.Multimedia.Camera.Core Stops this **CaptureSession** instance. This API uses a promise to return the result.
**Description** **System capability**: SystemCapability.Multimedia.Camera.Core
Stops this **CaptureSession** instance. This method uses a promise to return the result. **Return value**
**Return values** | Type | Description |
| -------------- | --------------------------- |
| Type | Description | | Promise<void\> | Promise used to return the result.|
|----------------|-----------------------------------|
| Promise<void\> | Promise used to return the result |
**Example** **Example**
...@@ -1884,21 +1765,19 @@ captureSession.stop().then(() => { ...@@ -1884,21 +1765,19 @@ captureSession.stop().then(() => {
}) })
``` ```
### release\(callback: AsyncCallback<void\>\): void;<a name="section84581011418"></a> ### release
**System Capabilities:** release\(callback: AsyncCallback<void\>\): void
SystemCapability.Multimedia.Camera.Core Releases this **CaptureSession** instance. This API uses an asynchronous callback to return the instance.
**Description** **System capability**: SystemCapability.Multimedia.Camera.Core
Releases this **CaptureSession** instance. This method uses an asynchronous callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|----------|----------------------|-----------|------------------------------------| | -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result | | callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example** **Example**
...@@ -1912,21 +1791,19 @@ captureSession.release((err) => { ...@@ -1912,21 +1791,19 @@ captureSession.release((err) => {
}); });
``` ```
### release(): Promise<void\>; ### release
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core release(): Promise<void\>
**Description** Releases this **CaptureSession** instance. This API uses a promise to return the result.
Releases this **CaptureSession** instance. This method uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core
**Return values** **Return value**
| Type | Description | | Type | Description |
|----------------|---------------------------------------------| | -------------- | --------------------------- |
| Promise<void\> | Promise used to return the result | | Promise<void\> | Promise used to return the result.|
**Example** **Example**
...@@ -1936,22 +1813,20 @@ captureSession.release().then(() => { ...@@ -1936,22 +1813,20 @@ captureSession.release().then(() => {
}) })
``` ```
### on(type: 'error', callback: Callback<CaptureSessionError\>): void; ### on('error')
**System Capabilities:** on(type: 'error', callback: ErrorCallback<CaptureSessionError\>): void
SystemCapability.Multimedia.Camera.Core Listens for **CaptureSession** errors. This API uses a callback to return the errors.
**Description** **System capability**: SystemCapability.Multimedia.Camera.Core
Listens for **CaptureSession** errors. This method uses a callback to get errors.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :--------------------- | :-------- | :-----------------------------------------------| | :------- | :---------------------------------- | :--- | :-------------------------------------------- |
| type | string | Yes | Capture session error event. | | type | string | Yes | Type of event to listen for. The value is fixed at **error**, indicating the capture session error event.|
| callback | Callback<CaptureSessionError\> | Yes | Callback used to get the capture session errors. | | callback | ErrorCallback<CaptureSessionError\> | Yes | Callback used to return the capture session errors. |
**Example** **Example**
...@@ -1961,22 +1836,20 @@ captureSession.on('error', (captureSessionError) => { ...@@ -1961,22 +1836,20 @@ captureSession.on('error', (captureSessionError) => {
}) })
``` ```
## createPreviewOutput(surfaceId: string, callback: AsyncCallback<PreviewOutput\>): void; ## camera.createPreviewOutput
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core createPreviewOutput(surfaceId: string, callback: AsyncCallback<PreviewOutput\>): void
**Description** Creates a **PreviewOutput** instance. This API uses an asynchronous callback to return the instance.
Creates a **PreviewOutput** instance. This method uses an asynchronous callback to return the instance. **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|------------|-------------------------------|-----------|----------------------------------------------------| | --------- | ----------------------------------------------- | ---- | ------------------------------------- |
| surfaceId | string | Yes | Surface ID received from XComponent view | | surfaceId | string | Yes | Surface ID received from **XComponent**. |
| callback | AsyncCallback<PreviewOutput\> | Yes | Callback used to return the PreviewOutput instance | | callback | AsyncCallback<[PreviewOutput](#previewoutput)\> | Yes | Callback used to return the **PreviewOutput** instance.|
**Example** **Example**
...@@ -1990,27 +1863,25 @@ camera.createPreviewOutput((surfaceId), (err, previewOutput) => { ...@@ -1990,27 +1863,25 @@ camera.createPreviewOutput((surfaceId), (err, previewOutput) => {
}); });
``` ```
## createPreviewOutput(surfaceId: string): Promise<PreviewOutput>; ## camera.createPreviewOutput
**System Capabilities:** createPreviewOutput(surfaceId: string): Promise\<PreviewOutput>
SystemCapability.Multimedia.Camera.Core Creates a **PreviewOutput** instance. This API uses a promise to return the instance.
**Description** **System capability**: SystemCapability.Multimedia.Camera.Core
Creates a **PreviewOutput** instance. This method uses a promise to return the instance.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|------------|-----------------|-----------|----------------------------------------------------| | --------- | ------ | ---- | ---------------------------------- |
| surfaceId | string | Yes | Surface ID received from XComponent view | | surfaceId | string | Yes | Surface ID received from **XComponent**.|
**Return values** **Return value**
| Type | Description | | Type | Description |
|-------------------------|---------------------------------------------------| | ----------------------------------------- | --------------------------- |
| Promise<PreviewOutput\> | Promise used to return the PreviewOutput instance | | Promise<[PreviewOutput](#previewoutput)\> | Promise used to return the **PreviewOutput** instance.|
**Example** **Example**
...@@ -2024,21 +1895,19 @@ camera.createPreviewOutput(surfaceId).then((previewOutput) => { ...@@ -2024,21 +1895,19 @@ camera.createPreviewOutput(surfaceId).then((previewOutput) => {
Implements preview output. Implements preview output.
### release(callback: AsyncCallback<void\>): void; ### release
**System Capabilities:** release(callback: AsyncCallback<void\>): void
SystemCapability.Multimedia.Camera.Core Releases this **PreviewOutput** instance. This API uses an asynchronous callback to return the result.
**Description** **System capability**: SystemCapability.Multimedia.Camera.Core
Releases this **PreviewOutput** instance. This method uses an asynchronous callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|----------|----------------------|-----------|----------------------------------------------| | -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result | | callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example** **Example**
...@@ -2052,21 +1921,19 @@ previewOutput.release((err) => { ...@@ -2052,21 +1921,19 @@ previewOutput.release((err) => {
}); });
``` ```
### release(): Promise<void\>; ### release
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core release(): Promise<void\>
**Description** Releases this **PreviewOutput** instance. This API uses a promise to return the result.
Releases this **PreviewOutput** instance. This method uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core
**Return values** **Return value**
| Type | Description | | Type | Description |
|----------------|-----------------------------------| | -------------- | --------------------------- |
| Promise<void\> | Promise used to return the result | | Promise<void\> | Promise used to return the result.|
**Example** **Example**
...@@ -2077,22 +1944,20 @@ previewOutput.release().then(() => { ...@@ -2077,22 +1944,20 @@ previewOutput.release().then(() => {
}) })
``` ```
### on(type: 'frameStart', callback: Callback<number\>): void; ### on('frameStart')
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core on(type: 'frameStart', callback: AsyncCallback<void\>): void
**Description** Listens for preview frame start events. This API uses an asynchronous callback to return the result.
Listens for preview frame start events. This method uses a callback to get the event information. **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :---------------- | :-------- | :----------------------------------| | :------- | :------------------- | :--- | :------------------------------------------- |
| type | string | Yes | Name of the event to listen for. | | type | string | Yes | Type of event to listen for. The value is fixed at **frameStart**, indicating the preview frame start event.|
| callback | Callback<void\> | Yes | Callback used to return the result | | callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Example** **Example**
...@@ -2102,22 +1967,20 @@ previewOutput.on('frameStart', () => { ...@@ -2102,22 +1967,20 @@ previewOutput.on('frameStart', () => {
}) })
``` ```
### on(type: 'frameEnd', callback: Callback<number\>): void; ### on('frameEnd')
**System Capabilities:** on(type: 'frameEnd', callback: AsyncCallback<void\>): void
SystemCapability.Multimedia.Camera.Core Listens for preview frame end events. This API uses an asynchronous callback to return the result.
**Description** **System capability**: SystemCapability.Multimedia.Camera.Core
Listens for preview frame end event. This method uses a callback to get the event information.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :---------------- | :-------- | :----------------------------------| | :------- | :------------------- | :--- | :----------------------------------------- |
| type | string | Yes | Name of the event to listen for. | | type | string | Yes | Type of event to listen for. The value is fixed at **frameEnd**, indicating the preview frame end event.|
| callback | Callback<void\> | Yes | Callback used to return the result | | callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Example** **Example**
...@@ -2127,22 +1990,20 @@ previewOutput.on('frameEnd', () => { ...@@ -2127,22 +1990,20 @@ previewOutput.on('frameEnd', () => {
}) })
``` ```
### on(type: 'error', callback: Callback<PreviewOutputError\>): void; ### on('error')
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core on(type: 'error', callback: ErrorCallback<PreviewOutputError\>): void
**Description** Listens for **PreviewOutput** errors. This API uses a callback to return the errors.
Listens for **PreviewOutput** errors. This method uses a callback to get errors. **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :--------------------- | :-------- | :-----------------------------------------------| | :------- | :--------------------------------- | :--- | :-------------------------------------------- |
| type | string | Yes | Preview output error event. | | type | string | Yes | Type of event to listen for. The value is fixed at **error**, indicating the preview output error event.|
| callback | Callback<PreviewOutputError\> | Yes | Callback used to get the preview output errors. | | callback | ErrorCallback<PreviewOutputError\> | Yes | Callback used to return the preview output errors. |
**Example** **Example**
...@@ -2152,22 +2013,20 @@ previewOutput.on('error', (previewOutputError) => { ...@@ -2152,22 +2013,20 @@ previewOutput.on('error', (previewOutputError) => {
}) })
``` ```
## createPhotoOutput(surfaceId: string, callback: AsyncCallback<PhotoOutput\>): void; ## camera.createPhotoOutput
**System Capabilities:** createPhotoOutput(surfaceId: string, callback: AsyncCallback<PhotoOutput\>): void
SystemCapability.Multimedia.Camera.Core Creates a **PhotoOutput** instance. This API uses an asynchronous callback to return the instance.
**Description** **System capability**: SystemCapability.Multimedia.Camera.Core
Creates a **PhotoOutput** instance. This method uses an asynchronous callback to return the instance.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|------------|-------------------------------|-----------|----------------------------------------------------| | --------- | ------------------------------------------- | ---- | ----------------------------------- |
| surfaceId | string | Yes | Surface ID received from ImageReceiver | | surfaceId | string | Yes | Surface ID received from **ImageReceiver**. |
| callback | AsyncCallback<PhotoOutput\> | Yes | Callback used to return the PhotoOutput instance | | callback | AsyncCallback<[PhotoOutput](#photooutput)\> | Yes | Callback used to return the **PhotoOutput** instance.|
**Example** **Example**
...@@ -2181,27 +2040,25 @@ camera.createPhotoOutput((surfaceId), (err, photoOutput) => { ...@@ -2181,27 +2040,25 @@ camera.createPhotoOutput((surfaceId), (err, photoOutput) => {
}); });
``` ```
## createPhotoOutput(surfaceId: string): Promise<PhotoOutput\>; ## camera.createPhotoOutput
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core createPhotoOutput(surfaceId: string): Promise<PhotoOutput\>
**Description** Creates a **PhotoOutput** instance. This API uses a promise to return the instance.
Creates a **PhotoOutput** instance. This method uses a promise to return the PhotoOutput instance. **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|------------|-----------------|-----------|----------------------------------------------------| | --------- | ------ | ---- | --------------------------------- |
| surfaceId | string | Yes | Surface ID received from ImageReceiver | | surfaceId | string | Yes | Surface ID received from **ImageReceiver**.|
**Return values** **Return value**
| Type | Description | | Type | Description |
|-------------------------|--------------------------------------------------| | ------------------------------------- | -------------------------------------- |
| Promise<PhotoOutput\> | Promise used to return the PhotoOutput instance | | Promise<[PhotoOutput](#photooutput)\> | Promise used to return the **PhotoOutput** instance.|
**Example** **Example**
...@@ -2214,79 +2071,59 @@ camera.createPhotoOutput(surfaceId).then((photoOutput) => { ...@@ -2214,79 +2071,59 @@ camera.createPhotoOutput(surfaceId).then((photoOutput) => {
Enumerates the image rotation angles. Enumerates the image rotation angles.
**System Capabilities:** **System capability**: SystemCapability.Multimedia.Camera.Core
SystemCapability.Multimedia.Camera.Core
| Name | Default Value | Description |
|--------------|---------------|----------------------------------------|
| ROTATION_0 | 0 | The capture image rotates 0 degrees |
| ROTATION_90 | 90 | The capture image rotates 90 degrees |
| ROTATION_180 | 180 | The capture image rotates 180 degrees |
| ROTATION_270 | 270 | The capture image rotates 270 degrees |
| Name | Default Value| Description |
| ------------ | ------ | --------------- |
| ROTATION_0 | 0 | The image rotates 0 degrees. |
| ROTATION_90 | 90 | The image rotates 90 degrees. |
| ROTATION_180 | 180 | The image rotates 180 degrees.|
| ROTATION_270 | 270 | The image rotates 270 degrees.|
## Location
Defines the location of a captured image.
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core
| Name | Type | Access | Description |
|-----------|--------|--------------|-------------|
| latitude | number | read / write | Latitude |
| longitude | number | read / write | Longitude |
## QualityLevel ## QualityLevel
Enumerates the image quality levels. Enumerates the image quality levels.
**System Capabilities:** **System capability**: SystemCapability.Multimedia.Camera.Core
SystemCapability.Multimedia.Camera.Core | Name | Default Value| Description |
| -------------------- | ------ | -------------- |
| Name | Default value | Description | | QUALITY_LEVEL_HIGH | 0 | High image quality. |
|----------------------|---------------|----------------------| | QUALITY_LEVEL_MEDIUM | 1 | Medium image quality.|
| QUALITY_LEVEL_HIGH | 0 | High image quality | | QUALITY_LEVEL_LOW | 2 | Low image quality. |
| QUALITY_LEVEL_MEDIUM | 1 | Medium image quality |
| QUALITY_LEVEL_LOW | 2 | Low image quality |
## PhotoCaptureSetting ## PhotoCaptureSetting
Defines the settings for image capture. Defines the settings for image capture.
**System Capabilities:** **System capability**: SystemCapability.Multimedia.Camera.Core
SystemCapability.Multimedia.Camera.Core
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|----------|---------------|-----------|---------------------| | -------- | ------------------------------- | ---- | -------------- |
| quality | QualityLevel | Optional | Photo image quality | | quality | [QualityLevel](#qualitylevel) | No | Photo image quality. |
| rotation | ImageRotation | Optional | Photo rotation | | rotation | [ImageRotation](#imagerotation) | No | Photo rotation.|
## PhotoOutput ## PhotoOutput
Implements photo output. Implements photo output.
### capture(callback: AsyncCallback<void\>): void; ### capture
**System Capabilities:** capture(callback: AsyncCallback<void\>): void
SystemCapability.Multimedia.Camera.Core Captures a photo. This API uses an asynchronous callback to return the result.
**Description** **System capability**: SystemCapability.Multimedia.Camera.Core
Captures a photo. This method uses an asynchronous callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|----------|---------------------|-----------|----------------------------------------------| | -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result | | callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example** **Example**
...@@ -2300,22 +2137,20 @@ photoOutput.capture((err) => { ...@@ -2300,22 +2137,20 @@ photoOutput.capture((err) => {
}); });
``` ```
### capture(setting: PhotoCaptureSetting, callback: AsyncCallback<void\>): void; ### capture
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core capture(setting: PhotoCaptureSetting, callback: AsyncCallback<void\>): void
**Description** Captures a photo with the specified capture settings. This API uses an asynchronous callback to return the result.
Captures a photo with the specified capture settings. This method uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|----------|----------------------|-----------|----------------------------------------------| | -------- | ------------------------------------------- | ---- | ------------------------ |
| setting | PhotoCaptureSetting | Yes | Photo capture settings | | setting | [PhotoCaptureSetting](#photocapturesetting) | Yes | Photo capture settings. |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result | | callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example** **Example**
...@@ -2329,27 +2164,25 @@ photoOutput.capture(settings, (err) => { ...@@ -2329,27 +2164,25 @@ photoOutput.capture(settings, (err) => {
}); });
``` ```
### capture(setting?: PhotoCaptureSetting): Promise<void\>; ### capture
**System Capabilities:** capture(setting?: PhotoCaptureSetting): Promise<void\>
SystemCapability.Multimedia.Camera.Core Captures a photo with the specified capture settings. This API uses a promise to return the result.
**Description** **System capability**: SystemCapability.Multimedia.Camera.Core
Captures a photo with the specified capture settings. This method uses a promise to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|----------|---------------------|-----------|----------------------------------------------| | ------- | ------------------------------------------- | ---- | ---------- |
| setting | PhotoCaptureSetting | No | Photo capture settings | | setting | [PhotoCaptureSetting](#photocapturesetting) | No | Photo capture settings.|
**Return values** **Return value**
| Type | Description | | Type | Description |
|----------------|---------------------------------------------| | -------------- | --------------------------- |
| Promise<void\> | Promise used to return the result | | Promise<void\> | Promise used to return the result.|
**Example** **Example**
...@@ -2360,21 +2193,19 @@ photoOutput.capture().then(() => { ...@@ -2360,21 +2193,19 @@ photoOutput.capture().then(() => {
}) })
``` ```
### release(callback: AsyncCallback<void\>): void; ### release
**System Capabilities:** release(callback: AsyncCallback<void\>): void
SystemCapability.Multimedia.Camera.Core Releases this **PhotoOutput** instance. This API uses an asynchronous callback to return the result.
**Description** **System capability**: SystemCapability.Multimedia.Camera.Core
Releases this **PhotoOutput** instance. This method uses an asynchronous callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|----------|----------------------|-----------|----------------------------------------------| | -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result | | callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example** **Example**
...@@ -2388,21 +2219,19 @@ photoOutput.release((err) => { ...@@ -2388,21 +2219,19 @@ photoOutput.release((err) => {
}); });
``` ```
### release(): Promise<void\>; ### release
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core release(): Promise<void\>
**Description** Releases this **PhotoOutput** instance. This API uses a promise to return the result.
Releases this **PhotoOutput** instance. This method uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core
**Return values** **Return value**
| Type | Description | | Type | Description |
|----------------|---------------------------------------------| | -------------- | --------------------------- |
| Promise<void\> | Promise used to return the result | | Promise<void\> | Promise used to return the result.|
**Example** **Example**
...@@ -2413,22 +2242,20 @@ photoOutput.release().then(() => { ...@@ -2413,22 +2242,20 @@ photoOutput.release().then(() => {
}) })
``` ```
### on(type: 'captureStart', callback: Callback<number\>): void; ### on('captureStart')
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core on(type: 'captureStart', callback: AsyncCallback<number\>): void
**Description** Listens for photo capture start events. This API uses a callback to return the event information.
Listens for photo capture start events. This method uses a callback to get the event information. **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :--------------------- | :-------- | :-----------------------------------------------| | :------- | :--------------------- | :--- | :----------------------------------------------- |
| type | string | Yes | Name of the event to listen for. | | type | string | Yes | Type of event to listen for. The value is fixed at **captureStart**, indicating the photo capture start event.|
| callback | Callback<number\> | Yes | Callback used to get the capture ID. | | callback | AsyncCallback<number\> | Yes | Callback used to return the capture ID. |
**Example** **Example**
...@@ -2438,22 +2265,20 @@ photoOutput.on('captureStart', (captureId) => { ...@@ -2438,22 +2265,20 @@ photoOutput.on('captureStart', (captureId) => {
}) })
``` ```
### on(type: 'frameShutter', callback: Callback<FrameShutterInfo\>): void; ### on('frameShutter')
**System Capabilities:** on(type: 'frameShutter', callback: AsyncCallback<FrameShutterInfo\>): void
SystemCapability.Multimedia.Camera.Core Listens for frame shutter events. This API uses a callback to return the event information.
**Description** **System capability**: SystemCapability.Multimedia.Camera.Core
Listens for frame shutter events. This method uses a callback to get the event information.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :--------------------- | :-------- | :-----------------------------------------------| | :------- | :------------------------------- | :--- | :--------------------------------------------- |
| type | string | Yes | Name of the event to listen for. | | type | string | Yes | Type of event to listen for. The value is fixed at **frameShutter**, indicating the frame shutter event.|
| callback | Callback<FrameShutterInfo\> | Yes | Callback used to get the frame shutter information.| | callback | AsyncCallback<FrameShutterInfo\> | Yes | Callback used to return the frame shutter information. |
**Example** **Example**
...@@ -2464,22 +2289,20 @@ photoOutput.on('frameShutter', (frameShutterInfo) => { ...@@ -2464,22 +2289,20 @@ photoOutput.on('frameShutter', (frameShutterInfo) => {
}) })
``` ```
### on(type: 'captureEnd', callback: Callback<CaptureEndInfo\>): void; ### on('captureEnd')
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core on(type: 'captureEnd', callback: AsyncCallback<CaptureEndInfo\>): void
**Description** Listens for photo capture end events. This API uses a callback to return the event information.
Listens for photo capture end events. This method uses a callback to get the event information. **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :--------------------- | :-------- | :------------------------------------------------| | :------- | :----------------------------- | :--- | :--------------------------------------------- |
| type | string | Yes | Name of the event to listen for. | | type | string | Yes | Type of event to listen for. The value is fixed at **captureEnd**, indicating the photo capture end event.|
| callback | Callback<CaptureEndInfo\> | Yes | Callback used to get the capture end information | | callback | AsyncCallback<CaptureEndInfo\> | Yes | Callback used to return the capture end information. |
**Example** **Example**
...@@ -2490,22 +2313,20 @@ photoOutput.on('captureEnd', (captureEndInfo) => { ...@@ -2490,22 +2313,20 @@ photoOutput.on('captureEnd', (captureEndInfo) => {
}) })
``` ```
### on(type: 'error', callback: Callback<PhotoOutputError\>): void; ### on('error')
**System Capabilities:** on(type: 'error', callback: ErrorCallback<PhotoOutputError\>): void
SystemCapability.Multimedia.Camera.Core Listens for **PhotoOutput** errors. This API uses a callback to return the errors.
**Description** **System capability**: SystemCapability.Multimedia.Camera.Core
Listens for **PhotoOutput** errors. This method uses a callback to get errors.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :--------------------- | :-------- | :-----------------------------------------------| | :------- | :------------------------------- | :--- | :---------------------------------------- |
| type | string | Yes | Photo output error event. | | type | string | Yes | Type of event to listen for. The value is fixed at **error**, indicating the photo output error event.|
| callback | Callback<PhotoOutputError\> | Yes | Callback used to get the photo output errors. | | callback | ErrorCallback<PhotoOutputError\> | Yes | Callback used to return the photo output errors. |
**Example** **Example**
...@@ -2515,22 +2336,20 @@ photoOutput.on('error', (photoOutputError) => { ...@@ -2515,22 +2336,20 @@ photoOutput.on('error', (photoOutputError) => {
}) })
``` ```
## createVideoOutput(surfaceId: string, callback: AsyncCallback<VideoOutput\>): void; ## camera.createVideoOutput
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core createVideoOutput(surfaceId: string, callback: AsyncCallback<VideoOutput\>): void
**Description** Creates a **VideoOutput** instance. This API uses an asynchronous callback to return the instance.
Creates a **VideoOutput** instance. This method uses an asynchronous callback to return the instance. **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|------------|-------------------------------|-----------|----------------------------------------------------| | --------- | ------------------------------------------- | ---- | ----------------------------------- |
| surfaceId | string | Yes | Surface ID received from VideoRecorder | | surfaceId | string | Yes | Surface ID received from **VideoRecorder**. |
| callback | AsyncCallback<VideoOutput\> | Yes | Callback used to return the VideoOutput instance | | callback | AsyncCallback<[VideoOutput](#videooutput)\> | Yes | Callback used to return the **VideoOutput** instance.|
**Example** **Example**
...@@ -2544,27 +2363,25 @@ camera.createVideoOutput((surfaceId), (err, videoOutput) => { ...@@ -2544,27 +2363,25 @@ camera.createVideoOutput((surfaceId), (err, videoOutput) => {
}); });
``` ```
## createVideoOutput(surfaceId: string): Promise<VideoOutput\>; ## camera.createVideoOutput
**System Capabilities:** createVideoOutput(surfaceId: string): Promise<VideoOutput\>
SystemCapability.Multimedia.Camera.Core Creates a **VideoOutput** instance. This API uses a promise to return the instance.
**Description** **System capability**: SystemCapability.Multimedia.Camera.Core
Creates a **VideoOutput** instance. This method uses a promise to return the VideoOutput instance.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|------------|-----------------|-----------|----------------------------------------------------| | --------- | ------ | ---- | --------------------------------- |
| surfaceId | string | Yes | Surface ID received from VideoRecorder | | surfaceId | string | Yes | Surface ID received from **VideoRecorder**.|
**Return values** **Return value**
| Type | Description | | Type | Description |
|---------------------------------------|-------------------------------------------------| | ------------------------------------- | -------------------------------------- |
| Promise<[VideoOutput](#videooutput)\> | Promise used to return the VideoOutput instance | | Promise<[VideoOutput](#videooutput)\> | Promise used to return the **VideoOutput** instance.|
**Example** **Example**
...@@ -2573,25 +2390,24 @@ camera.createVideoOutput(surfaceId).then((videoOutput) => { ...@@ -2573,25 +2390,24 @@ camera.createVideoOutput(surfaceId).then((videoOutput) => {
console.log('Promise returned with the VideoOutput instance'); console.log('Promise returned with the VideoOutput instance');
}) })
``` ```
## VideoOutput ## VideoOutput
Implements video output. Implements video output.
### start(callback: AsyncCallback<void\>): void; ### start
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core start(callback: AsyncCallback<void\>): void
**Description** Starts the video output. This API uses an asynchronous callback to return the result.
Starts the video output. This method uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|----------|----------------------|-----------|----------------------------------------------| | -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result | | callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example** **Example**
...@@ -2605,21 +2421,19 @@ videoOutput.start((err) => { ...@@ -2605,21 +2421,19 @@ videoOutput.start((err) => {
}); });
``` ```
### start(): Promise<void\>; ### start
**System Capabilities:** start(): Promise<void\>
SystemCapability.Multimedia.Camera.Core Starts the video output. This API uses a promise to return the result.
**Description** **System capability**: SystemCapability.Multimedia.Camera.Core
Starts the video output. This method uses a promise to return the result. **Return value**
**Return values** | Type | Description |
| -------------- | --------------------------- |
| Type | Description | | Promise<void\> | Promise used to return the result.|
|----------------|---------------------------------------------|
| Promise<void\> | Promise used to return the result |
**Example** **Example**
...@@ -2630,21 +2444,19 @@ videoOutput.start().then(() => { ...@@ -2630,21 +2444,19 @@ videoOutput.start().then(() => {
}) })
``` ```
### stop(callback: AsyncCallback<void\>): void; ### stop
**System Capabilities:** stop(callback: AsyncCallback<void\>): void
SystemCapability.Multimedia.Camera.Core Stops the video output. This API uses an asynchronous callback to return the result.
**Description** **System capability**: SystemCapability.Multimedia.Camera.Core
Stops the video output. This method uses an asynchronous callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|----------|----------------------|-----------|----------------------------------------------| | -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result | | callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example** **Example**
...@@ -2658,21 +2470,19 @@ videoOutput.stop((err) => { ...@@ -2658,21 +2470,19 @@ videoOutput.stop((err) => {
}); });
``` ```
### stop(): Promise<void\>; ### stop
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core stop(): Promise<void\>
**Description** Stops the video output. This API uses a promise to return the result.
Stops the video output. This method uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core
**Return values** **Return value**
| Type | Description | | Type | Description |
|----------------|---------------------------------------------| | -------------- | --------------------------- |
| Promise<void\> | Promise used to return the result | | Promise<void\> | Promise used to return the result.|
**Example** **Example**
...@@ -2682,21 +2492,19 @@ videoOutput.start().then(() => { ...@@ -2682,21 +2492,19 @@ videoOutput.start().then(() => {
}) })
``` ```
### release(callback: AsyncCallback<void\>): void; ### release
**System Capabilities:**
SystemCapability.Multimedia.Camera.Core release(callback: AsyncCallback<void\>): void
**Description** Releases this **VideoOutput** instance. This API uses an asynchronous callback to return the result.
Releases this VideoOutput instance. This method uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
|----------|----------------------|-----------|----------------------------------------------| | -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result | | callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example** **Example**
...@@ -2710,21 +2518,19 @@ videoOutput.release((err) => { ...@@ -2710,21 +2518,19 @@ videoOutput.release((err) => {
}); });
``` ```
### release(): Promise<void\>; ### release
**System Capabilities:** release(): Promise<void\>
SystemCapability.Multimedia.Camera.Core Releases this **VideoOutput** instance. This API uses a promise to return the result.
**Description** **System capability**: SystemCapability.Multimedia.Camera.Core
Releases this VideoOutput instance. This method uses a promise to return the result. **Return value**
**Return values** | Type | Description |
| -------------- | --------------------------- |
| Type | Description | | Promise<void\> | Promise used to return the result.|
|----------------|---------------------------------------------|
| Promise<void\> | Promise used to return the result |
**Example** **Example**
...@@ -2735,22 +2541,20 @@ videoOutput.release().then(() => { ...@@ -2735,22 +2541,20 @@ videoOutput.release().then(() => {
}) })
``` ```
### on(type: 'frameStart', callback: Callback<number\>): void; ### on('frameStart')
**System Capabilities:** on(type: 'frameStart', callback: AsyncCallback<void\>): void
SystemCapability.Multimedia.Camera.Core Listens for video frame start events. This API uses a callback to return the event information.
**Description** **System capability**: SystemCapability.Multimedia.Camera.Core
Listens for video frame start events. This method uses a callback to get the event information.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :---------------- | :-------- | :----------------------------------| | :------- | :------------------- | :--- | :----------------------------------------------- |
| type | string | Yes | Name of the event to listen for. | | type | string | Yes | Type of event to listen for. The value is fixed at **frameStart**, indicating the video frame start event.|
| callback | Callback<void\> | Yes | Callback used to return the result | | callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Example** **Example**
...@@ -2760,16 +2564,20 @@ videoOutput.on('frameStart', () => { ...@@ -2760,16 +2564,20 @@ videoOutput.on('frameStart', () => {
}) })
``` ```
### on(type: 'frameEnd', callback: Callback<number\>): void; ### on('frameEnd')
on(type: 'frameEnd', callback: AsyncCallback<void\>): void
Listens for video frame end events. This method uses a callback to get the event information. Listens for video frame end events. This API uses a callback to return the event information.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :---------------- | :-------- | :----------------------------------| | :------- | :------------------- | :--- | :--------------------------------------------- |
| type | string | Yes | Name of the event to listen for. | | type | string | Yes | Type of event to listen for. The value is fixed at **frameEnd**, indicating the video frame end event.|
| callback | Callback<void\> | Yes | Callback used to return the result | | callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Example** **Example**
...@@ -2779,16 +2587,20 @@ videoOutput.on('frameEnd', () => { ...@@ -2779,16 +2587,20 @@ videoOutput.on('frameEnd', () => {
}) })
``` ```
### on(type: 'error', callback: Callback<VideoOutputError\>): void; ### on('error')
on(type: 'error', callback: ErrorCallback<VideoOutputError\>): void
Listens for **VideoOutput** errors. This method uses a callback to get errors. Listens for **VideoOutput** errors. This API uses a callback to return the errors.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :--------------------- | :-------- | :-----------------------------------------------| | :------- | :-------------------------- | :--- | :-------------------------------------------- |
| type | string | Yes | Video output error event. | | type | string | Yes | Type of event to listen for. The value is fixed at **error**, indicating the video output error event.|
| callback | Callback<VideoOutputError\> | Yes | Callback used to get the video output errors. | | callback | Callback<VideoOutputError\> | Yes | Callback used to return the video output errors. |
**Example** **Example**
...@@ -2796,4 +2608,4 @@ Listens for **VideoOutput** errors. This method uses a callback to get errors. ...@@ -2796,4 +2608,4 @@ Listens for **VideoOutput** errors. This method uses a callback to get errors.
videoOutput.on('error', (VideoOutputError) => { videoOutput.on('error', (VideoOutputError) => {
console.log('Video output error code: ' + VideoOutputError.code); console.log('Video output error code: ' + VideoOutputError.code);
}) })
``` ```
\ No newline at end of file
# Image Processing # Image Processing
> **NOTE** > **NOTE**<br/>
> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> API version 9 is a canary release for trial use. The APIs of this version may be unstable.
## Modules to Import ## Modules to Import
...@@ -990,14 +992,40 @@ Enumerates pixel map formats. ...@@ -990,14 +992,40 @@ Enumerates pixel map formats.
| RGBA_8888 | 3 | RGBA_8888.| | RGBA_8888 | 3 | RGBA_8888.|
| RGB_565 | 2 | RGB_565. | | RGB_565 | 2 | RGB_565. |
## AlphaType<sup>9+</sup>
Enumerates alpha types.
**System capability**: SystemCapability.Multimedia.Image
| Name | Default Value| Description |
| -------- | ------ | ----------------------- |
| UNKNOWN | 0 | Unknown alpha type. |
| OPAQUE | 1 | There is no alpha or the image is opaque.|
| PREMUL | 2 | Premultiplied alpha. |
| UNPREMUL | 3 | Unpremultiplied alpha, that is, straight alpha. |
## ScaleMode<sup>9+</sup>
Enumerates scale modes.
**System capability**: SystemCapability.Multimedia.Image
| Name | Default Value| Description |
| --------------- | ------ | -------------------------------------------------- |
| CENTER_CROP | 1 | The image is scaled in such a way that it fits the dimensions of the target and centered in the target. |
| FIT_TARGET_SIZE | 2 | The image size is reduced to fit the dimensions of the target. |
## InitializationOptions<sup>8+</sup> ## InitializationOptions<sup>8+</sup>
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| ----------- | ---------------------------------- | ---- | ---- | -------------- | | ----------- | ---------------------------------- | ---- | ---- | -------------- |
| alphaType<sup>9+</sup> | [AlphaType](#alphatype9) | Yes | Yes | Alpha type. |
| editable | boolean | Yes | Yes | Whether the image is editable. | | editable | boolean | Yes | Yes | Whether the image is editable. |
| pixelFormat | [PixelMapFormat](#pixelmapformat7) | Yes | Yes | Pixel map format. | | pixelFormat | [PixelMapFormat](#pixelmapformat7) | Yes | Yes | Pixel map format. |
| scaleMode<sup>9+</sup> | [ScaleMode](#scalemode9) | Yes | Yes | Scale mode. |
| size | [Size](#size) | Yes | Yes | Image size.| | size | [Size](#size) | Yes | Yes | Image size.|
## DecodingOptions<sup>7+</sup> ## DecodingOptions<sup>7+</sup>
......
# Media # Media
> **NOTE** > **NOTE**
>
> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> API version 9 is a canary release for trial use. The APIs of this version may be unstable.
The multimedia subsystem provides a set of simple and easy-to-use APIs for you to access the system and use media resources. The multimedia subsystem provides a set of simple and easy-to-use APIs for you to access the system and use media resources.
...@@ -10,6 +13,7 @@ This subsystem offers various media services covering audio and video, which pro ...@@ -10,6 +13,7 @@ This subsystem offers various media services covering audio and video, which pro
- Audio playback ([AudioPlayer](#audioplayer)) - Audio playback ([AudioPlayer](#audioplayer))
- Video playback ([VideoPlayer](#videoplayer8)) - Video playback ([VideoPlayer](#videoplayer8))
- Audio recording ([AudioRecorder](#audiorecorder)) - Audio recording ([AudioRecorder](#audiorecorder))
- Video recording ([VideoRecorder](#videorecorder9))
The following capabilities will be provided in later versions: data source audio/video playback, audio/video encoding and decoding, container encapsulation and decapsulation, and media capability query. The following capabilities will be provided in later versions: data source audio/video playback, audio/video encoding and decoding, container encapsulation and decapsulation, and media capability query.
...@@ -87,21 +91,16 @@ Creates a **VideoPlayer** instance in asynchronous mode. This API uses a promise ...@@ -87,21 +91,16 @@ Creates a **VideoPlayer** instance in asynchronous mode. This API uses a promise
```js ```js
let videoPlayer let videoPlayer
function failureCallback(error) { media.createVideoPlayer().then((video) => {
console.info(`video failureCallback, error:${error.message}`); if (typeof(video) != 'undefined') {
}
function catchCallback(error) {
console.info(`video catchCallback, error:${error.message}`);
}
await media.createVideoPlayer.then((video) => {
if (typeof(video) != 'undefined') {
videoPlayer = video; videoPlayer = video;
console.info('video createVideoPlayer success'); console.info('video createVideoPlayer success');
} else { } else {
console.info('video createVideoPlayer fail'); console.info('video createVideoPlayer fail');
} }
}, failureCallback).catch(catchCallback); }).catch((error) => {
console.info(`video catchCallback, error:${error.message}`);
});
``` ```
## media.createAudioRecorder ## media.createAudioRecorder
...@@ -124,6 +123,68 @@ Creates an **AudioRecorder** instance to control audio recording. ...@@ -124,6 +123,68 @@ Creates an **AudioRecorder** instance to control audio recording.
let audiorecorder = media.createAudioRecorder(); let audiorecorder = media.createAudioRecorder();
``` ```
## media.createVideoRecorder<sup>9+</sup>
createVideoRecorder(callback: AsyncCallback\<[VideoRecorder](#videorecorder9)>): void
Creates a **VideoRecorder** instance in asynchronous mode. This API uses a callback to return the result.
**System capability**: SystemCapability.Multimedia.Media.VideoRecorder
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------------------- | ---- | ------------------------------ |
| callback | AsyncCallback<[VideoRecorder](#videorecorder9)> | Yes | Callback used to return the **VideoRecorder** instance created.|
**Example**
```js
let videoRecorder
media.createVideoRecorder((error, video) => {
if (typeof(video) != 'undefined') {
videoRecorder = video;
console.info('video createVideoRecorder success');
} else {
console.info(`video createVideoRecorder fail, error:${error.message}`);
}
});
```
## media.createVideoRecorder<sup>9+</sup>
createVideoRecorder(): Promise<[VideoRecorder](#videorecorder9)>
Creates a **VideoRecorder** instance in asynchronous mode. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Media.VideoRecorder
**Return value**
| Type | Description |
| ----------------------------------------- | ----------------------------------- |
| Promise<[VideoRecorder](#videorecorder9)> | Promise used to return the **VideoRecorder** instance created.|
**Example**
```js
let videoRecorder
media.createVideoRecorder().then((video) => {
if (typeof(video) != 'undefined') {
videoRecorder = video;
console.info('video createVideoRecorder success');
} else {
console.info('video createVideoRecorder fail');
}
}).catch((error) => {
console.info(`video catchCallback, error:${error.message}`);
});
```
## MediaErrorCode<sup>8+</sup> ## MediaErrorCode<sup>8+</sup>
Enumerates the media error codes. Enumerates the media error codes.
...@@ -358,7 +419,7 @@ audioPlayer = undefined; ...@@ -358,7 +419,7 @@ audioPlayer = undefined;
getTrackDescription(callback: AsyncCallback<Array\<MediaDescription>>): void getTrackDescription(callback: AsyncCallback<Array\<MediaDescription>>): void
Obtains the audio track information. This API uses a callback to return the result. Obtains the audio track information. This API uses a callback to return the result. It can be called only after the [dataLoad](#audioplayer_on) event is triggered.
**System capability**: SystemCapability.Multimedia.Media.AudioPlayer **System capability**: SystemCapability.Multimedia.Media.AudioPlayer
...@@ -394,7 +455,7 @@ audioPlayer.getTrackDescription((error, arrlist) => { ...@@ -394,7 +455,7 @@ audioPlayer.getTrackDescription((error, arrlist) => {
getTrackDescription(): Promise<Array\<MediaDescription>> getTrackDescription(): Promise<Array\<MediaDescription>>
Obtains the audio track information. This API uses a promise to return the result. Obtains the audio track information. This API uses a promise to return the result. It can be called only after the [dataLoad](#audioplayer_on) event is triggered.
**System capability**: SystemCapability.Multimedia.Media.AudioPlayer **System capability**: SystemCapability.Multimedia.Media.AudioPlayer
...@@ -414,20 +475,17 @@ function printfDescription(obj) { ...@@ -414,20 +475,17 @@ function printfDescription(obj) {
console.info('audio value is ' + property); console.info('audio value is ' + property);
} }
} }
function failureCallback(error) {
console.info(`audio failureCallback, error:${error.message}`);
}
function catchCallback(error) {
console.info(`audio catchCallback, error:${error.message}`);
}
await audioPlayer.getTrackDescription.then((arrlist) => { audioPlayer.getTrackDescription().then((arrlist) => {
if (typeof (arrlist) != 'undefined') { if (typeof (arrlist) != 'undefined') {
arrayDescription = arrlist; arrayDescription = arrlist;
} else { } else {
console.log('audio getTrackDescription fail'); console.log('audio getTrackDescription fail');
} }
}, failureCallback).catch(catchCallback); }).catch((error) => {
console.info(`audio catchCallback, error:${error.message}`);
});
for (let i = 0; i < arrayDescription.length; i++) { for (let i = 0; i < arrayDescription.length; i++) {
printfDescription(arrayDescription[i]); printfDescription(arrayDescription[i]);
} }
...@@ -517,13 +575,14 @@ audioPlayer.on('error', (error) => { // Set the 'error' event callback ...@@ -517,13 +575,14 @@ audioPlayer.on('error', (error) => { // Set the 'error' event callback
// Set the FD (local playback) of the video file selected by the user. // Set the FD (local playback) of the video file selected by the user.
let fdPath = 'fd://' let fdPath = 'fd://'
let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3'; // The stream in the path can be pushed to the device by running the "hdc file send D:\xxx\01.mp3 /data/accounts/account_0/appdata" command.
await fileIO.open(path).then(fdNumber) => { let path = '/data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3';
fileIO.open(path).then(fdNumber) => {
fdPath = fdPath + '' + fdNumber; fdPath = fdPath + '' + fdNumber;
console.info('open fd sucess fd is' + fdPath); console.info('open fd sucess fd is' + fdPath);
}, (err) => { }, (err) => {
console.info('open fd failed err is' + err); console.info('open fd failed err is' + err);
}),catch((err) => { }).catch((err) => {
console.info('open fd failed err is' + err); console.info('open fd failed err is' + err);
}); });
audioPlayer.src = fdPath; // Set the src attribute and trigger the 'dataLoad' event callback. audioPlayer.src = fdPath; // Set the src attribute and trigger the 'dataLoad' event callback.
...@@ -667,15 +726,11 @@ Sets **SurfaceId**. This API uses a promise to return the result. ...@@ -667,15 +726,11 @@ Sets **SurfaceId**. This API uses a promise to return the result.
**Example** **Example**
```js ```js
function failureCallback(error) { videoPlayer.setDisplaySurface(surfaceId).then(() => {
console.info(`video failureCallback, error:${error.message}`);
}
function catchCallback(error) {
console.info(`video catchCallback, error:${error.message}`);
}
await videoPlayer.setDisplaySurface(surfaceId).then(() => {
console.info('setDisplaySurface success'); console.info('setDisplaySurface success');
}, failureCallback).catch(catchCallback); }).catch((error) => {
console.info(`video catchCallback, error:${error.message}`);
});
``` ```
### prepare<sup>8+</sup> ### prepare<sup>8+</sup>
...@@ -721,15 +776,11 @@ Prepares for video playback. This API uses a promise to return the result. ...@@ -721,15 +776,11 @@ Prepares for video playback. This API uses a promise to return the result.
**Example** **Example**
```js ```js
function failureCallback(error) { videoPlayer.prepare().then(() => {
console.info(`video failureCallback, error:${error.message}`);
}
function catchCallback(error) {
console.info(`video catchCallback, error:${error.message}`);
}
await videoPlayer.prepare().then(() => {
console.info('prepare success'); console.info('prepare success');
}, failureCallback).catch(catchCallback); }).catch((error) => {
console.info(`video catchCallback, error:${error.message}`);
});
``` ```
### play<sup>8+</sup> ### play<sup>8+</sup>
...@@ -775,15 +826,11 @@ Starts to play video resources. This API uses a promise to return the result. ...@@ -775,15 +826,11 @@ Starts to play video resources. This API uses a promise to return the result.
**Example** **Example**
```js ```js
function failureCallback(error) { videoPlayer.play().then(() => {
console.info(`video failureCallback, error:${error.message}`);
}
function catchCallback(error) {
console.info(`video catchCallback, error:${error.message}`);
}
await videoPlayer.play().then(() => {
console.info('play success'); console.info('play success');
}, failureCallback).catch(catchCallback); }).catch((error) => {
console.info(`video catchCallback, error:${error.message}`);
});
``` ```
### pause<sup>8+</sup> ### pause<sup>8+</sup>
...@@ -829,15 +876,11 @@ Pauses video playback. This API uses a promise to return the result. ...@@ -829,15 +876,11 @@ Pauses video playback. This API uses a promise to return the result.
**Example** **Example**
```js ```js
function failureCallback(error) { videoPlayer.pause().then(() => {
console.info(`video failureCallback, error:${error.message}`);
}
function catchCallback(error) {
console.info(`video catchCallback, error:${error.message}`);
}
await videoPlayer.pause().then(() => {
console.info('pause success'); console.info('pause success');
}, failureCallback).catch(catchCallback); }).catch((error) => {
console.info(`video catchCallback, error:${error.message}`);
});
``` ```
### stop<sup>8+</sup> ### stop<sup>8+</sup>
...@@ -883,15 +926,11 @@ Stops video playback. This API uses a promise to return the result. ...@@ -883,15 +926,11 @@ Stops video playback. This API uses a promise to return the result.
**Example** **Example**
```js ```js
function failureCallback(error) { videoPlayer.stop().then(() => {
console.info(`video failureCallback, error:${error.message}`);
}
function catchCallback(error) {
console.info(`video catchCallback, error:${error.message}`);
}
await videoPlayer.stop().then(() => {
console.info('stop success'); console.info('stop success');
}, failureCallback).catch(catchCallback); }).catch((error) => {
console.info(`video catchCallback, error:${error.message}`);
});
``` ```
### reset<sup>8+</sup> ### reset<sup>8+</sup>
...@@ -937,15 +976,11 @@ Switches the video resource to be played. This API uses a promise to return the ...@@ -937,15 +976,11 @@ Switches the video resource to be played. This API uses a promise to return the
**Example** **Example**
```js ```js
function failureCallback(error) { videoPlayer.reset().then(() => {
console.info(`video failureCallback, error:${error.message}`);
}
function catchCallback(error) {
console.info(`video catchCallback, error:${error.message}`);
}
await videoPlayer.reset().then(() => {
console.info('reset success'); console.info('reset success');
}, failureCallback).catch(catchCallback); }).catch((error) => {
console.info(`video catchCallback, error:${error.message}`);
});
``` ```
### seek<sup>8+</sup> ### seek<sup>8+</sup>
...@@ -1027,19 +1062,17 @@ Seeks to the specified playback position. If **mode** is not specified, the next ...@@ -1027,19 +1062,17 @@ Seeks to the specified playback position. If **mode** is not specified, the next
**Example** **Example**
```js ```js
function failureCallback(error) { videoPlayer.seek(seekTime).then((seekDoneTime) => { // seekDoneTime indicates the position after the seek operation is complete.
console.info(`video failureCallback, error:${error.message}`);
}
function catchCallback(error) {
console.info(`video catchCallback, error:${error.message}`);
}
await videoPlayer.seek(seekTime).then((seekDoneTime) => { // seekDoneTime indicates the position after the seek operation is complete.
console.info('seek success'); console.info('seek success');
}, failureCallback).catch(catchCallback); }).catch((error) => {
console.info(`video catchCallback, error:${error.message}`);
});
await videoPlayer.seek(seekTime, seekMode).then((seekDoneTime) => { videoPlayer.seek(seekTime, seekMode).then((seekDoneTime) => {
console.info('seek success'); console.info('seek success');
}, failureCallback).catch(catchCallback); }).catch((error) => {
console.info(`video catchCallback, error:${error.message}`);
});
``` ```
### setVolume<sup>8+</sup> ### setVolume<sup>8+</sup>
...@@ -1092,15 +1125,11 @@ Sets the volume. This API uses a promise to return the result. ...@@ -1092,15 +1125,11 @@ Sets the volume. This API uses a promise to return the result.
**Example** **Example**
```js ```js
function failureCallback(error) { videoPlayer.setVolume(vol).then() => {
console.info(`video failureCallback, error:${error.message}`);
}
function catchCallback(error) {
console.info(`video catchCallback, error:${error.message}`);
}
await videoPlayer.setVolume(vol).then() => {
console.info('setVolume success'); console.info('setVolume success');
}, failureCallback).catch(catchCallback); }).catch((error) => {
console.info(`video catchCallback, error:${error.message}`);
});
``` ```
### release<sup>8+</sup> ### release<sup>8+</sup>
...@@ -1146,15 +1175,11 @@ Releases the video playback resource. This API uses a promise to return the resu ...@@ -1146,15 +1175,11 @@ Releases the video playback resource. This API uses a promise to return the resu
**Example** **Example**
```js ```js
function failureCallback(error) { videoPlayer.release().then() => {
console.info(`video failureCallback, error:${error.message}`);
}
function catchCallback(error) {
console.info(`video catchCallback, error:${error.message}`);
}
await videoPlayer.release().then() => {
console.info('release success'); console.info('release success');
}, failureCallback).catch(catchCallback); }).catch((error) => {
console.info(`video catchCallback, error:${error.message}`);
});
``` ```
### getTrackDescription<sup>8+</sup> ### getTrackDescription<sup>8+</sup>
...@@ -1217,21 +1242,17 @@ function printfDescription(obj) { ...@@ -1217,21 +1242,17 @@ function printfDescription(obj) {
console.info('video value is ' + property); console.info('video value is ' + property);
} }
} }
function failureCallback(error) {
console.info(`video failureCallback, error:${error.message}`);
}
function catchCallback(error) {
console.info(`video catchCallback, error:${error.message}`);
}
let arrayDescription; let arrayDescription;
await videoPlayer.getTrackDescription().then((arrlist) => { videoPlayer.getTrackDescription().then((arrlist) => {
if (typeof (arrlist) != 'undefined') { if (typeof (arrlist) != 'undefined') {
arrayDescription = arrlist; arrayDescription = arrlist;
} else { } else {
console.log('video getTrackDescription fail'); console.log('video getTrackDescription fail');
} }
}, failureCallback).catch(catchCallback); }).catch((error) => {
console.info(`video catchCallback, error:${error.message}`);
});
for (let i = 0; i < arrayDescription.length; i++) { for (let i = 0; i < arrayDescription.length; i++) {
printfDescription(arrayDescription[i]); printfDescription(arrayDescription[i]);
} }
...@@ -1287,15 +1308,11 @@ Sets the video playback speed. This API uses a promise to return the result. ...@@ -1287,15 +1308,11 @@ Sets the video playback speed. This API uses a promise to return the result.
**Example** **Example**
```js ```js
function failureCallback(error) { videoPlayer.setSpeed(speed).then() => {
console.info(`video failureCallback, error:${error.message}`);
}
function catchCallback(error) {
console.info(`video catchCallback, error:${error.message}`);
}
await videoPlayer.setSpeed(speed).then() => {
console.info('setSpeed success'); console.info('setSpeed success');
}, failureCallback).catch(catchCallback); }).catch((error) => {
console.info(`video catchCallback, error:${error.message}`);
});
``` ```
### on('playbackCompleted')<sup>8+</sup> ### on('playbackCompleted')<sup>8+</sup>
...@@ -1774,6 +1791,644 @@ Enumerates the audio output formats. ...@@ -1774,6 +1791,644 @@ Enumerates the audio output formats.
| AMR_WB | 4 | AMR_WB.<br>This API is defined but not implemented yet.| | AMR_WB | 4 | AMR_WB.<br>This API is defined but not implemented yet.|
| AAC_ADTS | 6 | Audio Data Transport Stream (ADTS), which is a transport stream format of AAC-based audio.| | AAC_ADTS | 6 | Audio Data Transport Stream (ADTS), which is a transport stream format of AAC-based audio.|
## VideoRecorder<sup>9+</sup>
Implements video recording. Before calling an API of the **VideoRecorder** class, you must call [createVideoRecorder()](#mediacreatevideorecorder9) to create a [VideoRecorder](#videorecorder9) instance.
For details about the video recording demo, see [Video Recording Development](../../media/video-recorder.md).
### Attributes
**System capability**: SystemCapability.Multimedia.Media.VideoRecorder
| Name | Type | Readable| Writable| Description |
| ------------------ | -------------------------------------- | ---- | ---- | ---------------- |
| state<sup>8+</sup> | [VideoRecordState](#videorecordstate9) | Yes | No | Video recording state.|
### prepare<sup>9+</sup><a name=videorecorder_prepare1></a>
prepare(config: VideoRecorderConfig, callback: AsyncCallback\<void>): void;
Sets video recording parameters in asynchronous mode. This API uses a callback to return the result.
**Required permissions:** ohos.permission.MICROPHONE
**System capability**: SystemCapability.Multimedia.Media.VideoRecorder
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------------------------------- | ---- | ----------------------------------- |
| config | [VideoRecorderConfig](#videorecorderconfig9) | Yes | Video recording parameters to set. |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example**
```js
let videoProfile = {
audioBitrate : 48000,
audioChannels : 2,
audioCodec : 'audio/mp4a-latm',
audioSampleRate : 48000,
fileFormat : 'mp4',
videoBitrate : 48000,
videoCodec : 'video/mp4v-es',
videoFrameWidth : 640,
videoFrameHeight : 480,
videoFrameRate : 30
}
let videoConfig = {
audioSourceType : 1,
videoSourceType : 0,
profile : videoProfile,
url : 'fd://xx', // The file must be created by the caller and granted with proper permissions.
orientationHint : 0,
location : { latitude : 30, longitude : 130 },
}
// asyncallback
let videoRecorder = null;
let events = require('events');
let eventEmitter = new events.EventEmitter();
eventEmitter.on('prepare', () => {
videoRecorder.prepare(videoConfig, (err) => {
if (typeof (err) == 'undefined') {
console.info('prepare success');
} else {
console.info('prepare failed and error is ' + err.message);
}
});
});
media.createVideoRecorder((err, recorder) => {
if (typeof (err) == 'undefined' && typeof (recorder) != 'undefined') {
videoRecorder = recorder;
console.info('createVideoRecorder success');
eventEmitter.emit('prepare'); // Trigger the 'prepare' event.
} else {
console.info('createVideoRecorder failed and error is ' + err.message);
}
});
```
### prepare<sup>9+</sup><a name=videorecorder_prepare2></a>
prepare(config: VideoRecorderConfig): Promise\<void>;
Sets video recording parameters in asynchronous mode. This API uses a promise to return the result.
**Required permissions:** ohos.permission.MICROPHONE and ohos.permission.CAMERA
**System capability**: SystemCapability.Multimedia.Media.VideoRecorder
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | -------------------------------------------- | ---- | ------------------------ |
| config | [VideoRecorderConfig](#videorecorderconfig9) | Yes | Video recording parameters to set.|
**Return value**
| Type | Description |
| -------------- | ---------------------------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```js
let videoProfile = {
audioBitrate : 48000,
audioChannels : 2,
audioCodec : 'audio/mp4a-latm',
audioSampleRate : 48000,
fileFormat : 'mp4',
videoBitrate : 48000,
videoCodec : 'video/mp4v-es',
videoFrameWidth : 640,
videoFrameHeight : 480,
videoFrameRate : 30
}
let videoConfig = {
audioSourceType : 1,
videoSourceType : 0,
profile : videoProfile,
url : 'fd://xx', // The file must be created by the caller and granted with proper permissions.
orientationHint : 0,
location : { latitude : 30, longitude : 130 },
}
// promise
let videoRecorder = null;
media.createVideoRecorder().then((recorder) => {
if (typeof (recorder) != 'undefined') {
videoRecorder = recorder;
console.info('createVideoRecorder success');
} else {
console.info('createVideoRecorder failed');
}
}).catch((err) => {
console.info('catch err error message is ' + err.message);
});
videoRecorder.prepare(videoConfig).then(() => {
console.info('prepare success');
}).catch((err) => {
console.info('prepare failed and catch error is ' + err.message);
});
```
### getInputSurface<sup>9+</sup>
getInputSurface(callback: AsyncCallback\<string>): void;
Obtains the surface required for recording in asynchronous mode. This surface is provided for the caller. The caller obtains the **surfaceBuffer** from this surface and fills in the corresponding data.
Note that the video data must carry the timestamp (in ns) and buffer size, and the start time of the timestamp is based on the system startup time.
This API can be called only after [prepare()](#videorecorder_prepare1) is called.
**System capability**: SystemCapability.Multimedia.Media.VideoRecorder
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | --------------------------- |
| callback | AsyncCallback\<string> | Yes | Callback used to obtain the result.|
**Example**
```js
// asyncallback
let surfaceID = null; // Surface ID passed to the external system.
videoRecorder.getInputSurface((err, surfaceId) => {
if (typeof (err) == 'undefined') {
console.info('getInputSurface success');
surfaceID = surfaceId;
} else {
console.info('getInputSurface failed and error is ' + err.message);
}
});
```
### getInputSurface<sup>9+</sup>
getInputSurface(): Promise\<string>;
Obtains the surface required for recording in asynchronous mode. This surface is provided for the caller. The caller obtains the **surfaceBuffer** from this surface and fills in the corresponding data.
Note that the video data must carry the timestamp (in ns) and buffer size, and the start time of the timestamp is based on the system startup time.
This API can be called only after [prepare()](#videorecorder_prepare1) is called.
**System capability**: SystemCapability.Multimedia.Media.VideoRecorder
**Return value**
| Type | Description |
| ---------------- | -------------------------------- |
| Promise\<string> | Promise used to return the result.|
**Example**
```js
// promise
let surfaceID = null; // Surface ID passed to the external system.
videoRecorder.getInputSurface().then((surfaceId) => {
console.info('getInputSurface success');
surfaceID = surfaceId;
}).catch((err) => {
console.info('getInputSurface failed and catch error is ' + err.message);
});
```
### start<sup>9+</sup><a name=videorecorder_start1></a>
start(callback: AsyncCallback\<void>): void;
Starts video recording in asynchronous mode. This API uses a callback to return the result.
This API can be called only after [prepare()](#videorecorder_prepare1) and [getInputSurface()](#getinputsurface8) are called, because the data source must pass data to the surface first.
**System capability**: SystemCapability.Multimedia.Media.VideoRecorder
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ---------------------------- |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example**
```js
// asyncallback
videoRecorder.start((err) => {
if (typeof (err) == 'undefined') {
console.info('start videorecorder success');
} else {
console.info('start videorecorder failed and error is ' + err.message);
}
});
```
### start<sup>9+</sup><a name=videorecorder_start2></a>
start(): Promise\<void>;
Starts video recording in asynchronous mode. This API uses a promise to return the result.
This API can be called only after [prepare()](#videorecorder_prepare1) and [getInputSurface()](#getinputsurface8) are called, because the data source must pass data to the surface first.
**System capability**: SystemCapability.Multimedia.Media.VideoRecorder
**Return value**
| Type | Description |
| -------------- | ------------------------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```js
// promise
videoRecorder.start().then(() => {
console.info('start videorecorder success');
}).catch((err) => {
console.info('start videorecorder failed and catch error is ' + err.message);
});
```
### pause<sup>9+</sup><a name=videorecorder_pause1></a>
pause(callback: AsyncCallback\<void>): void;
Pauses video recording in asynchronous mode. This API uses a callback to return the result.
This API can be called only after [start()](#videorecorder_start1) is called. You can resume recording by calling [resume()](#videorecorder_resume1).
**System capability**: SystemCapability.Multimedia.Media.VideoRecorder
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ---------------------------- |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example**
```js
// asyncallback
videoRecorder.pause((err) => {
if (typeof (err) == 'undefined') {
console.info('pause videorecorder success');
} else {
console.info('pause videorecorder failed and error is ' + err.message);
}
});
```
### pause<sup>9+</sup><a name=videorecorder_pause2></a>
pause(): Promise\<void>;
Pauses video recording in asynchronous mode. This API uses a promise to return the result.
This API can be called only after [start()](#videorecorder_start1) is called. You can resume recording by calling [resume()](#videorecorder_resume1).
**System capability**: SystemCapability.Multimedia.Media.VideoRecorder
**Return value**
| Type | Description |
| -------------- | ------------------------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```js
// promise
videoRecorder.pause().then(() => {
console.info('pause videorecorder success');
}).catch((err) => {
console.info('pause videorecorder failed and catch error is ' + err.message);
});
```
### resume<sup>9+</sup><a name=videorecorder_resume1></a>
resume(callback: AsyncCallback\<void>): void;
Resumes video recording in asynchronous mode. This API uses a callback to return the result.
**System capability**: SystemCapability.Multimedia.Media.VideoRecorder
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ---------------------------- |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example**
```js
// asyncallback
videoRecorder.resume((err) => {
if (typeof (err) == 'undefined') {
console.info('resume videorecorder success');
} else {
console.info('resume videorecorder failed and error is ' + err.message);
}
});
```
### resume<sup>9+</sup><a name=videorecorder_resume2></a>
resume(): Promise\<void>;
Resumes video recording in asynchronous mode. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Media.VideoRecorder
**Return value**
| Type | Description |
| -------------- | ------------------------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```js
// promise
videoRecorder.resume().then(() => {
console.info('resume videorecorder success');
}).catch((err) => {
console.info('resume videorecorder failed and catch error is ' + err.message);
});
```
### stop<sup>9+</sup><a name=videorecorder_stop1></a>
stop(callback: AsyncCallback\<void>): void;
Stops video recording in asynchronous mode. This API uses a callback to return the result.
To start another recording, you must call [prepare()](#videorecorder_prepare1) and [getInputSurface()](#getinputsurface8) again.
**System capability**: SystemCapability.Multimedia.Media.VideoRecorder
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ---------------------------- |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example**
```js
// asyncallback
videoRecorder.stop((err) => {
if (typeof (err) == 'undefined') {
console.info('stop videorecorder success');
} else {
console.info('stop videorecorder failed and error is ' + err.message);
}
});
```
### stop<sup>9+</sup><a name=videorecorder_stop2></a>
stop(): Promise\<void>;
Stops video recording in asynchronous mode. This API uses a promise to return the result.
To start another recording, you must call [prepare()](#videorecorder_prepare1) and [getInputSurface()](#getinputsurface8) again.
**System capability**: SystemCapability.Multimedia.Media.VideoRecorder
**Return value**
| Type | Description |
| -------------- | ------------------------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```js
// promise
videoRecorder.stop().then(() => {
console.info('stop videorecorder success');
}).catch((err) => {
console.info('stop videorecorder failed and catch error is ' + err.message);
});
```
### release<sup>9+</sup><a name=videorecorder_release1></a>
release(callback: AsyncCallback\<void>): void;
Releases the video recording resource in asynchronous mode. This API uses a callback to return the result.
**System capability**: SystemCapability.Multimedia.Media.VideoRecorder
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | -------------------------------- |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example**
```js
// asyncallback
videoRecorder.release((err) => {
if (typeof (err) == 'undefined') {
console.info('release videorecorder success');
} else {
console.info('release videorecorder failed and error is ' + err.message);
}
});
```
### release<sup>9+</sup><a name=videorecorder_release2></a>
release(): Promise\<void>;
Releases the video recording resource in asynchronous mode. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Media.VideoRecorder
**Return value**
| Type | Description |
| -------------- | ----------------------------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```js
// promise
videoRecorder.release().then(() => {
console.info('release videorecorder success');
}).catch((err) => {
console.info('release videorecorder failed and catch error is ' + err.message);
});
```
### reset<sup>9+</sup><a name=videorecorder_reset1></a>
reset(callback: AsyncCallback\<void>): void;
Resets video recording in asynchronous mode. This API uses a callback to return the result.
To start another recording, you must call [prepare()](#videorecorder_prepare1) and [getInputSurface()](#getinputsurface8) again.
**System capability**: SystemCapability.Multimedia.Media.VideoRecorder
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ---------------------------- |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example**
```js
// asyncallback
videoRecorder.reset((err) => {
if (typeof (err) == 'undefined') {
console.info('reset videorecorder success');
} else {
console.info('reset videorecorder failed and error is ' + err.message);
}
});
```
### reset<sup>9+</sup><a name=videorecorder_reset2></a>
reset(): Promise\<void>;
Resets video recording in asynchronous mode. This API uses a promise to return the result.
To start another recording, you must call [prepare()](#videorecorder_prepare1) and [getInputSurface()](#getinputsurface8) again.
**System capability**: SystemCapability.Multimedia.Media.VideoRecorder
**Return value**
| Type | Description |
| -------------- | ------------------------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```js
// promise
videoRecorder.reset().then(() => {
console.info('reset videorecorder success');
}).catch((err) => {
console.info('reset videorecorder failed and catch error is ' + err.message);
});
```
### on('error')<sup>9+</sup>
on(type: 'error', callback: ErrorCallback): void
Subscribes to the video recording error event.
**System capability**: SystemCapability.Multimedia.Media.VideoRecorder
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------- | ---- | ------------------------------------------------------------ |
| type | string | Yes | Type of the event to subscribe to, which is 'error' in this API.<br>The 'error' event is triggered when an error occurs during video recording.|
| callback | ErrorCallback | Yes | Callback invoked when the event is triggered. |
**Example**
```js
videoRecorder.on('error', (error) => { // Set the 'error' event callback.
console.info(`audio error called, errName is ${error.name}`); // Print the error name.
console.info(`audio error called, errCode is ${error.code}`); // Print the error code.
console.info(`audio error called, errMessage is ${error.message}`); // Print the detailed description of the error type.
});
// This event is reported when an error occurs during the retrieval of videoRecordState.
```
## VideoRecordState<sup>9+</sup>
Enumerates the video recording states. You can obtain the state through the **state** attribute.
**System capability**: SystemCapability.Multimedia.Media.VideoRecorder
| Name | Type | Description |
| -------- | ------ | ---------------------- |
| idle | string | The video recorder is idle. |
| prepared | string | The video recording parameters are set.|
| playing | string | Video recording is in progress. |
| paused | string | Video recording is paused. |
| stopped | string | Video recording is stopped. |
| error | string | Video recording is in the error state. |
## VideoRecorderConfig<sup>9+</sup>
Describes the video recording parameters.
**System capability**: SystemCapability.Multimedia.Media.VideoRecorder
| Name | Type | Mandatory| Description |
| --------------- | ---------------------------------------------- | ---- | ------------------------------------------------------------ |
| audioSourceType | [AudioSourceType](#audiosourcetype9) | Yes | Type of the audio source for video recording. |
| videoSourceType | [VideoSourceType](#videosourcetype9) | Yes | Type of the video source for video recording. |
| profile | [VideoRecorderProfile](#videorecorderprofile9) | Yes | Video recording profile. |
| rotation | number | No | Rotation angle of the recorded video. |
| location | [Location](#location) | No | Geographical location of the recorded video. |
| url | string | Yes | Video output URL. Supported: fd://xx&nbsp;(fd&nbsp;number)<br>![](figures/en-us_image_url.png)<br>The file must be created by the caller and granted with proper permissions.|
## AudioSourceType<sup>9+</sup>
Enumerates the audio source types for video recording.
**System capability**: SystemCapability.Multimedia.Media.VideoRecorder
| Name | Value | Description |
| ------------------------- | ---- | ---------------------- |
| AUDIO_SOURCE_TYPE_DEFAULT | 0 | Default audio input source.|
| AUDIO_SOURCE_TYPE_MIC | 1 | Mic audio input source. |
## VideoSourceType<sup>9+</sup>
Enumerates the video source types for video recording.
**System capability**: SystemCapability.Multimedia.Media.VideoRecorder
| Name | Value | Description |
| ----------------------------- | ---- | ------------------------------- |
| VIDEO_SOURCE_TYPE_SURFACE_YUV | 0 | The input surface carries raw data.|
| VIDEO_SOURCE_TYPE_SURFACE_ES | 1 | The input surface carries ES data. |
## VideoRecorderProfile<sup>9+</sup>
Describes the video recording profile.
**System capability**: SystemCapability.Multimedia.Media.VideoRecorder
| Name | Type | Mandatory| Description |
| ---------------- | -------------------------------------------- | ---- | ---------------- |
| audioBitrate | number | Yes | Audio encoding bit rate.|
| audioChannels | number | Yes | Number of audio channels.|
| audioCodec | [CodecMimeType](#codecmimetype8) | Yes | Audio encoding format. |
| audioSampleRate | number | Yes | Audio sampling rate. |
| fileFormat | [ContainerFormatType](#containerformattype8) | Yes | Container format of a file.|
| videoBitrate | number | Yes | Video encoding bit rate.|
| videoCodec | [CodecMimeType](#codecmimetype8) | Yes | Video encoding format. |
| videoFrameWidth | number | Yes | Width of the recorded video frame.|
| videoFrameHeight | number | Yes | Height of the recorded video frame.|
| videoFrameRate | number | Yes | Video frame rate. |
## ContainerFormatType<sup>8+</sup> ## ContainerFormatType<sup>8+</sup>
Enumerates the container format types (CFTs). Enumerates the container format types (CFTs).
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册