diff --git a/en/application-dev/media/audio-playback.md b/en/application-dev/media/audio-playback.md
index 2124319f5e48f70657ce21c8d4f90b35136b2a37..085506f3c514624f8fd8a2a8526b149a8e0927a8 100644
--- a/en/application-dev/media/audio-playback.md
+++ b/en/application-dev/media/audio-playback.md
@@ -16,38 +16,49 @@ You can use audio playback APIs to convert audio data into audible analog signal
## How to Develop
-For details about the APIs used for audio playback, see [AudioPlayer in the Media API](../reference/apis/js-apis-media.md).
+For details about the APIs, see [AudioPlayer in the Media API](../reference/apis/js-apis-media.md).
### Full-Process Scenario
The full audio playback process includes creating an instance, setting the URI, playing audio, seeking to the playback position, setting the volume, pausing playback, obtaining track information, stopping playback, resetting the player, and releasing resources.
-For details about the **src** media source input types supported by **AudioPlayer**, see the [src attribute](../reference/apis/js-apis-media.md#audioplayer_attributes).
+For details about the **src** types supported by **AudioPlayer**, see the [src attribute](../reference/apis/js-apis-media.md#audioplayer_attributes).
```js
import media from '@ohos.multimedia.media'
import fileIO from '@ohos.fileio'
-function SetCallBack(audioPlayer) {
+// Print the stream track information.
+function printfDescription(obj) {
+ for (let item in obj) {
+ let property = obj[item];
+ console.info('audio key is ' + item);
+ console.info('audio value is ' + property);
+ }
+}
+
+// Set the player callbacks.
+function setCallBack(audioPlayer) {
audioPlayer.on('dataLoad', () => { // Set the 'dataLoad' event callback, which is triggered when the src attribute is set successfully.
console.info('audio set source success');
- // The playback page is ready. You can click the Play button to start the playback.
+ audioPlayer.play(); // The play() API can be invoked only after the 'dataLoad' event callback is complete. The 'play' event callback is then triggered.
});
audioPlayer.on('play', () => { // Set the 'play' event callback.
console.info('audio play success');
- // The Play button is changed to the pausable state.
+ audioPlayer.pause(); // Trigger the 'pause' event callback and pause the playback.
});
audioPlayer.on('pause', () => { // Set the 'pause' event callback.
console.info('audio pause success');
- // The Play button is changed to the playable state.
+ audioPlayer.seek(5000); // Trigger the 'timeUpdate' event callback, and seek to 5000 ms for playback.
});
audioPlayer.on('stop', () => { // Set the 'stop' event callback.
console.info('audio stop success');
- // The playback stops, the playback progress bar returns to 0, and the Play button is changed to the playable state.
+ audioPlayer.reset(); // Trigger the 'reset' event callback, and reconfigure the src attribute to switch to the next song.
});
audioPlayer.on('reset', () => { // Set the 'reset' event callback.
console.info('audio reset success');
- // You can reconfigure the src attribute to play another audio file.
+ audioPlayer.release(); // Release the AudioPlayer resources.
+ audioPlayer = undefined;
});
audioPlayer.on('timeUpdate', (seekDoneTime) => {// Set the 'timeUpdate' event callback.
if (typeof(seekDoneTime) == 'undefined') {
@@ -55,71 +66,49 @@ function SetCallBack(audioPlayer) {
return;
}
console.info('audio seek success, and seek time is ' + seekDoneTime);
- // The playback progress bar is updated to the seek position.
+ audioPlayer.setVolume(0.5); // Trigger the 'volumeChange' event callback.
});
audioPlayer.on('volumeChange', () => { // Set the 'volumeChange' event callback.
console.info('audio volumeChange success');
- // Display the updated volume.
+ audioPlayer.getTrackDescription((error, arrlist) => { // Obtain the audio track information in callback mode.
+ if (typeof (arrlist) != 'undefined') {
+ for (let i = 0; i < arrlist.length; i++) {
+ printfDescription(arrlist[i]);
+ }
+ } else {
+ console.log(`audio getTrackDescription fail, error:${error.message}`);
+ }
+ audioPlayer.stop(); // Trigger the 'stop' event callback to stop the playback.
+ });
});
- audioPlayer.on('finish', () => { // Set the 'finish' event callback, which is triggered when the playback is complete.
+ audioPlayer.on('finish', () => { // Set the 'finish' event callback, which is triggered when the playback is complete.
console.info('audio play finish');
});
- audioPlayer.on('error', (error) => { // Set the 'error' event callback.
+ audioPlayer.on('error', (error) => { // Set the 'error' event callback.
console.info(`audio error called, errName is ${error.name}`);
console.info(`audio error called, errCode is ${error.code}`);
console.info(`audio error called, errMessage is ${error.message}`);
});
}
-function printfDescription(obj) {
- for (let item in obj) {
- let property = obj[item];
- console.info('audio key is ' + item);
- console.info('audio value is ' + property);
- }
+async function audioPlayerDemo() {
+ // 1. Create an audioPlayer instance.
+ let audioPlayer = media.createAudioPlayer();
+ setCallBack(audioPlayer); // Set the event callbacks.
+ // 2. Set the URI of the audio file selected by the user.
+ let fdPath = 'fd://'
+ // The stream in the path can be pushed to the device by running the "hdc file send D:\xxx\01.mp3 /data/app/el1/bundle/public/ohos.acts.multimedia.audio.audioplayer/ohos.acts.multimedia.audio.audioplayer/assets/entry/resources/rawfile" command.
+ let path = '/data/app/el1/bundle/public/ohos.acts.multimedia.audio.audioplayer/ohos.acts.multimedia.audio.audioplayer/assets/entry/resources/rawfile/01.mp3';
+ 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);
+ });
+ audioPlayer.src = fdPath; // Set the src attribute and trigger the 'dataLoad' event callback.
}
-
-// 1. Create an audioPlayer instance.
-let audioPlayer = media.createAudioPlayer();
-SetCallBack(audioPlayer); // Set the event callbacks.
-// 2. Set the URI of the audio file selected by the user.
-let fdPath = 'fd://'
-let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3';
-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);
-});
-
-audioPlayer.src = fdPath; // Set the src attribute and trigger the 'dataLoad' event callback.
-// 3. Play the audio file.
-audioPlayer.play(); // The play() API can be invoked only after the 'dataLoad' event callback is complete. The 'play' event callback is triggered.
-// 4. Seek to the playback position.
-audioPlayer.seek(30000); // Trigger the 'timeUpdate' event callback, and seek to 30000 ms for playback.
-// 5. Set the volume.
-audioPlayer.setVolume(0.5); // Trigger the 'volumeChange' event callback.
-// 6. Pause the playback.
-audioPlayer.pause(); // Trigger the 'pause' event callback and pause the playback.
-// 7. Obtain the track information.
-audioPlayer.getTrackDescription((error, arrlist) => { // Obtain the audio track information in callback mode.
- if (typeof (arrlist) != 'undefined') {
- for (let i = 0; i < arrlist.length; i++) {
- printfDescription(arrlist[i]);
- }
- } else {
- console.log(`audio getTrackDescription fail, error:${error.message}`);
- }
-});
-// 8. Stop the playback.
-audioPlayer.stop(); // Trigger the 'stop' event callback.
-// 9. Reset the player.
-audioPlayer.reset(); // Trigger the 'reset' event callback, and reconfigure the src attribute to switch to the next song.
-// 10. Release the resource.
-audioPlayer.release(); // Release the AudioPlayer instance.
-audioPlayer = undefined;
```
### Normal Playback Scenario
@@ -127,37 +116,40 @@ audioPlayer = undefined;
```js
import media from '@ohos.multimedia.media'
import fileIO from '@ohos.fileio'
-
-function SetCallBack(audioPlayer) {
+export class AudioDemo {
+ // Set the player callbacks.
+ setCallBack(audioPlayer) {
audioPlayer.on('dataLoad', () => { // Set the 'dataLoad' event callback, which is triggered when the src attribute is set successfully.
- console.info('audio set source success');
- audioPlayer.play(); // Call the play() API to start the playback and trigger the 'play' event callback.
+ console.info('audio set source success');
+ audioPlayer.play(); // Call the play() API to start the playback and trigger the 'play' event callback.
});
audioPlayer.on('play', () => { // Set the 'play' event callback.
- console.info('audio play success');
+ console.info('audio play success');
});
audioPlayer.on('finish', () => { // Set the 'finish' event callback, which is triggered when the playback is complete.
- console.info('audio play finish');
- audioPlayer.release(); // Release the AudioPlayer instance.
- audioPlayer = undefined;
+ console.info('audio play finish');
+ audioPlayer.release(); // Release the AudioPlayer resources.
+ audioPlayer = undefined;
+ });
+ }
+
+ async audioPlayerDemo() {
+ let audioPlayer = media.createAudioPlayer(); // Create an AudioPlayer instance.
+ this.setCallBack(audioPlayer); // Set the event callbacks.
+ let fdPath = 'fd://'
+ // The stream in the path can be pushed to the device by running the "hdc file send D:\xxx\01.mp3 /data/app/el1/bundle/public/ohos.acts.multimedia.audio.audioplayer/ohos.acts.multimedia.audio.audioplayer/assets/entry/resources/rawfile" command.
+ let path = '/data/app/el1/bundle/public/ohos.acts.multimedia.audio.audioplayer/ohos.acts.multimedia.audio.audioplayer/assets/entry/resources/rawfile/01.mp3';
+ 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);
});
+ audioPlayer.src = fdPath; // Set the src attribute and trigger the 'dataLoad' event callback.
+ }
}
-
-let audioPlayer = media.createAudioPlayer(); // Create an AudioPlayer instance.
-SetCallBack(audioPlayer); // Set the event callbacks.
-/* Set the FD (local playback) of the audio file selected by the user. */
-let fdPath = 'fd://'
-let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3';
-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);
-});
-
-audioPlayer.src = fdPath; // Set the src attribute and trigger the 'dataLoad' event callback.
```
### Switching to the Next Song
@@ -165,52 +157,62 @@ audioPlayer.src = fdPath; // Set the src attribute and
```js
import media from '@ohos.multimedia.media'
import fileIO from '@ohos.fileio'
-
-function SetCallBack(audioPlayer) {
+export class AudioDemo {
+// Set the player callbacks.
+ private isNextMusic = false;
+ setCallBack(audioPlayer) {
audioPlayer.on('dataLoad', () => { // Set the 'dataLoad' event callback, which is triggered when the src attribute is set successfully.
- console.info('audio set source success');
- audioPlayer.play(); // Call the play() API to start the playback and trigger the 'play' event callback.
+ console.info('audio set source success');
+ audioPlayer.play(); // Call the play() API to start the playback and trigger the 'play' event callback.
});
audioPlayer.on('play', () => { // Set the 'play' event callback.
- console.info('audio play success');
+ console.info('audio play success');
+ audioPlayer.reset(); // Call the reset() API and trigger the 'reset' event callback.
});
- audioPlayer.on('finish', () => { // Set the 'finish' event callback, which is triggered when the playback is complete.
- console.info('audio play finish');
+ audioPlayer.on('reset', () => { // Set the 'reset' event callback.
+ console.info('audio play success');
+ if (!this.isNextMusic) { // When isNextMusic is false, changing songs is implemented.
+ this.nextMusic(audioPlayer); // Changing songs is implemented.
+ } else {
audioPlayer.release(); // Release the AudioPlayer instance.
- audioPlayer = undefined;
+ audioPlayer = undefined;
+ }
});
+ }
+
+ async nextMusic(audioPlayer) {
+ this.isNextMusic = true;
+ let nextFdPath = 'fd://'
+ // The stream in the path can be pushed to the device by running the "hdc file send D:\xxx\02.mp3 /data/app/el1/bundle/public/ohos.acts.multimedia.audio.audioplayer/ohos.acts.multimedia.audio.audioplayer/assets/entry/resources/rawfile" command.
+ let nextpath = '/data/app/el1/bundle/public/ohos.acts.multimedia.audio.audioplayer/ohos.acts.multimedia.audio.audioplayer/assets/entry/resources/rawfile/02.mp3';
+ await fileIO.open(nextpath).then((fdNumber) => {
+ nextFdPath = nextFdPath + '' + fdNumber;
+ console.info('open fd sucess fd is' + nextFdPath);
+ }, (err) => {
+ console.info('open fd failed err is' + err);
+ }).catch((err) => {
+ console.info('open fd failed err is' + err);
+ });
+ audioPlayer.src = nextFdPath; // Set the src attribute and trigger the 'dataLoad' event callback.
+ }
+
+ async audioPlayerDemo() {
+ let audioPlayer = media.createAudioPlayer(); // Create an AudioPlayer instance.
+ this.setCallBack(audioPlayer); // Set the event callbacks.
+ let fdPath = 'fd://'
+ // The stream in the path can be pushed to the device by running the "hdc file send D:\xxx\01.mp3 /data/app/el1/bundle/public/ohos.acts.multimedia.audio.audioplayer/ohos.acts.multimedia.audio.audioplayer/assets/entry/resources/rawfile" command.
+ let path = '/data/app/el1/bundle/public/ohos.acts.multimedia.audio.audioplayer/ohos.acts.multimedia.audio.audioplayer/assets/entry/resources/rawfile/01.mp3';
+ 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);
+ });
+ audioPlayer.src = fdPath; // Set the src attribute and trigger the 'dataLoad' event callback.
+ }
}
-
-let audioPlayer = media.createAudioPlayer(); // Create an AudioPlayer instance.
-SetCallBack(audioPlayer); // Set the event callbacks.
-/* Set the FD (local playback) of the audio file selected by the user. */
-let fdPath = 'fd://'
-let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3';
-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);
-});
-
-audioPlayer.src = fdPath; // Set the src attribute and trigger the 'dataLoad' event callback.
-/* Send the instruction to switch to the next song after a period of time. */
-audioPlayer.reset();
-
-/* Set the FD (local playback) of the audio file selected by the user. */
-let fdNextPath = 'fd://'
-let nextPath = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3';
-await fileIO.open(nextPath).then(fdNumber) => {
- fdNextPath = fdNextPath + '' + fdNumber;
- console.info('open fd sucess fd is' + fdNextPath);
-}, (err) => {
- console.info('open fd failed err is' + err);
-}),catch((err) => {
- console.info('open fd failed err is' + err);
-});
-audioPlayer.src = fdNextPath;
```
### Looping a Song
@@ -218,37 +220,43 @@ audioPlayer.src = fdNextPath;
```js
import media from '@ohos.multimedia.media'
import fileIO from '@ohos.fileio'
-
-function SetCallBack(audioPlayer) {
+export class AudioDemo {
+ // Set the player callbacks.
+ setCallBack(audioPlayer) {
audioPlayer.on('dataLoad', () => { // Set the 'dataLoad' event callback, which is triggered when the src attribute is set successfully.
- console.info('audio set source success');
- audioPlayer.play(); // Call the play() API to start the playback and trigger the 'play' event callback.
+ console.info('audio set source success');
+ audioPlayer.loop = true; // Set the loop playback attribute.
+ audioPlayer.play(); // Call the play() API to start the playback and trigger the 'play' event callback.
});
- audioPlayer.on('play', () => { // Set the 'play' event callback.
- console.info('audio play success');
+ audioPlayer.on('play', () => { // Sets the 'play' event callback to start loop playback.
+ console.info('audio play success');
});
- audioPlayer.on('finish', () => { // Set the 'finish' event callback, which is triggered when the playback is complete.
- console.info('audio play finish');
- audioPlayer.release(); // Release the AudioPlayer instance.
- audioPlayer = undefined;
+ }
+
+ async audioPlayerDemo() {
+ let audioPlayer = media.createAudioPlayer(); // Create an AudioPlayer instance.
+ this.setCallBack(audioPlayer); // Set the event callbacks.
+ let fdPath = 'fd://'
+ // The stream in the path can be pushed to the device by running the "hdc file send D:\xxx\01.mp3 /data/app/el1/bundle/public/ohos.acts.multimedia.audio.audioplayer/ohos.acts.multimedia.audio.audioplayer/assets/entry/resources/rawfile" command.
+ let path = '/data/app/el1/bundle/public/ohos.acts.multimedia.audio.audioplayer/ohos.acts.multimedia.audio.audioplayer/assets/entry/resources/rawfile/01.mp3';
+ 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);
});
+ audioPlayer.src = fdPath; // Set the src attribute and trigger the 'dataLoad' event callback.
+ }
}
-
-let audioPlayer = media.createAudioPlayer(); // Create an AudioPlayer instance.
-SetCallBack(audioPlayer); // Set the event callbacks.
-
-/* Set the FD (local playback) of the audio file selected by the user. */
-let fdPath = 'fd://'
-let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3';
-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);
-});
-
-audioPlayer.src = fdPath; // Set the src attribute and trigger the 'dataLoad' event callback.
-audioPlayer.loop = true; // Set the loop playback attribute.
```
+
+## Samples
+
+The following samples are provided to help you better understand how to develop audio playback:
+
+- [`JsDistributedMusicPlayer`: Distributed Music Player (JS) (API7)](https://gitee.com/openharmony/app_samples/tree/master/ability/JsDistributedMusicPlayer)
+- [`JsAudioPlayer`: Audio Playback and Management (JS, API 7)](https://gitee.com/openharmony/app_samples/tree/master/media/JsAudioPlayer)
+- [`eTsAudioPlayer`: Audio Player (eTS)](https://gitee.com/openharmony/app_samples/blob/master/media/Recorder/entry/src/main/ets/MainAbility/pages/Play.ets)
+- [Audio Player](https://gitee.com/openharmony/codelabs/tree/master/Media/Audio_OH_ETS)
diff --git a/en/application-dev/media/audio-recorder.md b/en/application-dev/media/audio-recorder.md
index 56f72dc5a475a6ba697e204117488c17a8c6846d..cd8d8ee0d976d6a2ee56cdb0e7ad93d2d46ac05d 100644
--- a/en/application-dev/media/audio-recorder.md
+++ b/en/application-dev/media/audio-recorder.md
@@ -25,46 +25,49 @@ The full audio recording process includes creating an instance, setting recordin
```js
import media from '@ohos.multimedia.media'
import mediaLibrary from '@ohos.multimedia.mediaLibrary'
-
-let testFdNumber;
-
-function SetCallBack(audioRecorder) {
- audioRecorder.on('prepare', () => { // Set the 'prepare' event callback.
- console.log('prepare success');
- // The recording page is ready. You can click the Record button to start recording.
+export class AudioRecorderDemo {
+ private testFdNumber; // Used to save the FD address.
+
+ // Set the callbacks related to audio recording.
+ setCallBack(audioRecorder) {
+ audioRecorder.on('prepare', () => { // Set the 'prepare' event callback.
+ console.log('prepare success');
+ audioRecorder.start(); // Call the start API to start recording and trigger the 'start' event callback.
});
- audioRecorder.on('start', () => { // Set the 'start' event callback.
- console.log('audio recorder start success');
- // The Record button is changed to the pausable state.
+ audioRecorder.on('start', () => { // Set the 'start' event callback.
+ console.log('audio recorder start success');
+ audioRecorder.pause(); // Call the pause API to pause recording and trigger the 'pause' event callback.
});
- audioRecorder.on('pause', () => { // Set the 'pause' event callback.
- console.log('audio recorder pause success');
- // The Record button is changed to the recordable state.
+ audioRecorder.on('pause', () => { // Set the 'pause' event callback.
+ console.log('audio recorder pause success');
+ audioRecorder.resume(); // Call the resume API to resume recording and trigger the 'resume' event callback.
});
- audioRecorder.on('resume', () => { // Set the 'resume' event callback.
- console.log('audio recorder resume success');
- // The Record button is changed to the pausable state.
+ audioRecorder.on('resume', () => { // Set the 'resume' event callback.
+ console.log('audio recorder resume success');
+ audioRecorder.stop(); // Call the stop API to stop recording and trigger the 'stop' event callback.
});
- audioRecorder.on('stop', () => { // Set the 'stop' event callback.
- console.log('audio recorder stop success');
+ audioRecorder.on('stop', () => { // Set the 'stop' event callback.
+ console.log('audio recorder stop success');
+ audioRecorder.reset(); // Call the reset API to reset the recorder and trigger the 'reset' event callback.
});
- audioRecorder.on('release', () => { // Set the 'release' event callback.
- console.log('audio recorder release success');
+ audioRecorder.on('reset', () => { // Set the 'reset' event callback.
+ console.log('audio recorder reset success');
+ audioRecorder.release(); // Call the release API to release resources and trigger the 'release' event callback.
});
- audioRecorder.on('reset', () => { // Set the 'reset' event callback.
- console.log('audio recorder reset success');
- // You need to reset the recording parameters for another recording.
+ audioRecorder.on('release', () => { // Set the 'release' event callback.
+ console.log('audio recorder release success');
+ audioRecorder = undefined;
});
- audioRecorder.on('error', (error) => { // Set the 'error' event callback.
- console.info(`audio error called, errName is ${error.name}`);
- console.info(`audio error called, errCode is ${error.code}`);
- console.info(`audio error called, errMessage is ${error.message}`);
+ audioRecorder.on('error', (error) => { // Set the 'error' event callback.
+ console.info(`audio error called, errName is ${error.name}`);
+ console.info(`audio error called, errCode is ${error.code}`);
+ console.info(`audio error called, errMessage is ${error.message}`);
});
-}
+ }
-// pathName indicates the passed recording file name, for example, 01.mp3. The generated file address is /storage/media/100/local/files/Movies/01.mp3.
-// To use the media library, declare the following permissions: ohos.permission.MEDIA_LOCATION, ohos.permission.WRITE_MEDIA, and ohos.permission.READ_MEDIA.
-async function getFd(pathName) {
+ // pathName indicates the passed recording file name, for example, 01.mp3. The generated file address is /storage/media/100/local/files/Video/01.mp3.
+ // To use the media library, declare the following permissions: ohos.permission.MEDIA_LOCATION, ohos.permission.WRITE_MEDIA, and ohos.permission.READ_MEDIA.
+ async getFd(pathName) {
let displayName = pathName;
const mediaTest = mediaLibrary.getMediaLibrary();
let fileKeyObj = mediaLibrary.FileKey;
@@ -72,49 +75,37 @@ async function getFd(pathName) {
let publicPath = await mediaTest.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO);
let dataUri = await mediaTest.createAsset(mediaType, displayName, publicPath);
if (dataUri != undefined) {
- let args = dataUri.id.toString();
- let fetchOp = {
- selections : fileKeyObj.ID + "=?",
- selectionArgs : [args],
- }
- let fetchFileResult = await mediaTest.getFileAssets(fetchOp);
- let fileAsset = await fetchFileResult.getAllObject();
- let fdNumber = await fileAsset[0].open('Rw');
- fdNumber = "fd://" + fdNumber.toString();
- testFdNumber = fdNumber;
+ let args = dataUri.id.toString();
+ let fetchOp = {
+ selections : fileKeyObj.ID + "=?",
+ selectionArgs : [args],
+ }
+ let fetchFileResult = await mediaTest.getFileAssets(fetchOp);
+ let fileAsset = await fetchFileResult.getAllObject();
+ let fdNumber = await fileAsset[0].open('Rw');
+ this.testFdNumber = "fd://" + fdNumber.toString();
}
+ }
+
+ async audioRecorderDemo() {
+ // 1. Create an AudioRecorder instance.
+ let audioRecorder = media.createAudioRecorder();
+ // 2. Set the callbacks.
+ this.setCallBack(audioRecorder);
+ await this.getFd('01.mp3'); // Call the getFd method to obtain the FD address of the file to be recorded.
+ // 3. Set the recording parameters.
+ let audioRecorderConfig = {
+ audioEncodeBitRate : 22050,
+ audioSampleRate : 22050,
+ numberOfChannels : 2,
+ uri : this.testFdNumber, // testFdNumber is generated by getFd.
+ location : { latitude : 30, longitude : 130},
+ audioEncoderMime : media.CodecMimeType.AUDIO_AAC,
+ fileFormat : media.ContainerFormatType.CFT_MPEG_4A,
+ }
+ audioRecorder.prepare(audioRecorderConfig); // Call the prepare method to trigger the 'prepare' event callback.
+ }
}
-
-await getFd('01.mp3');
-
-// 1. Create an AudioRecorder instance.
-let audioRecorder = media.createAudioRecorder();
-// 2. Set the callbacks.
-SetCallBack(audioRecorder);
-// 3. Set the recording parameters.
-let audioRecorderConfig = {
- audioEncoder : media.AudioEncoder.AAC_LC ,
- audioEncodeBitRate : 22050,
- audioSampleRate : 22050,
- numberOfChannels : 2,
- format : media.AudioOutputFormat.AAC_ADTS,
- uri : testFdNumber, // testFdNumber is generated by getFd.
- location : { latitude : 30, longitude : 130},
-}
-audioRecorder.prepare(audioRecorderConfig);
-// 4. Start recording.
-audioRecorder.start(); // The start API can be called to trigger the 'start' event callback only after the 'prepare' event callback is complete.
-// 5. Pause recording.
-audioRecorder.pause(); // The pause API can be called to trigger the 'pause' event callback only after the 'start' event callback is complete.
-// 6. Resume recording.
-audioRecorder.resume(); // The resume API can be called to trigger the 'resume' event callback only after the 'pause' event callback is complete.
-// 7. Stop recording.
-audioRecorder.stop(); // The stop API can be called to trigger the 'stop' event callback only after the 'start' or 'resume' event callback is complete.
-// 8. Reset recording.
-audioRecorder.reset(); // The prepare API can be called for another recording only after the 'reset' event callback is complete.
-// 9. Release resources.
-audioRecorder.release(); // The AudioRecorder resource is destroyed.
-audioRecorder = undefined;
```
### Normal Recording Scenario
@@ -124,29 +115,37 @@ Unlike the full-process scenario, the normal recording scenario does not include
```js
import media from '@ohos.multimedia.media'
import mediaLibrary from '@ohos.multimedia.mediaLibrary'
-
-let testFdNumber;
-
-function SetCallBack(audioRecorder) {
- audioRecorder.on('prepare', () => { // Set the 'prepare' event callback.
- console.log('prepare success');
- // The recording page is ready. You can click the Record button to start recording.
+export class AudioRecorderDemo {
+ private testFdNumber; // Used to save the FD address.
+
+ // Set the callbacks related to audio recording.
+ setCallBack(audioRecorder) {
+ audioRecorder.on('prepare', () => { // Set the 'prepare' event callback.
+ console.log('prepare success');
+ audioRecorder.start(); // Call the start API to start recording and trigger the 'start' event callback.
});
- audioRecorder.on('start', () => { // Set the 'start' event callback.
- console.log('audio recorder start success');
- // The Record button is changed to the pausable state.
- });
- audioRecorder.on('stop', () => { // Set the 'stop' event callback.
- console.log('audio recorder stop success');
- });
- audioRecorder.on('release', () => { // Set the 'release' event callback.
- console.log('audio recorder release success');
- });
-}
+ audioRecorder.on('start', () => { // Set the 'start' event callback.
+ console.log('audio recorder start success');
+ audioRecorder.stop(); // Call the stop API to stop recording and trigger the 'stop' event callback.
+ });
+ audioRecorder.on('stop', () => { // Set the 'stop' event callback.
+ console.log('audio recorder stop success');
+ audioRecorder.release(); // Call the release API to release resources and trigger the 'release' event callback.
+ });
+ audioRecorder.on('release', () => { // Set the 'release' event callback.
+ console.log('audio recorder release success');
+ audioRecorder = undefined;
+ });
+ audioRecorder.on('error', (error) => { // Set the 'error' event callback.
+ console.info(`audio error called, errName is ${error.name}`);
+ console.info(`audio error called, errCode is ${error.code}`);
+ console.info(`audio error called, errMessage is ${error.message}`);
+ });
+ }
-// pathName indicates the passed recording file name, for example, 01.mp3. The generated file address is /storage/media/100/local/files/Movies/01.mp3.
-// To use the media library, declare the following permissions: ohos.permission.MEDIA_LOCATION, ohos.permission.WRITE_MEDIA, and ohos.permission.READ_MEDIA.
-async function getFd(pathName) {
+ // pathName indicates the passed recording file name, for example, 01.mp3. The generated file address is /storage/media/100/local/files/Video/01.mp3.
+ // To use the media library, declare the following permissions: ohos.permission.MEDIA_LOCATION, ohos.permission.WRITE_MEDIA, and ohos.permission.READ_MEDIA.
+ async getFd(pathName) {
let displayName = pathName;
const mediaTest = mediaLibrary.getMediaLibrary();
let fileKeyObj = mediaLibrary.FileKey;
@@ -154,41 +153,43 @@ async function getFd(pathName) {
let publicPath = await mediaTest.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO);
let dataUri = await mediaTest.createAsset(mediaType, displayName, publicPath);
if (dataUri != undefined) {
- let args = dataUri.id.toString();
- let fetchOp = {
- selections : fileKeyObj.ID + "=?",
- selectionArgs : [args],
- }
- let fetchFileResult = await mediaTest.getFileAssets(fetchOp);
- let fileAsset = await fetchFileResult.getAllObject();
- let fdNumber = await fileAsset[0].open('Rw');
- fdNumber = "fd://" + fdNumber.toString();
- testFdNumber = fdNumber;
+ let args = dataUri.id.toString();
+ let fetchOp = {
+ selections : fileKeyObj.ID + "=?",
+ selectionArgs : [args],
+ }
+ let fetchFileResult = await mediaTest.getFileAssets(fetchOp);
+ let fileAsset = await fetchFileResult.getAllObject();
+ let fdNumber = await fileAsset[0].open('Rw');
+ this.testFdNumber = "fd://" + fdNumber.toString();
}
+ }
+
+ async audioRecorderDemo() {
+ // 1. Create an AudioRecorder instance.
+ let audioRecorder = media.createAudioRecorder();
+ // 2. Set the callbacks.
+ this.setCallBack(audioRecorder);
+ await this.getFd('01.mp3'); // Call the getFd method to obtain the FD address of the file to be recorded.
+ // 3. Set the recording parameters.
+ let audioRecorderConfig = {
+ audioEncodeBitRate : 22050,
+ audioSampleRate : 22050,
+ numberOfChannels : 2,
+ uri : this.testFdNumber, // testFdNumber is generated by getFd.
+ location : { latitude : 30, longitude : 130},
+ audioEncoderMime : media.CodecMimeType.AUDIO_AAC,
+ fileFormat : media.ContainerFormatType.CFT_MPEG_4A,
+ }
+ audioRecorder.prepare(audioRecorderConfig); // Call the prepare method to trigger the 'prepare' event callback.
+ }
}
-
-await getFd('01.mp3');
-
-// 1. Create an AudioRecorder instance.
-let audioRecorder = media.createAudioRecorder();
-// 2. Set the callbacks.
-SetCallBack(audioRecorder);
-// 3. Set the recording parameters.
-let audioRecorderConfig = {
- audioEncoder : media.AudioEncoder.AAC_LC ,
- audioEncodeBitRate : 22050,
- audioSampleRate : 22050,
- numberOfChannels : 2,
- format : media.AudioOutputFormat.AAC_ADTS,
- uri : testFdNumber, // testFdNumber is generated by getFd.
- location : { latitude : 30, longitude : 130},
-}
-audioRecorder.prepare(audioRecorderConfig)
-// 4. Start recording.
-audioRecorder.start(); // The start API can be called to trigger the 'start' event callback only after the 'prepare' event callback is complete.
-// 5. Stop recording.
-audioRecorder.stop(); // The stop API can be called to trigger the 'stop' event callback only after the 'start' or 'resume' event callback is complete.
-// 6. Release resources.
-audioRecorder.release(); // The AudioRecorder resource is destroyed.
-audioRecorder = undefined;
```
+
+## Samples
+
+The following samples are provided to help you better understand how to develop audio recording:
+
+- [`Recorder`: Recorder (eTS, API 8)](https://gitee.com/openharmony/app_samples/tree/master/media/Recorder)
+- [`eTsAudioPlayer`: Audio Player (eTS)](https://gitee.com/openharmony/app_samples/blob/master/media/Recorder/entry/src/main/ets/MainAbility/pages/Play.ets)
+- [Audio Player](https://gitee.com/openharmony/codelabs/tree/master/Media/Audio_OH_ETS)
diff --git a/en/application-dev/media/video-playback.md b/en/application-dev/media/video-playback.md
index 946e975a2bf13af7c1ce8d159ad144a66baf720c..49f0f084420b7302806ea46833636815ab12ade0 100644
--- a/en/application-dev/media/video-playback.md
+++ b/en/application-dev/media/video-playback.md
@@ -2,7 +2,7 @@
## 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
@@ -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.
-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.
3. The media service flushes the frame data to the surface buffer.
## 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.
-| 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|
| 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
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
import media from '@ohos.multimedia.media'
import fileIO from '@ohos.fileio'
-
-let videoPlayer = undefined; // Used to store instances created by calling the createVideoPlayer API.
-let surfaceID = undefined; // Used to save the surface ID returned by the Xcomponent interface.
-
-// 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) {
+export class VideoPlayerDemo {
+ // Report an error in the case of a function invocation failure.
+ failureCallback(error) {
console.info(`error happened,error Name is ${error.name}`);
console.info(`error happened,error Code is ${error.code}`);
console.info(`error happened,error Message is ${error.message}`);
-}
+ }
-// Report an error in the case of a function invocation exception.
-function catchCallback(error) {
+ // Report an error in the case of a function invocation exception.
+ catchCallback(error) {
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 Message is ${error.message}`);
-}
+ }
-// Used to print the video track information.
-function printfDescription(obj) {
+ // Used to print the video track information.
+ printfDescription(obj) {
for (let item in obj) {
- let property = obj[item];
- console.info('key is ' + item);
- console.info('value is ' + property);
+ let property = obj[item];
+ console.info('key is ' + item);
+ console.info('value is ' + property);
}
-}
-
-// Call createVideoPlayer to create a VideoPlayer instance.
-await media.createVideoPlayer().then((video) => {
- if (typeof (video) != 'undefined') {
+ }
+
+ 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) => {
+ if (typeof (video) != 'undefined') {
console.info('createVideoPlayer success!');
videoPlayer = video;
- } else {
+ } else {
console.info('createVideoPlayer fail!');
- }
-}, failureCallback).catch(catchCallback);
-
-// Set the FD (local playback) of the video file selected by the user.
-let fdPath = 'fd://'
-let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.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);
-});
-
-videoPlayer.url = fdPath;
-
-// Set the surface ID to display the video image.
-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);
-
-// 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') {
+ }
+ }, this.failureCallback).catch(this.catchCallback);
+ // Set the playback source URL for the player.
+ videoPlayer.url = fdPath;
+
+ // Set the surface ID to display the video image.
+ await videoPlayer.setDisplaySurface(surfaceID).then(() => {
+ console.info('setDisplaySurface success');
+ }, this.failureCallback).catch(this.catchCallback);
+
+ // Call the prepare API to prepare for playback.
+ await videoPlayer.prepare().then(() => {
+ console.info('prepare success');
+ }, this.failureCallback).catch(this.catchCallback);
+
+ // Call the play API to start playback.
+ await videoPlayer.play().then(() => {
+ console.info('play success');
+ }, this.failureCallback).catch(this.catchCallback);
+
+ // Pause playback.
+ await videoPlayer.pause().then(() => {
+ console.info('pause success');
+ }, this.failureCallback).catch(this.catchCallback);
+
+ // Use a promise to obtain the video track information.
+ let arrayDescription;
+ await videoPlayer.getTrackDescription().then((arrlist) => {
+ if (typeof (arrlist) != 'undefined') {
arrayDescription = arrlist;
- } else {
+ } else {
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++) {
- printfDescription(arrayDescription[i]);
+ // Seek to the 50s position. For details about the input parameters, see the interface document.
+ 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
@@ -182,85 +179,86 @@ surfaceID = undefined;
```js
import media from '@ohos.multimedia.media'
import fileIO from '@ohos.fileio'
-
-let videoPlayer = undefined; // Used to store instances created by calling the createVideoPlayer API.
-let surfaceID = undefined; // Used to save the surface ID returned by the Xcomponent interface.
-
-// 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) {
+export class VideoPlayerDemo {
+ // Report an error in the case of a function invocation failure.
+ failureCallback(error) {
console.info(`error happened,error Name is ${error.name}`);
console.info(`error happened,error Code is ${error.code}`);
console.info(`error happened,error Message is ${error.message}`);
-}
+ }
-// Report an error in the case of a function invocation exception.
-function catchCallback(error) {
+ // Report an error in the case of a function invocation exception.
+ catchCallback(error) {
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 Message is ${error.message}`);
-}
+ }
-// Set the 'playbackCompleted' event callback, which is triggered when the playback is complete.
-function SetCallBack(videoPlayer) {
- videoPlayer.on('playbackCompleted', () => {
- console.info('video play finish');
-
- await videoPlayer.release().then(() => {
- console.info('release success');
- }, failureCallback).catch(catchCallback);
-
- videoPlayer = undefined;
- surfaceID = undefined;
+ // Used to print the video track information.
+ printfDescription(obj) {
+ for (let item in obj) {
+ let property = obj[item];
+ console.info('key is ' + item);
+ console.info('value is ' + property);
+ }
+ }
+
+ 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) => {
- if (typeof (video) != 'undefined') {
+ // Call createVideoPlayer to create a VideoPlayer instance.
+ await media.createVideoPlayer().then((video) => {
+ if (typeof (video) != 'undefined') {
console.info('createVideoPlayer success!');
videoPlayer = video;
- } else {
+ } else {
console.info('createVideoPlayer fail!');
- }
-}, failureCallback).catch(catchCallback);
-
-// Set the event callbacks.
-SetCallBack(videoPlayer);
-
-// Set the FD (local playback) of the video file selected by the user.
-let fdPath = 'fd://'
-let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.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);
-});
-
-videoPlayer.url = fdPath;
-
-// Set the surface ID to display the video image.
-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);
+ }
+ }, this.failureCallback).catch(this.catchCallback);
+ // Set the playback source for the player.
+ videoPlayer.url = fdPath;
+
+ // Set the surface ID to display the video image.
+ await videoPlayer.setDisplaySurface(surfaceID).then(() => {
+ console.info('setDisplaySurface success');
+ }, this.failureCallback).catch(this.catchCallback);
+
+ // Call the prepare API to prepare for playback.
+ await videoPlayer.prepare().then(() => {
+ console.info('prepare success');
+ }, this.failureCallback).catch(this.catchCallback);
+
+ // Call the play API to start playback.
+ await videoPlayer.play().then(() => {
+ console.info('play success');
+ }, this.failureCallback).catch(this.catchCallback);
+
+ // Stop playback.
+ await videoPlayer.stop().then(() => {
+ console.info('stop 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;
+ }
+}
```
### Switching to the Next Video Clip
@@ -268,120 +266,110 @@ await videoPlayer.play().then(() => {
```js
import media from '@ohos.multimedia.media'
import fileIO from '@ohos.fileio'
-
-let videoPlayer = undefined; // Used to store instances created by calling the createVideoPlayer API.
-let surfaceID = undefined; // Used to save the surface ID returned by the Xcomponent interface.
-
-// 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) {
+export class VideoPlayerDemo {
+ // Report an error in the case of a function invocation failure.
+ failureCallback(error) {
console.info(`error happened,error Name is ${error.name}`);
console.info(`error happened,error Code is ${error.code}`);
console.info(`error happened,error Message is ${error.message}`);
-}
+ }
-// Report an error in the case of a function invocation exception.
-function catchCallback(error) {
+ // Report an error in the case of a function invocation exception.
+ catchCallback(error) {
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 Message is ${error.message}`);
-}
+ }
-// Set the 'playbackCompleted' event callback, which is triggered when the playback is complete.
-function SetCallBack(videoPlayer) {
- videoPlayer.on('playbackCompleted', () => {
- console.info('video play finish');
-
- await videoPlayer.release().then(() => {
- console.info('release success');
- }, failureCallback).catch(catchCallback);
-
- videoPlayer = undefined;
- surfaceID = undefined;
+ // Used to print the video track information.
+ printfDescription(obj) {
+ for (let item in obj) {
+ let property = obj[item];
+ console.info('key is ' + item);
+ console.info('value is ' + property);
+ }
+ }
+
+ 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';
+ 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) => {
- if (typeof (video) != 'undefined') {
+ // Call createVideoPlayer to create a VideoPlayer instance.
+ await media.createVideoPlayer().then((video) => {
+ if (typeof (video) != 'undefined') {
console.info('createVideoPlayer success!');
videoPlayer = video;
- } else {
+ } else {
console.info('createVideoPlayer fail!');
- }
-}, failureCallback).catch(catchCallback);
-
-// Set the event callbacks.
-SetCallBack(videoPlayer);
-
-// Set the FD (local playback) of the video file selected by the user.
-let fdPath = 'fd://'
-let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.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);
-});
-
-videoPlayer.url = fdPath;
-
-// Set the surface ID to display the video image.
-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);
-
-// Send the instruction to switch to the next video clip after a period of time.
-// Reset the playback configuration.
-await videoPlayer.reset().then(() => {
- console.info('reset success');
-}, failureCallback).catch(catchCallback);
-
-// Set the FD (local playback) of the video file selected by the user.
-let fdNextPath = 'fd://'
-let nextPath = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/02.mp4';
-await fileIO.open(nextPath).then(fdNumber) => {
- fdNextPath = fdNextPath + '' + fdNumber;
- console.info('open fd sucess fd is' + fdNextPath);
-}, (err) => {
- console.info('open fd failed err is' + err);
-}),catch((err) => {
- console.info('open fd failed err is' + err);
-});
-
-videoPlayer.url = fdNextPath;
-
-// Set the surface ID to display the video image.
-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);
+ }
+ }, this.failureCallback).catch(this.catchCallback);
+ // Set the playback source for the player.
+ videoPlayer.url = fdPath;
+
+ // Set the surface ID to display the video image.
+ await videoPlayer.setDisplaySurface(surfaceID).then(() => {
+ console.info('setDisplaySurface success');
+ }, this.failureCallback).catch(this.catchCallback);
+
+ // Call the prepare API to prepare for playback.
+ await videoPlayer.prepare().then(() => {
+ console.info('prepare success');
+ }, this.failureCallback).catch(this.catchCallback);
+
+ // Call the play API to start playback.
+ await videoPlayer.play().then(() => {
+ console.info('play success');
+ }, this.failureCallback).catch(this.catchCallback);
+
+ // Reset the playback configuration.
+ await videoPlayer.reset().then(() => {
+ console.info('reset success');
+ }, this.failureCallback).catch(this.catchCallback);
+
+ // Obtain the next video FD address.
+ fdPath = 'fd://'
+ await fileIO.open(nextPath).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);
+ });
+ // Set the second video playback source.
+ videoPlayer.url = fdPath;
+
+ // Call the prepare interface to prepare for playback.
+ await videoPlayer.prepare().then(() => {
+ console.info('prepare success');
+ }, this.failureCallback).catch(this.catchCallback);
+
+ // Call the play API to start playback.
+ await videoPlayer.play().then(() => {
+ console.info('play 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;
+ }
+}
```
### Looping a Video Clip
@@ -389,99 +377,88 @@ await videoPlayer.play().then(() => {
```js
import media from '@ohos.multimedia.media'
import fileIO from '@ohos.fileio'
-
-let videoPlayer = undefined; // Used to store instances created by calling the createVideoPlayer API.
-let surfaceID = undefined; // Used to save the surface ID returned by the Xcomponent interface.
-
-// 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) {
+export class VideoPlayerDemo {
+ // Report an error in the case of a function invocation failure.
+ failureCallback(error) {
console.info(`error happened,error Name is ${error.name}`);
console.info(`error happened,error Code is ${error.code}`);
console.info(`error happened,error Message is ${error.message}`);
-}
+ }
-// Report an error in the case of a function invocation exception.
-function catchCallback(error) {
+ // Report an error in the case of a function invocation exception.
+ catchCallback(error) {
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 Message is ${error.message}`);
-}
+ }
-// Set the 'playbackCompleted' event callback, which is triggered when the playback is complete.
-function SetCallBack(videoPlayer) {
- videoPlayer.on('playbackCompleted', () => {
- console.info('video play finish');
-
- await videoPlayer.release().then(() => {
- console.info('release success');
- }, failureCallback).catch(catchCallback);
-
- videoPlayer = undefined;
- surfaceID = undefined;
+ // Used to print the video track information.
+ printfDescription(obj) {
+ for (let item in obj) {
+ let property = obj[item];
+ console.info('key is ' + item);
+ console.info('value is ' + property);
+ }
+ }
+
+ sleep(time) {
+ 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) => {
- if (typeof (video) != 'undefined') {
+ // Call createVideoPlayer to create a VideoPlayer instance.
+ await media.createVideoPlayer().then((video) => {
+ if (typeof (video) != 'undefined') {
console.info('createVideoPlayer success!');
videoPlayer = video;
- } else {
+ } else {
console.info('createVideoPlayer fail!');
- }
-}, failureCallback).catch(catchCallback);
-
-// Set the event callbacks.
-SetCallBack(videoPlayer);
-
-// Set the FD (local playback) of the video file selected by the user.
-let fdPath = 'fd://'
-let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.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);
-});
-
-videoPlayer.url = fdPath;
-
-// Set the surface ID to display the video image.
-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);
-
-// Set the loop playback attribute.
-videoPlayer.loop = true;
-
-// 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
- // Set the window width, height, and other attributes.
-
+ }
+ }, this.failureCallback).catch(this.catchCallback);
+ // Set the playback source for the player.
+ videoPlayer.url = fdPath;
+
+ // Set the surface ID to display the video image.
+ await videoPlayer.setDisplaySurface(surfaceID).then(() => {
+ console.info('setDisplaySurface success');
+ }, this.failureCallback).catch(this.catchCallback);
+
+ // Call the prepare API to prepare for playback.
+ await videoPlayer.prepare().then(() => {
+ console.info('prepare success');
+ }, this.failureCallback).catch(this.catchCallback);
+ // Set the loop playback attribute.
+ videoPlayer.loop = true;
+ // Call the play API to start playback.
+ await videoPlayer.play().then(() => {
+ console.info('play success');
+ }, this.failureCallback).catch(this.catchCallback);
+ // 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.seek(videoPlayer.duration, media.SeekMode.SEEK_NEXT_SYNC).then((seekDoneTime) => {
+ console.info('seek duration success');
+ }, this.failureCallback).catch(this.catchCallback);
+ this.sleep(3000);
+ // 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;
+ }
+}
```
diff --git a/en/application-dev/reference/apis/js-apis-audio.md b/en/application-dev/reference/apis/js-apis-audio.md
index 4ae4ecd6a7843cd4781431ba5eed30afd0989f11..d1ac497ef790b5f776cdab16218d1934dcdc98b5 100644
--- a/en/application-dev/reference/apis/js-apis-audio.md
+++ b/en/application-dev/reference/apis/js-apis-audio.md
@@ -1,13 +1,15 @@
# Audio Management
-> **NOTE**
-> 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.
+> **NOTE**
+> 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:
-- [AudioManager](#audiomanager): Audio management.
-- [AudioRenderer](#audiorenderer8): Audio rendering, used to play Pulse Code Modulation (PCM) audio data.
-- [AudioCapturer](#audiocapturer8): Audio capture, used to record PCM audio data.
+- [AudioManager](#audiomanager): audio management.
+- [AudioRenderer](#audiorenderer8): audio rendering, used to play Pulse Code Modulation (PCM) audio data.
+- [AudioCapturer](#audiocapturer8): audio capture, used to record PCM audio data.
## Modules to Import
@@ -15,22 +17,21 @@ This module provides the following common audio-related functions:
import audio from '@ohos.multimedia.audio';
```
+
## audio.getAudioManager
getAudioManager(): AudioManager
Obtains an **AudioManager** instance.
-**System capability:** SystemCapability.Multimedia.Audio.Core
-
-**Return value:**
+**System capability**: SystemCapability.Multimedia.Audio.Core
-| Type | Description |
-| ----------------------------- | -------------------- |
-| [AudioManager](#audiomanager) | AudioManager object. |
-
-**Example:**
+**Return value**
+| Type | Description |
+| ----------------------------- | ------------ |
+| [AudioManager](#audiomanager) | **AudioManager** instance.|
+**Example**
```
var audioManager = audio.getAudioManager();
```
@@ -39,17 +40,18 @@ var audioManager = audio.getAudioManager();
createAudioRenderer(options: AudioRendererOptions, callback: AsyncCallback\): 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 |
-| :--------- | :---------------------------------------------- | :-------- | :--------------------------------------------------- |
-| options | [AudioRendererOptions](#audiorendereroptions8) | Yes | Renderer configurations. |
-| callback | AsyncCallback<[AudioRenderer](#audiorenderer8)> | Yes | Callback used to return the audio renderer instance. |
+| Name | Type | Mandatory| Description |
+| -------- | ----------------------------------------------- | ---- | ---------------- |
+| options | [AudioRendererOptions](#audiorendereroptions8) | Yes | Renderer configurations. |
+| callback | AsyncCallback<[AudioRenderer](#audiorenderer8)> | Yes | Callback used to return the **AudioRenderer** instance.|
-**Example:**
+**Example**
```
import audio from '@ohos.multimedia.audio';
@@ -81,26 +83,28 @@ audio.createAudioRenderer(audioRendererOptions,(err, data) => {
}
});
```
+
## audio.createAudioRenderer8+
-createAudioRenderer(options: AudioRendererOptions): Promise
+createAudioRenderer(options: AudioRendererOptions): Promise
+
+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 |
-| :--------- | :--------------------------------------------- | :-------- | :---------------------------|
-| options | [AudioRendererOptions](#audiorendereroptions8) | Yes | Renderer configurations. |
+| Name | Type | Mandatory| Description |
+| :------ | :--------------------------------------------- | :--- | :----------- |
+| options | [AudioRendererOptions](#audiorendereroptions8) | Yes | Renderer configurations.|
-**Return value:**
+**Return value**
-| Type | Description |
-| ----------------------------------------- | --------------------------------------------------- |
-| Promise<[AudioRenderer](#audiorenderer8)> | Promise used to return the audio renderer instance. |
+| Type | Description |
+| ----------------------------------------- | ---------------- |
+| Promise<[AudioRenderer](#audiorenderer8)> | Promise used to return the **AudioRenderer** instance.|
-**Example:**
+**Example**
```
import audio from '@ohos.multimedia.audio';
@@ -136,17 +140,18 @@ audio.createAudioRenderer(audioRendererOptions).then((data) => {
createAudioCapturer(options: AudioCapturerOptions, callback: AsyncCallback): 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:**
-| Name | Type | Mandatory | Description |
-| :--------- | :---------------------------------------------- | :-------- | :--------------------------------------------------- |
-| options | [AudioCapturerOptions](#audiocaptureroptions8) | Yes | Capturer configurations. |
-| callback | AsyncCallback<[AudioCapturer](#audiocapturer8)> | Yes | Callback used to return the audio capturer instance. |
+**Parameters**
-**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';
@@ -182,22 +187,23 @@ audio.createAudioCapturer(audioCapturerOptions,(err, data) => {
createAudioCapturer(options: AudioCapturerOptions): Promise
-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 |
-| :--------- | :-------------------------------------------- | :-------- | :-------------------------- |
-| options | [AudioCapturerOptions](#audiocaptureroptions8) | Yes | Capturer configurations. |
+| Name | Type | Mandatory| Description |
+| :------ | :--------------------------------------------- | :--- | :--------------- |
+| options | [AudioCapturerOptions](#audiocaptureroptions8) | Yes | Capturer configurations.|
-**Return value:**
+**Return value**
-| Type | Description |
-| ----------------------------------------- | --------------------------------------------------- |
-| Promise<[AudioCapturer](#audiocapturer8)> | Promise used to return the audio capturer instance. |
+| Type | Description |
+| ----------------------------------------- | -------------- |
+| Promise<[AudioCapturer](#audiocapturer8)> | Promise used to return the **AudioCapturer** instance.|
-**Example:**
+**Example**
```
import audio from '@ohos.multimedia.audio';
@@ -230,422 +236,429 @@ audio.createAudioRenderer(audioCapturerOptions).then((data) => {
## 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_CALL8+ | 0 | Audio stream for voice calls.|
+| RINGTONE | 2 | Audio stream for ringtones. |
+| MEDIA | 3 | Audio stream for media purpose. |
+| VOICE_ASSISTANT8+ | 9 | Audio stream for voice assistant.|
-| Name | Default Value | Description |
-| ---------------------------- | -------------- | --------------------------------- |
-| VOICE_CALL8+ | 0 | Audio stream for voice calls. |
-| RINGTONE | 2 | Audio stream for ringtones. |
-| MEDIA | 3 | Audio stream for media purpose. |
-| VOICE_ASSISTANT8+ | 9 | Audio stream for voice assistant. |
## 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 |
-| ------------------- | ------------- | -------------- |
-| OUTPUT_DEVICES_FLAG | 1 | Output device. |
-| INPUT_DEVICES_FLAG | 2 | Input device. |
-| ALL_DEVICES_FLAG | 3 | All devices. |
+| Name | Default Value| Description |
+| ------------------- | ------ | ---------- |
+| OUTPUT_DEVICES_FLAG | 1 | Output device.|
+| INPUT_DEVICES_FLAG | 2 | Input device.|
+| ALL_DEVICES_FLAG | 3 | All devices.|
## 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
-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 |
-| ---------------- | ------------- | ------------------------------------------------------------------------ |
-| INVALID | 0 | Invalid device. |
-| EARPIECE | 1 | Earpiece. |
-| SPEAKER | 2 | Speaker. |
-| WIRED_HEADSET | 3 | Wired headset. |
-| WIRED_HEADPHONES | 4 | Wired headset without microphone. |
-| BLUETOOTH_SCO | 7 | Bluetooth device using Synchronous Connection Oriented (SCO) links. |
-| BLUETOOTH_A2DP | 8 | Bluetooth device using Advanced Audio Distribution Profile (A2DP) links. |
-| MIC | 15 | Microphone. |
-| USB_HEADSET | 22 | USB Type-C headset. |
+| Name | Default Value| Description |
+| ---------------- | ------ | --------------------------------------------------------- |
+| INVALID | 0 | Invalid device. |
+| EARPIECE | 1 | Earpiece. |
+| SPEAKER | 2 | Speaker. |
+| WIRED_HEADSET | 3 | Wired headset with a microphone. |
+| WIRED_HEADPHONES | 4 | Wired headset without microphone. |
+| BLUETOOTH_SCO | 7 | Bluetooth device using Synchronous Connection Oriented (SCO) links. |
+| BLUETOOTH_A2DP | 8 | Bluetooth device using Advanced Audio Distribution Profile (A2DP) links.|
+| MIC | 15 | Microphone. |
+| USB_HEADSET | 22 | USB Type-C headset. |
## ActiveDeviceType
Enumerates the active device types.
-**System capability:** SystemCapability.Multimedia.Audio.Device
+**System capability**: SystemCapability.Multimedia.Audio.Device
-| Name | Default Value | Description |
-| ------------- | ------------- | ---------------------------------------------------------------------- |
-| SPEAKER | 2 | Speaker. |
-| BLUETOOTH_SCO | 7 | Bluetooth device using the SCO links. |
+| Name | Default Value| Description |
+| ------------- | ------ | ---------------------------------------------------- |
+| SPEAKER | 2 | Speaker. |
+| BLUETOOTH_SCO | 7 | Bluetooth device using the SCO links.|
## AudioRingMode
-Enumerates ringer modes.
+Enumerates the ringer modes.
-**System capability:** SystemCapability.Multimedia.Audio.Communication
+**System capability**: SystemCapability.Multimedia.Audio.Communication
-| Name | Default Value | Description |
-| ------------------- | ------------- | ---------------- |
-| RINGER_MODE_SILENT | 0 | Silent mode. |
-| RINGER_MODE_VIBRATE | 1 | Vibration mode. |
-| RINGER_MODE_NORMAL | 2 | Normal mode. |
+| Name | Default Value| Description |
+| ------------------- | ------ | ---------- |
+| RINGER_MODE_SILENT | 0 | Silent mode.|
+| RINGER_MODE_VIBRATE | 1 | Vibration mode.|
+| RINGER_MODE_NORMAL | 2 | Normal mode.|
## AudioSampleFormat8+
-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 |
-| :-------------------- | :------------ | :------------------------------------ |
-| SAMPLE_FORMAT_INVALID | -1 | Invalid format. |
-| SAMPLE_FORMAT_U8 | 0 | Unsigned 8 bit integer. |
-| SAMPLE_FORMAT_S16LE | 1 | Signed 16 bit integer, little endian. |
-| SAMPLE_FORMAT_S24LE | 2 | Signed 24 bit integer, little endian. |
-| SAMPLE_FORMAT_S32LE | 3 | Signed 32 bit integer, little endian. |
+| Name | Default Value| Description |
+| --------------------- | ------ | -------------------------- |
+| SAMPLE_FORMAT_INVALID | -1 | Invalid format. |
+| SAMPLE_FORMAT_U8 | 0 | Unsigned 8-bit integer. |
+| SAMPLE_FORMAT_S16LE | 1 | Signed 16-bit integer, little endian.|
+| SAMPLE_FORMAT_S24LE | 2 | Signed 24-bit integer, little endian.|
+| SAMPLE_FORMAT_S32LE | 3 | Signed 32-bit integer, little endian.|
## AudioChannel8+
Enumerates the audio channels.
-**System capability:** SystemCapability.Multimedia.Audio.Core
+**System capability**: SystemCapability.Multimedia.Audio.Core
-| Name | Default Value | Description |
-| :-------- | :------------ | :--------------- |
-| CHANNEL_1 | 0x1 << 0 | Channel count 1. |
-| CHANNEL_2 | 0x1 << 1 | Channel count 2. |
+| Name | Default Value | Description |
+| --------- | -------- | -------- |
+| CHANNEL_1 | 0x1 << 0 | Mono.|
+| CHANNEL_2 | 0x1 << 1 | Dual-channel.|
## AudioSamplingRate8+
Enumerates the audio sampling rates.
-**System capability:** SystemCapability.Multimedia.Audio.Core
-
-| Name | Default Value | Description |
-| :---------------- | :------------ | :------------------- |
-| SAMPLE_RATE_8000 | 8000 | Sampling rate 8000. |
-| SAMPLE_RATE_11025 | 11025 | Sampling rate 11025. |
-| SAMPLE_RATE_12000 | 12000 | Sampling rate 12000. |
-| SAMPLE_RATE_16000 | 16000 | Sampling rate 16000. |
-| SAMPLE_RATE_22050 | 22050 | Sampling rate 22050. |
-| SAMPLE_RATE_24000 | 24000 | Sampling rate 24000. |
-| SAMPLE_RATE_32000 | 32000 | Sampling rate 32000. |
-| SAMPLE_RATE_44100 | 44100 | Sampling rate 44100. |
-| SAMPLE_RATE_48000 | 48000 | Sampling rate 48000. |
-| SAMPLE_RATE_64000 | 64000 | Sampling rate 64000. |
-| SAMPLE_RATE_96000 | 96000 | Sampling rate 96000. |
-
+**System capability**: SystemCapability.Multimedia.Audio.Core
+
+| Name | Default Value| Description |
+| ----------------- | ------ | --------------- |
+| SAMPLE_RATE_8000 | 8000 | The sampling rate is 8000. |
+| SAMPLE_RATE_11025 | 11025 | The sampling rate is 11025.|
+| SAMPLE_RATE_12000 | 12000 | The sampling rate is 12000.|
+| SAMPLE_RATE_16000 | 16000 | The sampling rate is 16000.|
+| SAMPLE_RATE_22050 | 22050 | The sampling rate is 22050.|
+| SAMPLE_RATE_24000 | 24000 | The sampling rate is 24000.|
+| SAMPLE_RATE_32000 | 32000 | The sampling rate is 32000.|
+| SAMPLE_RATE_44100 | 44100 | The sampling rate is 44100.|
+| SAMPLE_RATE_48000 | 48000 | The sampling rate is 48000.|
+| SAMPLE_RATE_64000 | 64000 | The sampling rate is 64000.|
+| SAMPLE_RATE_96000 | 96000 | The sampling rate is 96000.|
## AudioEncodingType8+
Enumerates the audio encoding types.
-**System capability:** SystemCapability.Multimedia.Audio.Core
-
-| Name | Default Value | Description |
-| :-------------------- | :------------- | :---------------- |
-| ENCODING_TYPE_INVALID | -1 | Invalid. |
-| ENCODING_TYPE_RAW | 0 | PCM encoding. |
+**System capability**: SystemCapability.Multimedia.Audio.Core
+| Name | Default Value| Description |
+| --------------------- | ------ | --------- |
+| ENCODING_TYPE_INVALID | -1 | Invalid. |
+| ENCODING_TYPE_RAW | 0 | PCM encoding.|
## ContentType
-Enumerates the content types.
-
-**System capability:** SystemCapability.Multimedia.Audio.Core
+Enumerates the audio content types.
-| Name | Default Value | Description |
-| :----------------------------------| :------------ | :---------------------- |
-| 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_RINGTONE8+ | 5 | Ringtone content. |
+**System capability**: SystemCapability.Multimedia.Audio.Core
+| 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_RINGTONE8+ | 5 | Ringtone. |
## StreamUsage
-Enumerates the stream usage.
-
-**System capability:** SystemCapability.Multimedia.Audio.Core
+Enumerates the audio stream usage.
-| Name | Default Value | Description |
-| :--------------------------------- | :------------ | :-------------------------------- |
-| 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. |
+**System capability**: SystemCapability.Multimedia.Audio.Core
+| 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.|
## AudioState8+
Enumerates the audio states.
-**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. |
+**System capability**: SystemCapability.Multimedia.Audio.Core
+| 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. |
## AudioRendererRate8+
Enumerates the audio renderer rates.
-**System capability:** SystemCapability.Multimedia.Audio.Renderer
+**System capability**: SystemCapability.Multimedia.Audio.Renderer
-| Name | Default Value | Description |
-| :----------------- | :------------ | :------------ |
-| RENDER_RATE_NORMAL | 0 | Normal rate. |
-| RENDER_RATE_DOUBLE | 1 | Double rate. |
-| RENDER_RATE_HALF | 2 | Half rate. |
+| Name | Default Value| Description |
+| ------------------ | ------ | ---------- |
+| RENDER_RATE_NORMAL | 0 | Normal rate.|
+| RENDER_RATE_DOUBLE | 1 | Double rate. |
+| RENDER_RATE_HALF | 2 | Half rate. |
## 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.|
+
+## InterruptForceType9+
-**System capability:** SystemCapability.Multimedia.Audio.Renderer
+Enumerates the types of force that causes audio interruption.
-| Name | Default Value | Description |
-| :------------------- | :------------ | :----------------------------------- |
-| INTERRUPT_TYPE_BEGIN | 1 | Audio playback interruption started. |
-| INTERRUPT_TYPE_END | 2 | Audio playback interruption ended. |
+**System capability**: SystemCapability.Multimedia.Audio.Renderer
+
+| Name | Default Value| Description |
+| --------------- | ------ | ------------------------------------ |
+| INTERRUPT_FORCE | 0 | Forced action taken by the system. |
+| INTERRUPT_SHARE | 1 | The application can choose to take action or ignore.|
## 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 |
-| :--------------------------------- | :------------ | :--------------------------- |
-| INTERRUPT_HINT_NONE8+ | 0 | None. |
-| INTERRUPT_HINT_RESUME | 1 | Resume the playback. |
-| INTERRUPT_HINT_PAUSE | 2 | Paused/Pause the playback. |
-| INTERRUPT_HINT_STOP | 3 | Stopped/Stop the playback. |
-| INTERRUPT_HINT_DUCK | 4 | Ducked the playback. |
-| INTERRUPT_HINT_UNDUCK8+ | 5 | Unducked the playback. |
+| Name | Default Value| Description |
+| ---------------------------------- | ------ | -------------------------------------------- |
+| INTERRUPT_HINT_NONE8+ | 0 | None. |
+| INTERRUPT_HINT_RESUME | 1 | Resume the playback. |
+| INTERRUPT_HINT_PAUSE | 2 | Paused/Pause the playback. |
+| INTERRUPT_HINT_STOP | 3 | Stopped/Stop the playback. |
+| INTERRUPT_HINT_DUCK | 4 | Ducked the playback. (In ducking, the audio volume is reduced, but not silenced.)|
+| INTERRUPT_HINT_UNDUCK8+ | 5 | Unducked the playback. |
## 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.
-**System capability:** SystemCapability.Multimedia.Audio.Renderer
+**System capability**: SystemCapability.Multimedia.Audio.Renderer
-| Name | Default Value | Description |
-| :------------- | :------------ | :---------------------------------------- |
-| TYPE_ACTIVATED | 0 | Audio interrupt activated. |
-| TYPE_INTERRUPT | 1 | Audio interrupted. |
+| Name | Default Value| Description |
+| -------------- | ------ | ------------------ |
+| TYPE_ACTIVATED | 0 | Focus gain event.|
+| TYPE_INTERRUPT | 1 | Audio interruption event.|
## AudioStreamInfo8+
Describes audio stream information.
-**System capability:** SystemCapability.Multimedia.Audio.Core
-
-**Parameters:**
+**System capability**: SystemCapability.Multimedia.Audio.Core
-| Name | Type | Mandatory | Description |
-| :------------ | :---------------------------------------- | :-------- | :-------------------- |
-| samplingRate | [AudioSamplingRate](#audiosamplingrate8) | Yes | Sampling rate. |
-| channels | [AudioChannel](#audiochannel8) | Yes | Audio channels. |
-| sampleFormat | [AudioSampleFormat](#audiosampleformat8) | Yes | Audio sample format. |
-| encodingType | [AudioEncodingType](#audioencodingtype8) | Yes | Audio encoding type. |
+| Name | Type | Mandatory| Description |
+| ------------ | ---------------------------------------- | ---- | ------------------ |
+| samplingRate | [AudioSamplingRate](#audiosamplingrate8) | Yes | Audio sampling rate.|
+| channels | [AudioChannel](#audiochannel8) | Yes | Number of audio channels.|
+| sampleFormat | [AudioSampleFormat](#audiosampleformat8) | Yes | Audio sample format. |
+| encodingType | [AudioEncodingType](#audioencodingtype8) | Yes | Audio encoding type. |
## AudioRendererInfo8+
Describes audio renderer information.
-**System capability:** SystemCapability.Multimedia.Audio.Core
+**System capability**: SystemCapability.Multimedia.Audio.Core
-**Parameters:**
-
-| Name | Type | Mandatory | Description |
-| :------------ | :-------------------------- | :-------- | :-------------------- |
-| contentType | [ContentType](#contenttype) | Yes | Content type. |
-| usage | [StreamUsage](#streamusage) | Yes | Stream usage. |
-| rendererFlags | number | Yes | Audio renderer flags. |
+| Name | Type | Mandatory| Description |
+| ------------- | --------------------------- | ---- | ---------------- |
+| content | [ContentType](#contenttype) | Yes | Audio content type. |
+| usage | [StreamUsage](#streamusage) | Yes | Audio stream usage.|
+| rendererFlags | number | Yes | Audio renderer flags.|
## AudioRendererOptions8+
-Describes audio renderer configuration options.
-
-**System capability:** SystemCapability.Multimedia.Audio.Renderer
-
-**Parameters:**
-
-| Name | Type | Mandatory | Description |
-| :------------ | :-----------------------------------------| :-------- | :-------------------- |
-| streamInfo | [AudioStreamInfo](#audiostreaminfo8) | Yes | Stream information. |
-| rendererInfo | [AudioRendererInfo](#audiorendererinfo8) | Yes | Renderer information. |
-
-## AudioCapturerInfo8+
-
-Describes audio capturer information.
-
-**System capability:** SystemCapability.Multimedia.Audio.Core
+Describes audio renderer configurations.
-**Parameters:**
+**System capability**: SystemCapability.Multimedia.Audio.Renderer
-| Name | Type | Mandatory | Description |
-| :---------------| :------------------------- | :-------- | :-------------------- |
-| source | [SourceType](#sourcetype) | Yes | Audio source type. |
-| capturerFlags | number | Yes | Audio capturer flags. |
+| Name | Type | Mandatory| Description |
+| ------------ | ---------------------------------------- | ---- | ---------------- |
+| streamInfo | [AudioStreamInfo](#audiostreaminfo8) | Yes | Audio stream information.|
+| rendererInfo | [AudioRendererInfo](#audiorendererinfo8) | Yes | Audio renderer information.|
-## AudioCapturerOptions8+
-
-Describes audio capturer configuration options.
+## InterruptEvent9+
-**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 |
-| :------------ | :-----------------------------------------| :-------- | :-------------------- |
-| streamInfo | [AudioStreamInfo](#audiostreaminfo8) | Yes | Stream information. |
-| capturerInfo | [AudioCapturerInfo](#audiocapturerinfo8) | Yes | Capturer information. |
+| Name | Type | Mandatory| Description |
+| --------- | ------------------------------------------ | ---- | ------------------------------------ |
+| eventType | [InterruptType](#interrupttype) | Yes | Whether the interruption has started or ended. |
+| 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
-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.
-**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. |
-| contentType | [ContentType](#contenttype) | Yes | Audio interrupt media 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). |
+| streamUsage | [StreamUsage](#streamusage) | Yes | Audio stream usage. |
+| contentType | [ContentType](#contenttype) | Yes | Audio content type. |
+| 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
-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.
-**System capability:** SystemCapability.Multimedia.Audio.Renderer
+**System capability**: SystemCapability.Multimedia.Audio.Renderer
-| 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. |
-| type | [InterruptType](#interrupttype) | No | Interrupt event type. |
-| hint | [InterruptHint](#interrupthint) | No | Interrupt event prompts. |
-| activated | boolean | No | Acquire/release focus. true indicates that the focus acquisition/release is successful, and false indicates that the focus acquisition/release fails. |
+| Name | Type | Mandatory| Description |
+| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ |
+| 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 | Type of the audio interruption event. |
+| hint | [InterruptHint](interrupthint) | No | Hint provided along with the audio interruption event. |
+| 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.|
## VolumeEvent8+
-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 |
-| :--------- | :---------------------------------- | :-------- | :--------------------------------------- |
-| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Volume type of the current stream. |
-| volume | number | Yes | Volume level. |
-| updateUi | boolean | Yes | Whether to show the volume change in UI. |
+| Name | Type | Mandatory| Description |
+| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
+| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
+| 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. |
## 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:**
-
-| Name | Type | Mandatory | Description |
-| :------------------ | :------------------------------------------------ | :-------- | :------------------ |
-| type | [DeviceChangeType](#devicechangetype) | Yes | Device change type. |
-| deviceDescriptors | [AudioDeviceDescriptors](#audiodevicedescriptors) | Yes | Device information. |
+**Parameters**
+| Name | Type | Mandatory| Description |
+| :---------------- | :------------------------------------------------ | :--- | :----------------- |
+| type | [DeviceChangeType](#DeviceChangeType) | Yes | Device connection status.|
+| deviceDescriptors | [AudioDeviceDescriptors](#AudioDeviceDescriptors) | Yes | Device information. |
## 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 |
-| :--------------------- | :------------ | :-------------------- |
-| CONNECT | 0 | Device connection. |
-| DISCONNECT | 1 | Device disconnection. |
+| Name | Default Value| Description |
+| :--------- | :----- | :------------- |
+| CONNECT | 0 | Connected. |
+| DISCONNECT | 1 | Disconnected.|
-## SourceType8+
+## AudioCapturerOptions8+
+
+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.|
+
+## AudioCapturerInfo8+
+
+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
+## SourceType8+
+
+Enumerates the audio source types.
-| Name | Default Value | Description |
-| :----------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------ | :------------------------------- |
-| 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. |
+**System capability**: SystemCapability.Multimedia.Audio.Core
+| 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.
This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.|
## AudioScene8+
-Enumerates audio scenes.
+Enumerates the audio scenes.
-**System capability:** SystemCapability.Multimedia.Audio.Communication
+**System capability**: SystemCapability.Multimedia.Audio.Communication
-| Name | Default Value | Description |
-| :------------------------------------------------------------------------------------ | :------------ | :---------------------- |
-| AUDIO_SCENE_DEFAULT | 0 | Default audio scene. |
-| AUDIO_SCENE_RINGING(system API, not supported by third-party applications) | 1 | Ringing audio scene. |
-| AUDIO_SCENE_PHONE_CALL(system API, not supported by third-party applications) | 2 | Phone call audio scene. |
-| AUDIO_SCENE_VOICE_CHAT | 3 | Voice chat audio scene. |
+| Name | Default Value| Description |
+| :--------------------- | :----- | :-------------------------------------------- |
+| AUDIO_SCENE_DEFAULT | 0 | Default audio scene. |
+| AUDIO_SCENE_RINGING | 1 | Ringing audio scene.
This is a system API and cannot be called by third-party applications.|
+| AUDIO_SCENE_PHONE_CALL | 2 | Phone call audio scene.
This is a system API and cannot be called by third-party applications.|
+| AUDIO_SCENE_VOICE_CHAT | 3 | Voice chat audio scene. |
## 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\(volumeType: AudioVolumeType, volume: number, callback: AsyncCallback\): void
+setVolume(volumeType: AudioVolumeType, volume: number, callback: AsyncCallback<void>): void
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 |
-| ---------- | ----------------------------------- | --------- | ---------------------------------------------------------------------------------------- |
-| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Volume stream type. |
-| volume | number | Yes | Volume to set. The value range can be obtained by calling getMinVolume and getMaxVolume. |
-| callback | AsyncCallback | Yes | Callback used to return the result. |
+| Name | Type | Mandatory| Description |
+| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
+| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
+| 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. |
-**Example:**
+**Example**
```
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.');
});
```
+
### setVolume
-setVolume\(volumeType: AudioVolumeType, volume: number\): Promise
+setVolume(volumeType: AudioVolumeType, volume: number): Promise<void>
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 |
-| ---------- | ----------------------------------- | --------- | ---------------------------------------------------------------------------------------- |
-| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Volume stream type. |
-| volume | number | Yes | Volume to set. The value range can be obtained by calling getMinVolume and getMaxVolume. |
+| Name | Type | Mandatory| Description |
+| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
+| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
+| volume | number | Yes | Volume to set. The value range can be obtained by calling **getMinVolume** and **getMaxVolume**.|
-**Return value:**
+**Return value**
-| Type | Description |
-| ------------------- | ----------------------------------- |
-| Promise | Promise used to return the result. |
+| Type | Description |
+| ------------------- | ----------------------------- |
+| Promise<void> | Promise used to return the result.|
-**Example:**
+**Example**
```
audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(() => {
@@ -687,20 +701,20 @@ audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(() => {
### getVolume
-getVolume\(volumeType: AudioVolumeType, callback: AsyncCallback\): void
+getVolume(volumeType: AudioVolumeType, callback: AsyncCallback<number>): 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 |
-| ---------- | ----------------------------------- | --------- | ------------------------------------ |
-| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
-| callback | AsyncCallback | Yes | Callback used to return the volume. |
+| Name | Type | Mandatory| Description |
+| ---------- | ----------------------------------- | ---- | ------------------ |
+| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
+| callback | AsyncCallback<number> | Yes | Callback used to return the volume.|
-**Example:**
+**Example**
```
audioManager.getVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
@@ -712,28 +726,27 @@ audioManager.getVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
});
```
-
### getVolume
-getVolume\(volumeType: AudioVolumeType\): Promise
+getVolume(volumeType: AudioVolumeType): Promise<number>
-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 |
-| ---------- | ----------------------------------- | --------- | ------------------------------------ |
-| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
+| Name | Type | Mandatory| Description |
+| ---------- | ----------------------------------- | ---- | ------------ |
+| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type.|
-**Return value:**
+**Return value**
-| Type | Description |
-| ------------------- | ----------------------------------- |
-| Promise | Promise used to return the result. |
+| Type | Description |
+| --------------------- | ------------------------- |
+| Promise<number> | Promise used to return the volume.|
-**Example:**
+**Example**
```
audioManager.getVolume(audio.AudioVolumeType.MEDIA).then((value) => {
@@ -743,20 +756,20 @@ audioManager.getVolume(audio.AudioVolumeType.MEDIA).then((value) => {
### getMinVolume
-getMinVolume\(volumeType: AudioVolumeType, callback: AsyncCallback\): void
+getMinVolume(volumeType: AudioVolumeType, callback: AsyncCallback<number>): 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 |
-| ---------- | ----------------------------------- | --------- | ------------------------------------ |
-| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
-| callback | AsyncCallback | Yes | Callback used to return the volume. |
+| Name | Type | Mandatory| Description |
+| ---------- | ----------------------------------- | ---- | ------------------ |
+| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
+| callback | AsyncCallback<number> | Yes | Callback used to return the minimum volume.|
-**Example:**
+**Example**
```
audioManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
@@ -768,28 +781,27 @@ audioManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
});
```
-
### getMinVolume
-getMinVolume\(volumeType: AudioVolumeType\): Promise
+getMinVolume(volumeType: AudioVolumeType): Promise<number>
-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 |
-| ---------- | ----------------------------------- | --------- | ------------------------------------ |
-| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
+| Name | Type | Mandatory| Description |
+| ---------- | ----------------------------------- | ---- | ------------ |
+| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type.|
-**Return value:**
+**Return value**
-| Type | Description |
-| ------------------- | ----------------------------------- |
-| Promise | Promise used to return the result. |
+| Type | Description |
+| --------------------- | ------------------------- |
+| Promise<number> | Promise used to return the minimum volume.|
-**Example:**
+**Example**
```
audioManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value) => {
@@ -799,20 +811,20 @@ audioManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value) => {
### getMaxVolume
-getMaxVolume\(volumeType: AudioVolumeType, callback: AsyncCallback\): void
+getMaxVolume(volumeType: AudioVolumeType, callback: AsyncCallback<number>): 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 |
-| ---------- | ----------------------------------- | --------- | ------------------------------------ |
-| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
-| callback | AsyncCallback | Yes | Callback used to return the volume. |
+| Name | Type | Mandatory| Description |
+| ---------- | ----------------------------------- | ---- | ---------------------- |
+| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
+| callback | AsyncCallback<number> | Yes | Callback used to return the maximum volume.|
-**Example:**
+**Example**
```
audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
@@ -824,28 +836,27 @@ audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
});
```
-
### getMaxVolume
-getMaxVolume\(volumeType: AudioVolumeType\): Promise
+getMaxVolume(volumeType: AudioVolumeType): Promise<number>
-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 |
-| ---------- | ----------------------------------- | --------- | ------------------------------------ |
-| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
+| Name | Type | Mandatory| Description |
+| ---------- | ----------------------------------- | ---- | ------------ |
+| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type.|
-**Return value:**
+**Return value**
-| Type | Description |
-| ------------------- | ----------------------------------- |
-| Promise | Promise used to return the result. |
+| Type | Description |
+| --------------------- | ----------------------------- |
+| Promise<number> | Promise used to return the maximum volume.|
-**Example:**
+**Example**
```
audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data) => {
@@ -855,21 +866,21 @@ audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data) => {
### mute
-mute\(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback\): void
+mute(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback<void>): 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 |
-| ---------- | ----------------------------------- | --------- | ------------------------------------------------------------------------------------------ |
-| 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. |
-| callback | AsyncCallback | Yes | Callback used to return the volume. |
+| 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.|
+| callback | AsyncCallback<void> | Yes | Callback used to return the result. |
-**Example:**
+**Example**
```
audioManager.mute(audio.AudioVolumeType.MEDIA, true, (err) => {
@@ -881,29 +892,29 @@ audioManager.mute(audio.AudioVolumeType.MEDIA, true, (err) => {
});
```
-
### mute
-mute\(volumeType: AudioVolumeType, mute: boolean\): Promise
+mute(volumeType: AudioVolumeType, mute: boolean): Promise<void>
+
+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 |
-| ---------- | ----------------------------------- | --------- | ------------------------------------------------------------------------------------------ |
-| 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**
-**Return value:**
+| Type | Description |
+| ------------------- | ----------------------------- |
+| Promise<void> | Promise used to return the result.|
-| Type | Description |
-| ------------------- | ----------------------------------- |
-| Promise | Promise used to return the result. |
+**Example**
-**Example:**
```
audioManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => {
@@ -914,20 +925,20 @@ audioManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => {
### isMute
-isMute\(volumeType: AudioVolumeType, callback: AsyncCallback\): void
+isMute(volumeType: AudioVolumeType, callback: AsyncCallback<boolean>): 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 |
-| ---------- | ----------------------------------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------- |
-| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
-| callback | AsyncCallback | 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.|
+| Name | Type | Mandatory| Description |
+| ---------- | ----------------------------------- | ---- | ----------------------------------------------- |
+| 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.|
-**Example:**
+**Example**
```
audioManager.isMute(audio.AudioVolumeType.MEDIA, (err, value) => {
@@ -942,25 +953,25 @@ audioManager.isMute(audio.AudioVolumeType.MEDIA, (err, value) => {
### isMute
-isMute\(volumeType: AudioVolumeType\): Promise
+isMute(volumeType: AudioVolumeType): Promise<boolean>
-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 |
-| ---------- | ----------------------------------- | --------- | ------------------- |
-| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
+| Name | Type | Mandatory| Description |
+| ---------- | ----------------------------------- | ---- | ------------ |
+| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type.|
-**Return value:**
+**Return value**
-| Type | Description |
-| ------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
-| Promise | Promise used to return the mute status of the stream. The value true means that the stream is muted, and false means the opposite. |
+| 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.|
-**Example:**
+**Example**
```
audioManager.isMute(audio.AudioVolumeType.MEDIA).then((value) => {
@@ -970,20 +981,20 @@ audioManager.isMute(audio.AudioVolumeType.MEDIA).then((value) => {
### isActive
-isActive\(volumeType: AudioVolumeType, callback: AsyncCallback\)
+isActive(volumeType: AudioVolumeType, callback: AsyncCallback<boolean>): 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 |
-| ---------- | ----------------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------- |
-| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
-| callback | AsyncCallback | 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.|
+| Name | Type | Mandatory| Description |
+| ---------- | ----------------------------------- | ---- | ------------------------------------------------- |
+| 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.|
-**Example:**
+**Example**
```
audioManager.isActive(audio.AudioVolumeType.MEDIA, (err, value) => {
@@ -995,28 +1006,27 @@ audioManager.isActive(audio.AudioVolumeType.MEDIA, (err, value) => {
});
```
-
### isActive
-isActive\(volumeType: AudioVolumeType\): Promise
+isActive(volumeType: AudioVolumeType): Promise<boolean>
-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 |
-| ---------- | ----------------------------------- | --------- | ------------------ |
-| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
+| Name | Type | Mandatory| Description |
+| ---------- | ----------------------------------- | ---- | ------------ |
+| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type.|
-**Return value:**
+**Return value**
-| Type | Description |
-| ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
-| Promise | Promise used to return the active status of the stream. The value true means that the stream is active, and false means the opposite. |
+| 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.|
-**Example:**
+**Example**
```
audioManager.isActive(audio.AudioVolumeType.MEDIA).then((value) => {
@@ -1024,23 +1034,22 @@ audioManager.isActive(audio.AudioVolumeType.MEDIA).then((value) => {
});
```
-
### setRingerMode
-setRingerMode\(mode: AudioRingMode, callback: AsyncCallback\): void
+setRingerMode(mode: AudioRingMode, callback: AsyncCallback<void>): void
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 |
-| ---------- | ----------------------------------- | --------- | ----------------------------------- |
-| mode | [AudioRingMode](#audioringmode) | Yes | Ringer mode. |
-| callback | AsyncCallback | Yes | Callback used to return the result. |
+| Name | Type | Mandatory| Description |
+| -------- | ------------------------------- | ---- | ------------------------ |
+| mode | [AudioRingMode](#audioringmode) | Yes | Ringer mode. |
+| callback | AsyncCallback<void> | Yes | Callback used to return the result.|
-**Example:**
+**Example**
```
audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL, (err) => {
@@ -1052,28 +1061,27 @@ audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL, (err) => {
});
```
-
### setRingerMode
-setRingerMode\(mode: AudioRingMode\): Promise
+setRingerMode(mode: AudioRingMode): Promise<void>
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 |
-| ---------- | ----------------------------------- | --------- | ----------------------------------- |
-| mode | [AudioRingMode](#audioringmode) | Yes | Ringer mode. |
+| Name| Type | Mandatory| Description |
+| ------ | ------------------------------- | ---- | -------------- |
+| mode | [AudioRingMode](#audioringmode) | Yes | Ringer mode.|
-**Return value:**
+**Return value**
-| Type | Description |
-| ------------------- | ----------------------------------- |
-| Promise | Promise used to return the result. |
+| Type | Description |
+| ------------------- | ------------------------------- |
+| Promise<void> | Promise used to return the result.|
-**Example:**
+**Example**
```
audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() => {
@@ -1084,19 +1092,19 @@ audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() => {
### getRingerMode
-getRingerMode\(callback: AsyncCallback\): void
+getRingerMode(callback: AsyncCallback<AudioRingMode>): 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 |
-| ---------- | ----------------------------------------------- | --------- | ---------------------------------------- |
-| callback | AsyncCallback<[AudioRingMode](#audioringmode)> | Yes | Callback used to return the ringer mode. |
+| Name | Type | Mandatory| Description |
+| -------- | ---------------------------------------------------- | ---- | ------------------------ |
+| callback | AsyncCallback<[AudioRingMode](#audioringmode)> | Yes | Callback used to return the ringer mode.|
-**Example:**
+**Example**
```
audioManager.getRingerMode((err, value) => {
@@ -1111,19 +1119,19 @@ audioManager.getRingerMode((err, value) => {
### getRingerMode
-getRingerMode\(\): Promise
+getRingerMode(): Promise<AudioRingMode>
-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 |
-| ---------------------------------------------- | --------------------------------------- |
-| Promise<[AudioRingMode](#audioringmode)> | Promise used to return the ringer mode. |
+| Type | Description |
+| ---------------------------------------------- | ------------------------------- |
+| Promise<[AudioRingMode](#audioringmode)> | Promise used to return the ringer mode.|
-**Example:**
+**Example**
```
audioManager.getRingerMode().then((value) => {
@@ -1131,24 +1139,23 @@ audioManager.getRingerMode().then((value) => {
});
```
-
### setAudioParameter
-setAudioParameter\(key: string, value: string, callback: AsyncCallback\): void
+setAudioParameter(key: string, value: string, callback: AsyncCallback<void>): void
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 |
-| --------- | ----------------------| --------- | ------------------------------------- |
-| key | string | Yes | Key of the audio parameter to set. |
-| value | string | Yes | Value of the audio parameter to set. |
-| callback | AsyncCallback | Yes | Callback used to return the result. |
+| Name | Type | Mandatory| Description |
+| -------- | ------------------------- | ---- | ------------------------ |
+| key | string | Yes | Key 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.|
-**Example:**
+**Example**
```
audioManager.setAudioParameter('PBits per sample', '8 bit', (err) => {
@@ -1160,29 +1167,28 @@ audioManager.setAudioParameter('PBits per sample', '8 bit', (err) => {
});
```
-
### setAudioParameter
-setAudioParameter\(key: string, value: string\): Promise
+setAudioParameter(key: string, value: string): Promise<void>
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 |
-| --------- | ----------------------| --------- | ------------------------------------- |
-| key | string | Yes | Key of the audio parameter to set. |
-| value | string | Yes | Value of the audio parameter to set. |
+| Name| Type | Mandatory| Description |
+| ------ | ------ | ---- | ---------------------- |
+| key | string | Yes | Key of the audio parameter to set.|
+| value | string | Yes | Value of the audio parameter to set.|
-**Return value:**
+**Return value**
-| Type | Description |
-| ------------------- | ----------------------------------- |
-| Promise | Promise used to return the result. |
+| Type | Description |
+| ------------------- | ------------------------------- |
+| Promise<void> | Promise used to return the result.|
-**Example:**
+**Example**
```
audioManager.setAudioParameter('PBits per sample', '8 bit').then(() => {
@@ -1190,23 +1196,22 @@ audioManager.setAudioParameter('PBits per sample', '8 bit').then(() => {
});
```
-
### getAudioParameter
-getAudioParameter\(key: string, callback: AsyncCallback\)
+getAudioParameter(key: string, callback: AsyncCallback<string>): 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 |
-| --------- | ----------------------| --------- | ---------------------------------------------------------- |
-| key | string | Yes | Key of the audio parameter whose value is to be obtained. |
-| callback | AsyncCallback | Yes | Callback used to return the value of the audio parameter. |
+| Name | Type | Mandatory| Description |
+| -------- | --------------------------- | ---- | ---------------------------- |
+| 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.|
-**Example:**
+**Example**
```
audioManager.getAudioParameter('PBits per sample', (err, value) => {
@@ -1218,28 +1223,27 @@ audioManager.getAudioParameter('PBits per sample', (err, value) => {
});
```
-
### getAudioParameter
-getAudioParameter\(key: string\): Promise
+getAudioParameter(key: string): Promise<string>
-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 |
-| --------- | ----------------------| --------- | ----------------------------------------------------------- |
-| key | string | Yes | Key of the audio parameter whose value is to be obtained. |
+| Name| Type | Mandatory| Description |
+| ------ | ------ | ---- | ---------------------- |
+| key | string | Yes | Key of the audio parameter whose value is to be obtained.|
-**Return value:**
+**Return value**
-| Type | Description |
-| ------------------- | ----------------------------------- |
-| Promise | Promise used to return the value of the audio parameter. |
+| Type | Description |
+| --------------------- | ----------------------------------- |
+| Promise<string> | Promise used to return the value of the audio parameter.|
-**Example:**
+**Example**
```
audioManager.getAudioParameter('PBits per sample').then((value) => {
@@ -1247,24 +1251,22 @@ audioManager.getAudioParameter('PBits per sample').then((value) => {
});
```
-
### getDevices
-getDevices\(deviceFlag: DeviceFlag, callback: AsyncCallback\): void
-
-Obtains the audio devices with a specific flag. This API uses an asynchronous callback to return the query result.
+getDevices(deviceFlag: DeviceFlag, callback: AsyncCallback<AudioDeviceDescriptors>): void
-**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 |
-| --------- | ---------------------------------------------------------------- | --------- | ----------------------------------------- |
-| deviceFlag | [DeviceFlag](#deviceflag) | Yes | Audio device flag. |
-| callback | AsyncCallback<[AudioDeviceDescriptors](#audiodevicedescriptors)> | Yes | Callback used to return the device list. |
+**Parameters**
-**Example:**
+| Name | Type | Mandatory| Description |
+| ---------- | ------------------------------------------------------------ | ---- | -------------------- |
+| deviceFlag | [DeviceFlag](#deviceflag) | Yes | Audio device flag. |
+| callback | AsyncCallback<[AudioDeviceDescriptors](#audiodevicedescriptors)> | Yes | Callback used to return the device list.|
+**Example**
```
audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err, value) => {
if (err) {
@@ -1275,29 +1277,27 @@ audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err, value) => {
});
```
-
-
### getDevices
-getDevices\(deviceFlag: DeviceFlag\): Promise
+getDevices(deviceFlag: DeviceFlag): Promise<AudioDeviceDescriptors>
-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 |
-| --------- | --------------------------- | --------- | ------------------- |
-| deviceFlag | [DeviceFlag](#deviceflag) | Yes | Audio device flag. |
+| Name | Type | Mandatory| Description |
+| ---------- | ------------------------- | ---- | ---------------- |
+| deviceFlag | [DeviceFlag](#deviceflag) | Yes | Audio device flag.|
-**Return value:**
+**Return value**
-| Type | Description |
-| ----------------------------------------------------------- | ---------------------------------------- |
-| Promise<[AudioDeviceDescriptors](#audiodevicedescriptors)> | Promise used to return the device list. |
+| Type | Description |
+| ------------------------------------------------------------ | ------------------------- |
+| Promise<[AudioDeviceDescriptors](#audiodevicedescriptors)> | Promise used to return the device list.|
-**Example:**
+**Example**
```
audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => {
@@ -1307,21 +1307,21 @@ audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => {
### setDeviceActive
-setDeviceActive\(deviceType: DeviceType, active: boolean, callback: AsyncCallback\): void
+setDeviceActive(deviceType: ActiveDeviceType, active: boolean, callback: AsyncCallback<void>): void
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 |
-| --------- | ---------------------------------------| --------- | ---------------------------------------------------------------------------------------------------------------- |
-| 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. |
-| callback | AsyncCallback | Yes | Callback used to return the result. |
+| Name | Type | Mandatory| Description |
+| ---------- | ------------------------------------- | ---- | ------------------------ |
+| deviceType | [ActiveDeviceType](#activedevicetype) | Yes | Audio device type. |
+| 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.|
-**Example:**
+**Example**
```
audioManager.setDeviceActive(audio.DeviceType.SPEAKER, true, (err) => {
@@ -1333,31 +1333,29 @@ audioManager.setDeviceActive(audio.DeviceType.SPEAKER, true, (err) => {
});
```
-
-
### setDeviceActive
-setDeviceActive\(deviceType: DeviceType, active: boolean\): Promise
+setDeviceActive(deviceType: ActiveDeviceType, active: boolean): Promise<void>
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 |
-| --------- | ---------------------------------------| --------- | ---------------------------------------------------------------------------------------------------------------- |
-| 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. |
+| Name | Type | Mandatory| Description |
+| ---------- | ------------------------------------- | ---- | ------------------ |
+| deviceType | [ActiveDeviceType](#activedevicetype) | Yes | Audio device type.|
+| 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 |
-| ------------------- | ----------------------------------- |
-| Promise | Promise used to return the result. |
+| Type | Description |
+| ------------------- | ------------------------------- |
+| Promise<void> | Promise used to return the result.|
+**Example**
-**Example:**
```
audioManager.setDeviceActive(audio.DeviceType.SPEAKER, true).then(() => {
@@ -1365,23 +1363,22 @@ audioManager.setDeviceActive(audio.DeviceType.SPEAKER, true).then(() => {
});
```
-
### isDeviceActive
-isDeviceActive\(deviceType: DeviceType, callback: AsyncCallback\): void
+isDeviceActive(deviceType: ActiveDeviceType, callback: AsyncCallback<boolean>): 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 |
-| --------- | ---------------------------------------| --------- | -------------------------------------------------------- |
-| deviceType | [ActiveDeviceType](#activedevicetype) | Yes | Audio device type. |
-| callback | AsyncCallback | Yes | Callback used to return the active status of the device. |
+| Name | Type | Mandatory| Description |
+| ---------- | ------------------------------------- | ---- | ------------------------ |
+| deviceType | [ActiveDeviceType](#activedevicetype) | Yes | Audio device type. |
+| callback | AsyncCallback<boolean> | Yes | Callback used to return the active state of the device.|
-**Example:**
+**Example**
```
audioManager.isDeviceActive(audio.DeviceType.SPEAKER, (err, value) => {
@@ -1396,25 +1393,25 @@ audioManager.isDeviceActive(audio.DeviceType.SPEAKER, (err, value) => {
### isDeviceActive
-isDeviceActive\(deviceType: DeviceType\): Promise
+isDeviceActive(deviceType: ActiveDeviceType): Promise<boolean>
-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 |
-| --------- | ---------------------------------------| --------- | ----------------------------------------- |
-| deviceType | [ActiveDeviceType](#activedevicetype) | Yes | Audio device type. |
+| Name | Type | Mandatory| Description |
+| ---------- | ------------------------------------- | ---- | ------------------ |
+| deviceType | [ActiveDeviceType](#activedevicetype) | Yes | Audio device type.|
-**Return value:**
+**Return value**
-| Type | Description |
-| ------------------- | ----------------------------------- |
-| Promise | Promise used to return the active status of the device. |
+| Type | Description |
+| ---------------------- | ------------------------------- |
+| Promise<boolean> | Promise used to return the active state of the device.|
-**Example:**
+**Example**
```
audioManager.isDeviceActive(audio.DeviceType.SPEAKER).then((value) => {
@@ -1422,23 +1419,22 @@ audioManager.isDeviceActive(audio.DeviceType.SPEAKER).then((value) => {
});
```
-
### setMicrophoneMute
-setMicrophoneMute\(mute: boolean, callback: AsyncCallback\): void
+setMicrophoneMute(mute: boolean, callback: AsyncCallback<void>): void
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 |
-| --------- | -------------------- | --------- | ---------------------------------------------------------------------------------------------- |
-| mute | boolean | Yes | Mute status to set. The value true means to mute the microphone, and false means the opposite. |
-| callback | AsyncCallback | Yes | Callback used to return the result. |
+| Name | Type | Mandatory| Description |
+| -------- | ------------------------- | ---- | --------------------------------------------- |
+| 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. |
-**Example:**
+**Example**
```
audioManager.setMicrophoneMute(true, (err) => {
@@ -1450,30 +1446,27 @@ audioManager.setMicrophoneMute(true, (err) => {
});
```
-
### setMicrophoneMute
-setMicrophoneMute\(mute: boolean\): Promise
+setMicrophoneMute(mute: boolean): Promise<void>
Mutes or unmutes the microphone. This API uses a promise to return the result.
-**System capability:** SystemCapability.Multimedia.Audio.Device
-
-**Parameters:**
+**System capability**: SystemCapability.Multimedia.Audio.Device
-| Name | Type | Mandatory | Description |
-| --------- | -------------------- | --------- | ---------------------------------------------------------------------------------------------- |
-| mute | boolean | Yes | Mute status to set. The value true means to mute the microphone, and false means the opposite. |
+**Parameters**
-**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 |
-| ------------------- | ----------------------------------- |
-| Promise | Promise used to return the result. |
+**Return value**
-
+| Type | Description |
+| ------------------- | ------------------------------- |
+| Promise<void> | Promise used to return the result.|
-**Example:**
+**Example**
```
audioManager.setMicrophoneMute(true).then(() => {
@@ -1481,25 +1474,23 @@ audioManager.setMicrophoneMute(true).then(() => {
});
```
-
### isMicrophoneMute
-isMicrophoneMute\(callback: AsyncCallback\): void
+isMicrophoneMute(callback: AsyncCallback<boolean>): 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 |
-| --------- | -------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
-| callback | AsyncCallback | 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. |
+| 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.|
-**Example:**
+**Example**
```
-var audioManager = audio.getAudioManager();
audioManager.isMicrophoneMute((err, value) => {
if (err) {
console.error('Failed to obtain the mute status of the microphone. ${err.message}');
@@ -1509,25 +1500,24 @@ audioManager.isMicrophoneMute((err, value) => {
});
```
-
### isMicrophoneMute
-isMicrophoneMute\(\): Promise
+isMicrophoneMute(): Promise<boolean>
+
+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<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.|
-| Type | Description |
-| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
-| Promise | 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**
-**Example:**
```
-var audioManager = audio.getAudioManager();
audioManager.isMicrophoneMute().then((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) => {
on(type: 'volumeChange', callback: Callback\): 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.
-**System capability:** SystemCapability.Multimedia.Audio.Volume
+**System capability**: SystemCapability.Multimedia.Audio.Volume
-**Parameters:**
+**Parameters**
-| 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. |
-| callback | Callback<[VolumeEvent](#volumeevent8)> | Yes | Callback used to get the system volume change event. |
+| Name | Type | Mandatory| Description |
+| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ |
+| 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 return the system volume change event. |
-**Example:**
+**Example**
```
audioManager.on('volumeChange', (volumeEvent) => {
@@ -1560,25 +1550,24 @@ audioManager.on('volumeChange', (volumeEvent) => {
});
```
-
### on('ringerModeChange')8+
on(type: 'ringerModeChange', callback: Callback\): 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.
-**System capability:** SystemCapability.Multimedia.Audio.Communication
+**System capability**: SystemCapability.Multimedia.Audio.Communication
-**Parameters:**
+**Parameters**
-| 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. |
-| callback | Callback<[AudioRingMode](#audioringmode)> | Yes | Callback used to get the updated ringer mode. |
+| Name | Type | Mandatory| Description |
+| -------- | ----------------------------------------- | ---- | ------------------------------------------------------------ |
+| 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 return the updated ringer mode. |
-**Example:**
+**Example**
```
audioManager.on('ringerModeChange', (ringerMode) => {
@@ -1590,18 +1579,18 @@ audioManager.on('ringerModeChange', (ringerMode) => {
on(type: 'deviceChange', callback: Callback): 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 |
-| :------- | :-------------------------------------------------- | :---------| :---------------------------------------------------------------------------------------------------------------------------------------------- |
-| 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. |
-| callback | Callback<[DeviceChangeAction](#devicechangeaction)> | Yes | Callback used to obtain the device update details. |
+| Name | Type | Mandatory| Description |
+| :------- | :--------------------------------------------------- | :--- | :----------------------------------------- |
+| 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 return the device update details. |
-**Example:**
+**Example**
```
audioManager.on('deviceChange', (deviceChanged) => {
@@ -1616,20 +1605,20 @@ audioManager.on('deviceChange', (deviceChanged) => {
off(type: 'deviceChange', callback?: Callback): 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.
-**System capability:** SystemCapability.Multimedia.Audio.Device
+**System capability**: SystemCapability.Multimedia.Audio.Device
-**Parameters:**
+**Parameters**
-| Name | Type | Mandatory | Description |
-| :------- | :-------------------------------------------------- | :---------| :-------------------------------------------------- |
-| type | string | Yes | Type of the event to unsubscribe from. |
-| callback | Callback<[DeviceChangeAction](#devicechangeaction)> | No | Callback used to obtain the device update details. |
+| Name | Type | Mandatory| Description |
+| -------- | --------------------------------------------------- | ---- | ------------------------------------------ |
+| 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 return the device update details. |
-**Example:**
+**Example**
```
audioManager.off('deviceChange', (deviceChanged) => {
@@ -1637,26 +1626,25 @@ audioManager.off('deviceChange', (deviceChanged) => {
});
```
-
### on('interrupt')
on(type: 'interrupt', interrupt: AudioInterrupt, callback: Callback\): 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.
-**System capability:** SystemCapability.Multimedia.Audio.Renderer
+**System capability**: SystemCapability.Multimedia.Audio.Renderer
-**Parameters:**
+**Parameters**
-| 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.|
-| interrupt | AudioInterrupt | Yes | Audio interrupt event type. |
-| callback | Callback<[InterruptAction](#interruptaction)> | Yes | Audio interrupt event callback method. |
+| 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 the audio playback of the current application is interrupted by another application.|
+| interrupt | AudioInterrupt | Yes | Audio interruption event type. |
+| callback | Callback<[InterruptAction](#interruptaction)> | Yes | Callback invoked for the audio interruption event. |
-**Example:**
+**Example**
```
var interAudioInterrupt = {
@@ -1680,21 +1668,21 @@ this.audioManager.on('interrupt', interAudioInterrupt, (InterruptAction) => {
off(type: 'interrupt', interrupt: AudioInterrupt, callback?: Callback\): 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.
-**System capability:** SystemCapability.Multimedia.Audio.Renderer
+**System capability**: SystemCapability.Multimedia.Audio.Renderer
-**Parameters:**
+**Parameters**
-| 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. |
-| interrupt | AudioInterrupt | Yes | Audio interrupt event type. |
-| callback | Callback<[InterruptAction](#interruptaction)> | No | Audio interrupt event callback method. |
+| 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 the audio playback of the current application is interrupted by another application.|
+| interrupt | AudioInterrupt | Yes | Audio interruption event type. |
+| callback | Callback<[InterruptAction](#interruptaction)> | No | Callback invoked for the audio interruption event. |
-**Example:**
+**Example**
```
var interAudioInterrupt = {
@@ -1710,25 +1698,24 @@ this.audioManager.off('interrupt', interAudioInterrupt, (InterruptAction) => {
});
```
-
### setAudioScene8+
setAudioScene\(scene: AudioScene, callback: AsyncCallback\): 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.
-**System capability:** SystemCapability.Multimedia.Audio.Communication
+**System capability**: SystemCapability.Multimedia.Audio.Communication
-**Parameters:**
+**Parameters**
-| Name | Type | Mandatory | Description |
-| :------- | :------------------------------------ | :-------- | :---------------------------------- |
-| scene | AudioScene | Yes | Audio scene mode. |
-| callback | AsyncCallback | Yes | Callback used to return the result. |
+| Name | Type | Mandatory| Description |
+| :------- | :----------------------------------- | :--- | :------------------- |
+| scene | AudioScene | Yes | Audio scene to set. |
+| callback | AsyncCallback | Yes | Callback used to return the result.|
-**Example:**
+**Example**
```
audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL, (err) => {
@@ -1740,32 +1727,29 @@ audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL, (err) => {
});
```
-
### setAudioScene8+
setAudioScene\(scene: AudioScene\): Promise
-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.
-**System capability:** SystemCapability.Multimedia.Audio.Communication
+**System capability**: SystemCapability.Multimedia.Audio.Communication
-**Parameters:**
+**Parameters**
-| Name | Type | Mandatory | Description |
-| :------- | :-------------------------------------- | :-------- | :---------------- |
-| scene | AudioScene | Yes | Audio scene mode. |
+| Name| Type | Mandatory| Description |
+| :----- | :----------------------------------- | :--- | :------------- |
+| scene | AudioScene | Yes | Audio scene to set.|
+**Return value**
-**Return value:**
+| Type | Description |
+| :------------- | :------------------- |
+| Promise | Promise used to return the result.|
-| Type | Description |
-| :------------- | :---------------------------------- |
-| Promise | Promise used to return the result. |
-
-
-**Example:**
+**Example**
```
audioManager.setAudioScene(audio.AudioSceneMode.AUDIO_SCENE_PHONE_CALL).then(() => {
@@ -1775,22 +1759,21 @@ audioManager.setAudioScene(audio.AudioSceneMode.AUDIO_SCENE_PHONE_CALL).then(()
});
```
-
### getAudioScene8+
getAudioScene\(callback: AsyncCallback\): 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 |
-| :------- | :-------------------------------------------------- | :-------- | :-------------------------------------------- |
-| callback | AsyncCallback<AudioScene> | Yes | Callback used to return the audio scene mode. |
+| Name | Type | Mandatory| Description |
+| :------- | :-------------------------------------------------- | :--- | :--------------------------- |
+| callback | AsyncCallback<AudioScene> | Yes | Callback used to return the audio scene.|
-**Example:**
+**Example**
```
audioManager.getAudioScene((err, value) => {
@@ -1807,18 +1790,17 @@ audioManager.getAudioScene((err, value) => {
getAudioScene\(\): Promise
-Obtains the audio scene mode. This API uses a promise to return the query result.
-
-**System capability:** SystemCapability.Multimedia.Audio.Communication
+Obtains the audio scene. This API uses a promise to return the result.
-**Return value:**
+**System capability**: SystemCapability.Multimedia.Audio.Communication
-| Type | Description |
-| :-------------------------------------------- | :------------------------------------------- |
-| Promise<AudioScene> | Promise used to return the audio scene mode. |
+**Return value**
+| Type | Description |
+| :-------------------------------------------- | :--------------------------- |
+| Promise<AudioScene> | Promise used to return the audio scene.|
-**Example:**
+**Example**
```
audioManager.getAudioScene().then((value) => {
@@ -1832,20 +1814,18 @@ audioManager.getAudioScene().then((value) => {
Describes an audio device.
-**System capability:** SystemCapability.Multimedia.Audio.Device
+**System capability**: SystemCapability.Multimedia.Audio.Device
-| Name | Type | Readable | Writable | Description |
-| ---------- | ------------------------- | -------- | -------- | ------------------ |
-| deviceRole | [DeviceRole](#devicerole) | Yes | No | Audio device role. |
-| deviceType | [DeviceType](#devicetype) | Yes | No | Audio device type. |
+| Name | Type | Readable| Writable| Description |
+| ---------- | ------------------------- | ---- | ---- | ---------- |
+| deviceRole | [DeviceRole](#devicerole) | Yes | No | Device role.|
+| deviceType | [DeviceType](#devicetype) | Yes | No | Device type.|
## AudioDeviceDescriptors
Array of [AudioDeviceDescriptor](#audiodevicedescriptor), which is read-only.
-**System capability:** SystemCapability.Multimedia.Audio.Device
-
-**Example:**
+**Example**
```
import audio from '@ohos.multimedia.audio';
@@ -1870,45 +1850,46 @@ promise.then(function (value) {
}
});
```
+
## AudioRenderer8+
-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
### state8+
-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 |
-| :---- | :-------------------------- | :------- | :------- | :------------------ |
-| state | [AudioState](#audiostate8) | Yes | No | Audio render state. |
+| Name | Type | Readable| Writable| Description |
+| ----- | -------------------------- | ---- | ---- | ------------------ |
+| state | [AudioState](#audiostate8) | Yes | No | Audio renderer state.|
-**Example:**
+**Example**
```
- var state = audioRenderer.state;
+var state = audioRenderer.state;
```
### getRendererInfo8+
getRendererInfo(callback: AsyncCallback): 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 |
-| :------- | :------------------------------------------------------- | :-------- | :------------------------------------------------ |
-| callback | AsyncCallback<[AudioRendererInfo](#audiorendererinfo8)> | Yes | Callback used to return the renderer information. |
+| Name | Type | Mandatory| Description |
+| :------- | :------------------------------------------------------- | :--- | :--------------------- |
+| callback | AsyncCallback<[AudioRendererInfo](#audiorendererinfo8)\> | Yes | Callback used to return the renderer information.|
-**Example:**
+**Example**
```
audioRenderer.getRendererInfo((err, rendererInfo) => {
@@ -1919,22 +1900,21 @@ audioRenderer.getRendererInfo((err, rendererInfo) => {
});
```
-
### getRendererInfo8+
getRendererInfo(): Promise
-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 |
-| :-------------------------------------------------- | :----------------------------------------------- |
-| Promise<[AudioRendererInfo](#audiorendererinfo8)> | Promise used to return the renderer information. |
+| Type | Description |
+| -------------------------------------------------- | ------------------------------- |
+| Promise<[AudioRendererInfo](#audiorendererinfo8)\> | Promise used to return the renderer information.|
-**Example:**
+**Example**
```
audioRenderer.getRendererInfo().then((rendererInfo) => {
@@ -1946,24 +1926,23 @@ audioRenderer.getRendererInfo().then((rendererInfo) => {
console.log('AudioFrameworkRenderLog: RendererInfo :ERROR: '+err.message);
resultFlag = false;
});
-
```
### getStreamInfo8+
getStreamInfo(callback: AsyncCallback): 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 |
-| :------- | :------------------------------------------------------ | :-------- | :---------------------------------------------- |
-| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | Yes | Callback used to return the stream information. |
+| Name | Type | Mandatory| Description |
+| :------- | :--------------------------------------------------- | :--- | :------------------- |
+| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | Yes | Callback used to return the stream information.|
-**Example:**
+**Example**
```
audioRenderer.getStreamInfo((err, streamInfo) => {
@@ -1979,17 +1958,17 @@ audioRenderer.getStreamInfo((err, streamInfo) => {
getStreamInfo(): Promise
-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 |
-| :------------------------------------------------- | :--------------------------------------------- |
-| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information. |
+| Type | Description |
+| :--------------------------------------------- | :--------------------- |
+| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information.|
-**Example:**
+**Example**
```
audioRenderer.getStreamInfo().then((streamInfo) => {
@@ -2001,7 +1980,6 @@ audioRenderer.getStreamInfo().then((streamInfo) => {
}).catch((err) => {
console.log('ERROR: '+err.message);
});
-
```
### start8+
@@ -2010,16 +1988,15 @@ start(callback: AsyncCallback): void
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 |
-| :------- | :---------------------- | :-------- | :-------------------------------------- |
-| callback | AsyncCallback | Yes | Callback used to return the result. |
-| | | | |
+| Name | Type | Mandatory| Description |
+| -------- | -------------------- | ---- | ---------- |
+| callback | AsyncCallback\ | Yes | Callback used to return the result.|
-**Example:**
+**Example**
```
audioRenderer.start((err) => {
@@ -2037,15 +2014,15 @@ start(): Promise
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 |
-| :------------- | :--------------------------------- |
-| Promise | Promise used to return the result. |
+| Type | Description |
+| -------------- | ------------------------- |
+| Promise\ | Promise used to return the result.|
-**Example:**
+**Example**
```
audioRenderer.start().then(() => {
@@ -2055,23 +2032,21 @@ audioRenderer.start().then(() => {
});
```
-
### pause8+
pause(callback: AsyncCallback\): void
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 |
-| :------- | :---------------------- | :-------- | :------------------------------------ |
-| callback | AsyncCallback | Yes | Callback used to return the result. |
-| | | | |
+| Name | Type | Mandatory| Description |
+| -------- | -------------------- | ---- | ---------------- |
+| callback | AsyncCallback\ | Yes | Callback used to return the result.|
-**Example:**
+**Example**
```
audioRenderer.pause((err) => {
@@ -2089,15 +2064,15 @@ pause(): Promise\
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 |
-| :------------- | :--------------------------------- |
-| Promise | Promise used to return the result. |
+| Type | Description |
+| -------------- | ------------------------- |
+| Promise\ | Promise used to return the result.|
-**Example:**
+**Example**
```
audioRenderer.pause().then(() => {
@@ -2113,16 +2088,15 @@ drain(callback: AsyncCallback\): void
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 |
-| :------- | :---------------------- | :-------- | :---------------------------------------|
-| callback | AsyncCallback | Yes | Callback used to return the result. |
-| | | | |
+| Name | Type | Mandatory| Description |
+| -------- | -------------------- | ---- | ---------------- |
+| callback | AsyncCallback\ | Yes | Callback used to return the result.|
-**Example:**
+**Example**
```
audioRenderer.drain((err) => {
@@ -2140,15 +2114,15 @@ drain(): Promise\
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 |
-| :------------- | :--------------------------------- |
-| Promise | Promise used to return the result. |
+| Type | Description |
+| -------------- | ------------------------- |
+| Promise\ | Promise used to return the result.|
-**Example:**
+**Example**
```
audioRenderer.drain().then(() => {
@@ -2158,22 +2132,21 @@ audioRenderer.drain().then(() => {
});
```
-
### stop8+
stop(callback: AsyncCallback\): void
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 |
-| :------- | :---------------------- | :-------- | :------------------------------------- |
-| callback | AsyncCallback | Yes | Callback used to return the result. |
+| Name | Type | Mandatory| Description |
+| -------- | -------------------- | ---- | ---------------- |
+| callback | AsyncCallback\ | Yes | Callback used to return the result.|
-**Example:**
+**Example**
```
audioRenderer.stop((err) => {
@@ -2191,15 +2164,15 @@ stop(): Promise\
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 |
-| :------------- | :--------------------------------- |
-| Promise | Promise used to return the result. |
+| Type | Description |
+| -------------- | ------------------------- |
+| Promise\ | Promise used to return the result.|
-**Example:**
+**Example**
```
audioRenderer.stop().then(() => {
@@ -2209,22 +2182,21 @@ audioRenderer.stop().then(() => {
});
```
-
### release8+
release(callback: AsyncCallback\): void
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 |
-| :------- | :---------------------- | :-------- | :------------------------------------- |
-| callback | AsyncCallback | Yes | Callback used to return the result. |
+| Name | Type | Mandatory| Description |
+| -------- | -------------------- | ---- | ---------------- |
+| callback | AsyncCallback\ | Yes | Callback used to return the result.|
-**Example:**
+**Example**
```
audioRenderer.release((err) => {
@@ -2242,15 +2214,15 @@ release(): Promise\
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 |
-| :------------- | :--------------------------------- |
-| Promise | Promise used to return the result. |
+| Type | Description |
+| -------------- | ------------------------- |
+| Promise\ | Promise used to return the result.|
-**Example:**
+**Example**
```
audioRenderer.release().then(() => {
@@ -2266,16 +2238,16 @@ write(buffer: ArrayBuffer, callback: AsyncCallback\): void
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 |
-| :------- | :---------------------- | :-------- | :--------------------------------------------------------------------------------------------------- |
-| buffer | ArrayBuffer | Yes | Buffer to be written. |
-| callback | AsyncCallback | Yes | Returns the number of bytes written if the operation is successful; returns an error code otherwise. |
+| Name | Type | Mandatory| Description |
+| -------- | ---------------------- | ---- | --------------------------------------------------- |
+| buffer | ArrayBuffer | Yes | Buffer to be written. |
+| callback | AsyncCallback\ | 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';
@@ -2293,22 +2265,21 @@ audioRenderer.write(buf, (err, writtenbytes) => {
});
```
-
### write8+
write(buffer: ArrayBuffer): Promise\
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 |
-| :--------------- | :--------------------------------------------------------------------------------------------------- |
-| Promise | Returns the number of bytes written if the operation is successful; returns an error code otherwise. |
+| Type | Description |
+| ---------------- | ------------------------------------------------------------ |
+| Promise\ | Returns the number of bytes written if the operation is successful; returns an error code otherwise.|
-**Example:**
+**Example**
```
import audio from '@ohos.multimedia.audio';
@@ -2333,17 +2304,17 @@ audioRenderer.write(buf).then((writtenbytes) => {
getAudioTime(callback: AsyncCallback\): 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 |
-| :------- | :--------------------- | :-------- | :------------------------------------- |
-| callback | AsyncCallback | Yes | Callback used to return the timestamp. |
+| Name | Type | Mandatory| Description |
+| -------- | ---------------------- | ---- | ---------------- |
+| callback | AsyncCallback\ | Yes | Callback used to return the timestamp.|
-**Example:**
+**Example**
```
audioRenderer.getAudioTime((err, timestamp) => {
@@ -2351,22 +2322,21 @@ audioRenderer.getAudioTime((err, timestamp) => {
});
```
-
### getAudioTime8+
getAudioTime(): Promise\
-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 |
-| :--------------- | :------------------------------------ |
-| Promise | Promise used to return the timestamp. |
+| Type | Description |
+| ---------------- | ----------------------- |
+| Promise\ | Promise used to return the timestamp.|
-**Example:**
+**Example**
```
audioRenderer.getAudioTime().then((timestamp) => {
@@ -2376,22 +2346,21 @@ audioRenderer.getAudioTime().then((timestamp) => {
});
```
-
### getBufferSize8+
getBufferSize(callback: AsyncCallback\): void
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 |
-| :------- | :--------------------- | :-------- | :--------------------------------------- |
-| callback | AsyncCallback | Yes | Callback used to return the buffer size. |
+| Name | Type | Mandatory| Description |
+| -------- | ---------------------- | ---- | -------------------- |
+| callback | AsyncCallback\ | Yes | Callback used to return the buffer size.|
-**Example:**
+**Example**
```
audioRenderer.getBufferSize((err, bufferSize) => {
@@ -2403,22 +2372,21 @@ let buf = new ArrayBuffer(bufferSize);
ss.readSync(buf);
```
-
### getBufferSize8+
getBufferSize(): Promise\
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 |
-| :--------------- | :-------------------------------------- |
-| Promise | Promise used to return the buffer size. |
+| Type | Description |
+| ---------------- | --------------------------- |
+| Promise\ | Promise used to return the buffer size.|
-**Example:**
+**Example**
```
audioRenderer.getBufferSize().then((bufferSize) => {
@@ -2435,16 +2403,16 @@ setRenderRate(rate: AudioRendererRate, callback: AsyncCallback\): void
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 |
-| :------- | :------------------------------------------ | :-------- | :---------------------------------- |
-| rate | [AudioRendererRate](#audiorendererrate8) | Yes | Audio render rate. |
-| callback | AsyncCallback | Yes | Callback used to return the result. |
+| Name | Type | Mandatory| Description |
+| -------- | ---------------------------------------- | ---- | ------------------------ |
+| rate | [AudioRendererRate](#audiorendererrate8) | Yes | Audio render rate. |
+| callback | AsyncCallback\ | Yes | Callback used to return the result.|
-**Example:**
+**Example**
```
audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL, (err) => {
@@ -2456,28 +2424,27 @@ audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL, (err) =>
});
```
-
### setRenderRate8+
setRenderRate(rate: AudioRendererRate): Promise\
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 |
-| :--- | :--------------------------------------- | :-------- | :----------------- |
-| rate | [AudioRendererRate](#audiorendererrate8) | Yes | Audio render rate. |
+| Name| Type | Mandatory| Description |
+| ------ | ---------------------------------------- | ---- | ------------ |
+| rate | [AudioRendererRate](#audiorendererrate8) | Yes | Audio render rate.|
-**Return value:**
+**Return value**
-| Type | Description |
-| :------------- | :--------------------------------- |
-| Promise | Promise used to return the result. |
+| Type | Description |
+| -------------- | ------------------------- |
+| Promise\ | Promise used to return the result.|
-**Example:**
+**Example**
```
audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL).then(() => {
@@ -2493,15 +2460,15 @@ getRenderRate(callback: AsyncCallback\): void
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 |
-| :------- | :------------------------------------------------------- | :-------- | :--------------------------------------------- |
-| callback | AsyncCallback<[AudioRendererRate](#audiorendererrate8)\> | Yes | Callback used to return the audio render rate. |
+| Name | Type | Mandatory| Description |
+| -------- | ------------------------------------------------------- | ---- | ------------------ |
+| callback | AsyncCallback<[AudioRendererRate](#audiorendererrate8)> | Yes | Callback used to return the audio render rate.|
-**Example:**
+**Example**
```
audioRenderer.getRenderRate((err, renderrate) => {
@@ -2509,22 +2476,21 @@ audioRenderer.getRenderRate((err, renderrate) => {
});
```
-
### getRenderRate8+
getRenderRate(): Promise\
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 |
-| :-------------------------------------------------- | :-------------------------------------------- |
-| Promise<<[AudioRendererRate](#audiorendererrate8)\> | Promise used to return the audio render rate. |
+| Type | Description |
+| ------------------------------------------------- | ------------------------- |
+| Promise<[AudioRendererRate](#audiorendererrate8)> | Promise used to return the audio render rate.|
-**Example:**
+**Example**
```
audioRenderer.getRenderRate().then((renderRate) => {
@@ -2534,23 +2500,68 @@ audioRenderer.getRenderRate().then((renderRate) => {
});
```
+### on('interrupt')9+
+
+on(type: 'interrupt', callback: Callback\): 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')8+
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 |
-| :------- | :------------------------ | :-------- | :----------------------------------------------------------------------- |
-| type | string | Yes | Type of the renderer event to subscribe to. |
-| 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. |
+| Name | Type | Mandatory| Description |
+| :------- | :----------------------- | :--- | :---------------------------------------- |
+| 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**. |
+| callback | (position: number) => {} | Yes | Callback invoked when the event is triggered. |
-**Example:**
+**Example**
```
audioRenderer.on('markReach', 1000, (position) => {
@@ -2567,15 +2578,15 @@ off(type: 'markReach'): void
Unsubscribes from mark reached events.
-**System capability:** SystemCapability.Multimedia.Audio.Renderer
+**System capability**: SystemCapability.Multimedia.Audio.Renderer
-**Parameters:**
+**Parameters**
-| Name | Type | Mandatory | Description |
-| :------- | :------------------------ | :-------- | :----------------------------------------------- |
-| type | string | Yes | Type of the renderer event to unsubscribe from. |
+| Name| Type | Mandatory| Description |
+| :----- | :----- | :--- | :------------------------------------------------ |
+| type | string | Yes | Type of event to unsubscribe from. The value is fixed at **markReach**.|
-**Example:**
+**Example**
```
audioRenderer.off('markReach');
@@ -2585,19 +2596,19 @@ audioRenderer.off('markReach');
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 |
-| :------- | :------------------------ | :-------- | :--------------------------------------------------------------------------------- |
-| type | string | Yes | Type of the renderer event to subscribe to. |
-| 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. |
+| Name | Type | Mandatory| Description |
+| :------- | :----------------------- | :--- | :------------------------------------------ |
+| 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**. |
+| callback | (position: number) => {} | Yes | Callback invoked when the event is triggered. |
-**Example:**
+**Example**
```
audioRenderer.on('periodReach', 1000, (position) => {
@@ -2613,15 +2624,15 @@ off(type: 'periodReach'): void
Unsubscribes from period reached events.
-**System capability:** SystemCapability.Multimedia.Audio.Renderer
+**System capability**: SystemCapability.Multimedia.Audio.Renderer
-**Parameters:**
+**Parameters**
-| Name | Type | Mandatory | Description |
-| :------- | :------------------------ | :-------- | :----------------------------------------------- |
-| type | string | Yes | Type of the renderer event to unsubscribe from. |
+| Name| Type | Mandatory| Description |
+| :----- | :----- | :--- | :-------------------------------------------------- |
+| type | string | Yes | Type of event to unsubscribe from. The value is fixed at **periodReach**.|
-**Example:**
+**Example**
```
audioRenderer.off('periodReach')
@@ -2633,16 +2644,16 @@ on(type: 'stateChange', callback: Callback): void
Subscribes to state change events.
-**System capability:** SystemCapability.Multimedia.Audio.Renderer
+**System capability**: SystemCapability.Multimedia.Audio.Renderer
-**Parameters:**
+**Parameters**
-| Name | Type | Mandatory | Description |
-| :------- | :------------------------- | :-------- | :--------------------------------------------------------------------------------------- |
-| type | string | Yes | Type of the event to subscribe to. The value 'stateChange' means the state change event. |
-| callback | [AudioState](#audiostate8) | Yes | Callback used to return the state change. |
+| Name | Type | Mandatory| Description |
+| :------- | :------------------------- | :--- | :------------------------------------------ |
+| 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. |
-**Example:**
+**Example**
```
audioRenderer.on('stateChange', (state) => {
@@ -2657,42 +2668,41 @@ audioRenderer.on('stateChange', (state) => {
## AudioCapturer8+
-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.
### state8+
-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 |
-| :---- | :------------------------- | :------- | :------- | :------------------- |
-| state | [AudioState](#audiostate8) | Yes | No | Audio capture state. |
+| Name | Type | Readable| Writable| Description |
+| :---- | :------------------------- | :--- | :--- | :--------------- |
+| state | [AudioState](#audiostate8) | Yes | No | Audio capturer state.|
-**Example:**
+**Example**
```
var state = audioCapturer.state;
```
-
### getCapturerInfo8+
getCapturerInfo(callback: AsyncCallback): 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 |
-| :------- | :------------------------------------------------------- | :-------- | :------------------------------------------------ |
-| callback | AsyncCallback<[AudioCapturerInfo](#audiocapturerinfo)\> | Yes | Callback used to return the capturer information. |
+| Name | Type | Mandatory| Description |
+| :------- | :-------------------------------- | :--- | :----------------------------------- |
+| callback | AsyncCallback | Yes | Callback used to return the capturer information.|
-**Example:**
+**Example**
```
audioCapturer.getCapturerInfo((err, capturerInfo) => {
@@ -2711,17 +2721,17 @@ audioCapturer.getCapturerInfo((err, capturerInfo) => {
getCapturerInfo(): Promise
-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 |
-| :-------------------------------------------------- | :----------------------------------------------- |
-| Promise<[AudioCapturerInfo](#audiocapturerinfo)\> | Promise used to return the capturer information. |
+| Type | Description |
+| :------------------------------------------------ | :---------------------------------- |
+| Promise<[AudioCapturerInfo](#audiocapturerinfo)\> | Promise used to return the capturer information.|
-**Example:**
+**Example**
```
audioCapturer.getCapturerInfo().then((audioParamsGet) => {
@@ -2736,24 +2746,23 @@ audioCapturer.getCapturerInfo().then((audioParamsGet) => {
}).catch((err) => {
console.log('AudioFrameworkRecLog: CapturerInfo :ERROR: '+err.message);
});
-
```
### getStreamInfo8+
getStreamInfo(callback: AsyncCallback): 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 |
-| :------- | :----------------------------------------------------------- | :-------- | :---------------------------------------------- |
-| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | Yes | Callback used to return the stream information. |
+| Name | Type | Mandatory| Description |
+| :------- | :--------------------------------------------------- | :--- | :------------------------------- |
+| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | Yes | Callback used to return the stream information.|
-**Example:**
+**Example**
```
audioCapturer.getStreamInfo((err, streamInfo) => {
@@ -2773,17 +2782,17 @@ audioCapturer.getStreamInfo((err, streamInfo) => {
getStreamInfo(): Promise
-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 |
-| :---------------------------------------------------- | :----------------------------------------------- |
-| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information. |
+| Type | Description |
+| :--------------------------------------------- | :------------------------------ |
+| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information.|
-**Example:**
+**Example**
```
audioCapturer.getStreamInfo().then((audioParamsGet) => {
@@ -2795,7 +2804,6 @@ audioCapturer.getStreamInfo().then((audioParamsGet) => {
}).catch((err) => {
console.log('getStreamInfo :ERROR: ' + err.message);
});
-
```
### start8+
@@ -2804,15 +2812,15 @@ start(callback: AsyncCallback): void
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 |
-| :------- | :---------------------- | :-------- | :-------------------------------------- |
-| callback | AsyncCallback | Yes | Callback used to return the result. |
+| Name | Type | Mandatory| Description |
+| :------- | :------------------- | :--- | :----------------------------- |
+| callback | AsyncCallback | Yes | Callback used to return the result.|
-**Example:**
+**Example**
```
audioCapturer.start((err) => {
@@ -2831,15 +2839,15 @@ start(): Promise
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 |
-| :------------- | :--------------------------------- |
-| Promise | Promise used to return the result. |
+| Type | Description |
+| :------------- | :---------------------------- |
+| Promise | Promise used to return the result.|
-**Example:**
+**Example**
```
audioCapturer.start().then(() => {
@@ -2862,15 +2870,15 @@ stop(callback: AsyncCallback): void
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 |
-| :------- | :---------------------- | :-------- | :------------------------------------- |
-| callback | AsyncCallback | Yes | Callback used to return the result. |
+| Name | Type | Mandatory| Description |
+| :------- | :------------------- | :--- | :----------------------------- |
+| callback | AsyncCallback | Yes | Callback used to return the result.|
-**Example:**
+**Example**
```
audioCapturer.stop((err) => {
@@ -2889,15 +2897,15 @@ stop(): Promise
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 |
-| :------------- | :--------------------------------- |
-| Promise | Promise used to return the result. |
+| Type | Description |
+| :------------- | :---------------------------- |
+| Promise | Promise used to return the result.|
-**Example:**
+**Example**
```
audioCapturer.stop().then(() => {
@@ -2913,22 +2921,21 @@ audioCapturer.stop().then(() => {
});
```
-
### release8+
release(callback: AsyncCallback): 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 |
-| :------- | :---------------------- | :-------- | :------------------------------------- |
-| callback | AsyncCallback | Yes | Callback used to return the result. |
+| Name | Type | Mandatory| Description |
+| :------- | :------------------- | :--- | :---------------------------------- |
+| callback | AsyncCallback | Yes | Callback used to return the result. |
-**Example:**
+**Example**
```
audioCapturer.release((err) => {
@@ -2945,20 +2952,19 @@ audioCapturer.release((err) => {
release(): Promise
-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 |
-| :------------- | :--------------------------------- |
-| Promise | Promise used to return the result. |
+| Type | Description |
+| :------------- | :---------------------------- |
+| Promise | Promise used to return the result.|
-**Example:**
+**Example**
```
-
audioCapturer.release().then(() => {
console.info('AudioFrameworkRecLog: ---------RELEASE RECORD---------');
console.info('AudioFrameworkRecLog: Capturer release : SUCCESS');
@@ -2971,7 +2977,6 @@ audioCapturer.release().then(() => {
console.info('AudioFrameworkRecLog: Capturer stop:ERROR : '+err.message);
stateFlag=false
});
-
```
@@ -2979,19 +2984,19 @@ audioCapturer.release().then(() => {
read(size: number, isBlockingRead: boolean, callback: AsyncCallback): 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 |
-| :------------- | :-------------------------- | :-------- | :-------------------------------------------- |
-| size | number | Yes | Number of bytes to read. |
-| isBlockingRead | boolean | Yes | Whether the read operation should be blocked. |
-| callback | AsyncCallback | Yes | Callback used to return the buffer. |
+| Name | Type | Mandatory| Description |
+| :------------- | :-------------------------- | :--- | :------------------------------- |
+| size | number | Yes | Number of bytes to read. |
+| isBlockingRead | boolean | Yes | Whether to block the read operation. |
+| callback | AsyncCallback | Yes | Callback used to return the buffer.|
-**Example:**
+**Example**
```
audioCapturer.read(bufferSize, true, async(err, buffer) => {
@@ -3006,24 +3011,24 @@ audioCapturer.read(bufferSize, true, async(err, buffer) => {
read(size: number, isBlockingRead: boolean): Promise
-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 |
-| :------------- | :--------- | :-------- | :-------------------------------------------- |
-| size | number | Yes | Number of bytes to read. |
-| isBlockingRead | boolean | Yes | Whether the read operation should be blocked. |
+| Name | Type | Mandatory| Description |
+| :------------- | :------ | :--- | :--------------- |
+| size | number | Yes | Number of bytes to read. |
+| isBlockingRead | boolean | Yes | Whether to block the read operation.|
-**Return value:**
+**Return value**
-| Type | Description |
-| :-------------------- | :----------------------------------------------------------------------------------------------- |
-| Promise | Returns the buffer data read if the operation is successful; returns an error code otherwise. |
+| Type | Description |
+| :-------------------- | :----------------------------------------------------- |
+| Promise | Returns the buffer data read if the operation is successful; returns an error code otherwise.|
-**Example:**
+**Example**
```
audioCapturer.read(bufferSize, true).then((buffer) => {
@@ -3038,18 +3043,17 @@ audioCapturer.read(bufferSize, true).then((buffer) => {
getAudioTime(callback: AsyncCallback): 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 |
-| :------- | :--------------------- | :-------- | :------------------------------------- |
-| callback | AsyncCallback | Yes | Callback used to return the timestamp. |
-| | | | |
+| Name | Type | Mandatory| Description |
+| :------- | :--------------------- | :--- | :----------------------------- |
+| callback | AsyncCallback | Yes | Callback used to return the timestamp.|
-**Example:**
+**Example**
```
audioCapturer.getAudioTime((err, timestamp) => {
@@ -3062,17 +3066,17 @@ audioCapturer.getAudioTime((err, timestamp) => {
getAudioTime(): Promise
-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 |
-| :--------------- | :------------------------------------ |
-| Promise | Promise used to return the timestamp. |
+| Type | Description |
+| :--------------- | :---------------------------- |
+| Promise | Promise used to return the timestamp.|
-**Example:**
+**Example**
```
audioCapturer.getAudioTime().then((audioTime) => {
@@ -3080,7 +3084,6 @@ audioCapturer.getAudioTime().then((audioTime) => {
}).catch((err) => {
console.info('AudioFrameworkRecLog: AudioCapturer Created : ERROR : '+err.message);
});
-
```
@@ -3090,16 +3093,15 @@ getBufferSize(callback: AsyncCallback): void
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 |
-| :------- | :--------------------- | :-------- | :--------------------------------------- |
-| callback | AsyncCallback | Yes | Callback used to return the buffer size. |
-| | | | |
+| Name | Type | Mandatory| Description |
+| :------- | :--------------------- | :--- | :----------------------------------- |
+| callback | AsyncCallback | Yes | Callback used to return the buffer size.|
-**Example:**
+**Example**
```
audioCapturer.getBufferSize((err, bufferSize) => {
@@ -3114,21 +3116,22 @@ audioCapturer.getBufferSize((err, bufferSize) => {
});
```
+
### getBufferSize8+
getBufferSize(): Promise
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 |
-| :--------------- | :-------------------------------------- |
-| Promise | Promise used to return the buffer size. |
+| Type | Description |
+| :--------------- | :---------------------------------- |
+| Promise | Promise used to return the buffer size.|
-**Example:**
+**Example**
```
audioCapturer.getBufferSize().then((bufferSize) => {
@@ -3143,23 +3146,24 @@ audioCapturer.getBufferSize().then((bufferSize) => {
});
```
+
### on('markReach')8+
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 |
-| :------- | :------------------------ | :-------- | :----------------------------------------------------------------------- |
-| type | string | Yes | Type of the capturer event to subscribe to. |
-| 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. |
+| Name | Type | Mandatory| Description |
+| :------- | :---------------------- | :--- | :----------------------------------------- |
+| 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**. |
+| callback | position: number) => {} | Yes | Callback invoked when the event is triggered.|
-**Example:**
+**Example**
```
audioCapturer.on('markReach', 1000, (position) => {
@@ -3169,22 +3173,21 @@ audioCapturer.on('markReach', 1000, (position) => {
});
```
-
### off('markReach')8+
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 |
-| :------- | :------------------------ | :-------- | :---------------------------------------------- |
-| type | string | Yes | Type of the capturer event to unsubscribe from. |
+| Name| Type | Mandatory| Description |
+| :----- | :----- | :--- | :-------------------------------------------- |
+| 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');
@@ -3194,19 +3197,19 @@ audioCapturer.off('markReach');
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 |
-| :------- | :------------------------ | :-------- | :--------------------------------------------------------------------------------- |
-| type | string | Yes | Type of the capturer event to subscribe to. |
-| frame | number | Yes | Period during which frame capturing is listened. The value must be greater than 0. |
-| callback | (position: number) => {} | Yes | Callback invoked when the event is triggered. |
+| Name | Type | Mandatory| Description |
+| :------- | :----------------------- | :--- | :------------------------------------------ |
+| 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 | 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. |
-**Example:**
+**Example**
```
audioCapturer.on('periodReach', 1000, (position) => {
@@ -3222,15 +3225,15 @@ off(type: 'periodReach'): void
Unsubscribes from period reached events.
-**System capability:** SystemCapability.Multimedia.Audio.Capturer
+**System capability**: SystemCapability.Multimedia.Audio.Capturer
-**Parameters:**
+**Parameters**
-| Name | Type | Mandatory | Description |
-| :------- | :------------------------ | :-------- | :---------------------------------------------- |
-| type | string | Yes | Type of the capturer event to unsubscribe from. |
+| Name| Type | Mandatory| Description |
+| :----- | :----- | :--- | :---------------------------------------------- |
+| 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')
@@ -3242,16 +3245,16 @@ on(type: 'stateChange', callback: Callback): void
Subscribes to state change events.
-**System capability:** SystemCapability.Multimedia.Audio.Capturer
+**System capability**: SystemCapability.Multimedia.Audio.Capturer
-**Parameters:**
+**Parameters**
-| Name | Type | Mandatory | Description |
-| :------- | :------------------------- | :-------- | :--------------------------------------------------------------------------------------- |
-| type | string | Yes | Type of the event to subscribe to. The value 'stateChange' means the state change event. |
-| callback | [AudioState](#audiostate8) | Yes | Callback used to return the state change. |
+| Name | Type | Mandatory| Description |
+| :------- | :------------------------- | :--- | :------------------------------------------ |
+| 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. |
-**Example:**
+**Example**
```
audioCapturer.on('stateChange', (state) => {
diff --git a/en/application-dev/reference/apis/js-apis-camera.md b/en/application-dev/reference/apis/js-apis-camera.md
index 6495d3cd2e44ebe1ed618620d60276d7f57f3ef6..17de0ce539b0da7fdaeabdac74bff55b84dede67 100644
--- a/en/application-dev/reference/apis/js-apis-camera.md
+++ b/en/application-dev/reference/apis/js-apis-camera.md
@@ -1,8 +1,7 @@
-# Camera
+# Camera Management
->  **NOTE**
->
-> 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.
+> **NOTE**
+> 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.
## Modules to Import
@@ -12,25 +11,22 @@ import camera from '@ohos.multimedia.camera';
## Required Permissions
-```
ohos.permission.CAMERA
-```
-## getCameraManager(context: Context, callback: AsyncCallback): void;
-**System Capabilities:**
+## camera.getCameraManager
-SystemCapability.Multimedia.Camera.Core
+getCameraManager(context: Context, callback: AsyncCallback): 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**
-| Name | Type | Mandatory | Description |
-|----------|-------------------------------|-----------|-----------------------------------------------------|
-| context | Context | Yes | Application context |
-| callback | AsyncCallback | Yes | Callback used to return the CameraManager instance |
+| Name | Type | Mandatory| Description |
+| -------- | ----------------------------------------------- | ---- | ---------------------------------- |
+| context | Context | Yes | Application context. |
+| callback | AsyncCallback<[CameraManager](#cameramanager)\> | Yes | Callback used to return the **CameraManager** instance.|
**Example**
@@ -44,116 +40,105 @@ camera.getCameraManager(context, (err, cameraManager) => {
});
```
-## getCameraManager(context: Context): Promise;
-
-**System Capabilities:**
+## camera.getCameraManager
-SystemCapability.Multimedia.Camera.Core
+getCameraManager(context: Context): Promise
-**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**
-| Name | Type | Mandatory | Description |
-|----------|----------------------|-----------|----------------------------|
-| context | Context | Yes | Application context |
+| Name | Type | Mandatory| Description |
+| ------- | ------- | ---- | ------------ |
+| context | Context | Yes | Application context.|
-**Return values**
+**Return value**
-| Type | Description |
-|-------------------------|--------------------------------------------------------|
-| Promise | Promise used to return the **CameraManager** instance |
+| Type | Description |
+| ----------------------------------------- | ----------------------------------------- |
+| Promise<[CameraManager](#cameramanager)\> | Promise used to return the **CameraManager** instance.|
**Example**
```
-camera.getCameraManager(context).then((cameraManger) => {
+camera.getCameraManager(context).then((cameraManager) => {
console.log('Promise returned with the CameraManager instance.');
})
```
-## CameraStatus
+## 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
Enumerates the camera positions.
-**System Capabilities:**
-
-SystemCapability.Multimedia.Camera.Core
+**System capability**: SystemCapability.Multimedia.Camera.Core
-| Name | Default value | Description |
-|-----------------------------|---------------|-----------------------|
-| CAMERA_POSITION_UNSPECIFIED | 0 | Unspecified position |
-| CAMERA_POSITION_BACK | 1 | Rear camera |
-| CAMERA_POSITION_FRONT | 2 | Front camera |
+| Name | Default Value| Description |
+| --------------------------- | ------ | ---------------- |
+| CAMERA_POSITION_UNSPECIFIED | 0 | Unspecified position.|
+| CAMERA_POSITION_BACK | 1 | Rear camera. |
+| CAMERA_POSITION_FRONT | 2 | Front camera. |
-## CameraType
+## CameraType
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
+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 |
-|------------------------------|---------------|----------------------------|
-| CAMERA_CONNECTION_BUILT_IN | 0 | Built-in camera |
-| CAMERA_CONNECTION_USB_PLUGIN | 1 | Camera connected using USB |
-| CAMERA_CONNECTION_REMOTE | 2 | Remote camera |
+## CameraManager
-## CameraManager
+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\>): void;
+getCameras(callback: AsyncCallback\>): 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
-
-**Description**
-
-Gets all cameras supported by the device. This method uses an asynchronous callback to return the array of supported cameras.
+**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
-| Name | Type | Mandatory | Description |
-|----------|--------------------------------|-----------|---------------------------------------------------------|
-| callback | AsyncCallback\> | Yes | Callback used to return the array of supported cameras. |
+| Name | Type | Mandatory| Description |
+| -------- | ----------------------------------------- | ---- | ------------------------------------ |
+| callback | AsyncCallback\> | Yes | Callback used to return the array of supported cameras.|
**Example**
@@ -167,21 +152,19 @@ cameraManager.getCameras((err, cameras) => {
})
```
-### getCameras(): Promise\>;
+### getCameras
-**System Capabilities:**
+getCameras(): Promise\>
-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 |
-|------------------------|--------------------------------------------------------|
-| Promise\> | Promise used to return an array of supported cameras |
+| Type | Description |
+| ----------------------------------- | ----------------------------- |
+| Promise\> | Promise used to return the array of supported cameras.|
**Example**
@@ -192,22 +175,20 @@ cameraManager.getCameras().then((cameraArray) => {
})
```
-### createCameraInput(cameraId: string, callback: AsyncCallback): void;
-
-**System Capabilities:**
+### createCameraInput
-SystemCapability.Multimedia.Camera.Core
+createCameraInput(cameraId: string, callback: AsyncCallback): 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**
-| Name | Default value | Mandatory | Description |
-|----------|------------------------------|-----------|--------------------------------------------------|
-| cameraId | string | Yes | Camera ID used to create the instance |
-| callback | AsyncCallback | Yes | Callback used to return the CameraInput instance |
+| Name | Default Value | Mandatory| Description |
+| -------- | ------------------------------------------- | ---- | ----------------------------------- |
+| cameraId | string | Yes | Camera ID used to create the instance. |
+| callback | AsyncCallback<[CameraInput](#camerainput)\> | Yes | Callback used to return the **CameraInput** instance.|
**Example**
@@ -221,27 +202,25 @@ cameraManager.createCameraInput(cameraId, (err, cameraInput) => {
})
```
-### createCameraInput(cameraId: string): Promise;
+### createCameraInput
-**System Capabilities:**
+createCameraInput(cameraId: string): Promise
-SystemCapability.Multimedia.Camera.Core
+Creates a **CameraInput** instance with the specified camera ID. This API uses a promise to return the instance.
-**Description**
-
-Creates a **CameraInput** instance with the specified camera ID. This method uses a promise to return the instance.
+**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
-| Name | Default value | Mandatory | Description |
-|----------|-----------------------------|-----------|------------------------------------------|
-| cameraId | string | Yes | Camera ID used to create the instance |
+| Name | Default Value| Mandatory| Description |
+| -------- | ------ | ---- | ------------ |
+| cameraId | string | Yes | Camera ID used to create the instance.|
-**Return values**
+**Return value**
-| Type | Description |
-|-------------------------|-------------------------------------------------|
-| Promise | Promise used to return the CameraInput instance |
+| Type | Description |
+| ------------------------------------- | ---------------------------------------- |
+| Promise<[CameraInput](#camerainput)\> | Promise used to return the **CameraInput** instance.|
**Example**
@@ -251,23 +230,21 @@ cameraManager.createCameraInput(cameraId).then((cameraInput) => {
})
```
-### createCameraInput(position: CameraPosition, type: CameraType, callback: AsyncCallback): void;
-
-**System Capabilities:**
+### createCameraInput
-SystemCapability.Multimedia.Camera.Core
+createCameraInput(position: CameraPosition, type: CameraType, callback: AsyncCallback): 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**
-| Name | Type | Mandatory | Description |
-|----------|-----------------------------|-----------|---------------------------------------------------|
-| position | CameraPosition | Yes | Camera position |
-| type | CameraType | Yes | Camera type |
-| callback | AsyncCallback | Yes | Callback used to return the CameraInput instance |
+| Name | Type | Mandatory| Description |
+| -------- | ------------------------------------------- | ---- | ----------------------------------- |
+| position | [CameraPosition](#cameraposition) | Yes | Camera position. |
+| type | [CameraType](#cameratype) | Yes | Camera type. |
+| callback | AsyncCallback<[CameraInput](#camerainput)\> | Yes | Callback used to return the **CameraInput** instance.|
**Example**
@@ -281,28 +258,26 @@ cameraManager.createCameraInput(cameraPosition, cameraType, (err, cameraInput) =
})
```
-### createCameraInput(position: CameraPosition, type: CameraType): Promise;
-
-**System Capabilities:**
+### createCameraInput
-SystemCapability.Multimedia.Camera.Core
+createCameraInput(position: CameraPosition, type: CameraType): Promise
-**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**
-| Name | Type | Mandatory | Description |
-|----------|----------------------------|-----------|----------------------------------------|
-| position | CameraPosition | Yes | Camera position |
-| type | CameraType | Yes | Camera type |
+| Name | Type | Mandatory| Description |
+| -------- | --------------------------------- | ---- | ---------- |
+| position | [CameraPosition](#cameraposition) | Yes | Camera position.|
+| type | [CameraType](#cameratype) | Yes | Camera type.|
-**Return values**
+**Return value**
-| Type | Description |
-|-------------------------|-------------------------------------------------|
-| Promise | Promise used to return the CameraInput instance |
+| Type | Description |
+| ------------------------------------- | ---------------------------------------- |
+| Promise<[CameraInput](#camerainput)\> | Promise used to return the **CameraInput** instance.|
**Example**
@@ -312,22 +287,20 @@ cameraManager.createCameraInput(cameraPosition, cameraType).then((cameraInput) =
})
```
-### on(type: 'cameraStatus', callback: Callback): void;
+### on('cameraStatus')
-**System Capabilities:**
+on(type: 'cameraStatus', callback: AsyncCallback): void
-SystemCapability.Multimedia.Camera.Core
+Listens for camera status changes. This API uses a callback to return the camera status changes.
-**Description**
-
-Listens for camera status changes. This method uses a callback to get camera status changes.
+**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
-| Name | Type | Mandatory | Description |
-| :------- | :--------------------- | :-------- | :--------------------------------------------------- |
-| type | string | Yes | Camera status event. |
-| callback | Callback | Yes | Callback used to get the camera status change. |
+| Name | Type | Mandatory| Description |
+| :------- | :---------------------------------------------------- | :--- | :--------------------------------------------------- |
+| type | string | Yes | Type of event to listen for. The value is fixed at **cameraStatus**, indicating the camera status change event.|
+| callback | AsyncCallback<[CameraStatusInfo](#camerastatusinfo)\> | Yes | Callback used to return the camera status change. |
**Example**
@@ -338,22 +311,20 @@ cameraManager.on('cameraStatus', (cameraStatusInfo) => {
})
```
-## 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*.
+## Camera
-**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 |
-|----------------|----------------|----------|------------------------|
-| cameraId | string | readonly | Camera ID |
-| cameraPosition | cameraPosition | readonly | Camera position |
-| cameraType | cameraType | readonly | Camera type |
-| connectionType | connectionType | readonly | Camera connection type |
+**Example**
```
async function getCameraInfo() {
@@ -368,41 +339,37 @@ async function getCameraInfo() {
```
-## 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
+## CameraStatusInfo
-**Fields**
+Describes the camera status information.
-| Name | Type | Description |
-|----------------|----------------|------------------|
-| camera | Camera | Camera object |
-| status | CameraStatus | Camera status |
+**System capability**: SystemCapability.Multimedia.Camera.Core
+| Name | Type | Description |
+| ------ | ----------------------------- | ---------- |
+| camera | [Camera](#camera) | Camera object. |
+| status | [CameraStatus](#camerastatus) | Camera status. |
-## CameraInput
-Implements a **CameraInput** instance.
+## CameraInput
-### getCameraId(callback: AsyncCallback\): 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\): 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**
-| Name | Type | Mandatory | Description |
-|----------|------------------------|-----------|---------------------------------------|
-| callback | AsyncCallback | Yes | Callback used to return the camera ID |
+| Name | Type | Mandatory | Description |
+| -------- | ---------------------- | ---- | -------------------------- |
+| callback | AsyncCallback | Yes | Callback used to return the camera ID. |
+
+**Example**
```
cameraInput.getCameraId((err, cameraId) => {
@@ -414,21 +381,19 @@ cameraInput.getCameraId((err, cameraId) => {
})
```
-### getCameraId(): Promise;
-
-**System Capabilities:**
+### getCameraId
-SystemCapability.Multimedia.Camera.Core
+getCameraId(): Promise
-**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 |
-|------------------------|--------------------------------------|
-| Promise | Promise used to return the camera ID |
+| Type | Description |
+| ---------------- | ----------------------------- |
+| Promise | Promise used to return the camera ID.|
**Example**
@@ -438,21 +403,20 @@ cameraInput.getCameraId().then((cameraId) => {
})
```
-### hasFlash(callback: AsyncCallback): void;
-**System Capabilities:**
+### hasFlash
-SystemCapability.Multimedia.Camera.Core
+hasFlash(callback: AsyncCallback): 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**
-| Name | Type | Mandatory | Description |
-|----------|-------------------------|-----------|----------------------------------------------------|
-| callback | AsyncCallback | Yes | Callback used to return the flash light support status |
+| Name | Type | Mandatory| Description |
+| -------- | ----------------------- | ---- | -------------------------------------- |
+| callback | AsyncCallback | Yes | Callback used to return the flash light support status. The value **true** means that the device has flash light.|
**Example**
@@ -466,21 +430,19 @@ cameraInput.hasFlash((err, status) => {
})
```
-### hasFlash(): Promise;
+### hasFlash
-**System Capabilities:**
+hasFlash(): Promise
-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 |
-|-----------------------|--------------------------------------------------------|
-| Promise | Promise used to return the flash light support status |
+| Type | Description |
+| ----------------- | ------------------------------------------------------- |
+| Promise | Promise used to return the flash light support status. The value **true** means that the device has flash light.|
**Example**
@@ -490,22 +452,20 @@ cameraInput.hasFlash().then((status) => {
})
```
-### isFlashModeSupported(flashMode: FlashMode, callback: AsyncCallback): void;
-
-**System Capabilities:**
+### isFlashModeSupported
-SystemCapability.Multimedia.Camera.Core
+isFlashModeSupported(flashMode: FlashMode, callback: AsyncCallback): 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**
-| Name | Type | Mandatory | Description |
-|-----------|------------------------|-----------|----------------------------------------------------|
-| flashMode | FlashMode | Yes | Flash mode |
-| callback | AsyncCallback | Yes | Callback used to return the device flash support status |
+| Name | Type | Mandatory| Description |
+| --------- | ----------------------- | ---- | ---------------------------------------- |
+| flashMode | [FlashMode](#flashmode) | Yes | Flash mode. |
+| callback | AsyncCallback | Yes | Callback used to return the flash mode support status. The value **true** means that the specified flash mode is supported.|
**Example**
@@ -519,27 +479,25 @@ cameraInput.isFlashModeSupported(flashMode, (err, status) => {
})
```
-### isFlashModeSupported(flashMode: FlashMode): Promise;
+### isFlashModeSupported
-**System Capabilities:**
+isFlashModeSupported(flashMode: FlashMode): Promise
-SystemCapability.Multimedia.Camera.Core
+Checks whether a specified flash mode is supported. This API uses a promise to return the result.
-**Description**
-
-Checks whether a specified flash mode is supported. This method uses a promise to return the result.
+**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
-| Name | Type | Mandatory | Description |
-|-----------|------------------------|-----------|----------------------------------------------------|
-| flashMode | FlashMode | Yes | Flash mode |
+| Name | Type | Mandatory| Description |
+| --------- | ----------------------- | ---- | ---------------- |
+| flashMode | [FlashMode](#flashmode) | Yes | Flash mode.|
-**Return values**
+**Return value**
-| Type | Description |
-|-----------------------|---------------------------------------------------|
-| Promise | Promise used to return flash mode support status. |
+| Type | Description |
+| ----------------- | ------------------------------------------------------------ |
+| Promise | Promise used to return the flash mode support status. The value **true** means that the specified flash mode is supported.|
**Example**
@@ -549,24 +507,25 @@ cameraInput.isFlashModeSupported(flashMode).then((status) => {
})
```
-### setFlashMode(flashMode: FlashMode, callback: AsyncCallback): void;
+### setFlashMode
-**System Capabilities:**
+setFlashMode(flashMode: FlashMode, callback: AsyncCallback): 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 (hasFlash method) and flash mode support (isFlashModeSupported method);
+**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
-| Name | Type | Mandatory | Description |
-|-----------|------------------------|-----------|----------------------------------------------------|
-| flashMode | FlashMode | Yes | Flash mode |
-| callback | AsyncCallback | Yes | Callback used to return the result |
+| Name | Type | Mandatory| Description |
+| --------- | ----------------------- | ---- | ------------------------ |
+| flashMode | [FlashMode](#flashmode) | Yes | Flash mode. |
+| callback | AsyncCallback | Yes | Callback used to return the result.|
**Example**
@@ -580,29 +539,30 @@ cameraInput.setFlashMode(flashMode, (err) => {
})
```
-### setFlashMode(flashMode: FlashMode): Promise;
+### setFlashMode
-**System Capabilities:**
+setFlashMode(flashMode: FlashMode): Promise
-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 (hasFlash method) and flash mode support (isFlashModeSupported method);
+**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
-| Name | Type | Mandatory | Description |
-|-----------|------------------------|-----------|----------------------------------------------------|
-| flashMode | FlashMode | Yes | Flash mode |
+| Name | Type | Mandatory| Description |
+| --------- | ----------------------- | ---- | ---------------- |
+| flashMode | [FlashMode](#flashmode) | Yes | Flash mode.|
-**Return values**
+**Return value**
-| Type | Description |
-|-----------------------|-----------------------------------------|
-| Promise | Promise used to return the result |
+| Type | Description |
+| -------------- | --------------------------- |
+| Promise | Promise used to return the result.|
**Example**
@@ -612,21 +572,19 @@ cameraInput.setFlashMode(flashMode).then(() => {
})
```
-### getFlashMode(callback: AsyncCallback): void;
+### getFlashMode
-**System Capabilities:**
+getFlashMode(callback: AsyncCallback): void
-SystemCapability.Multimedia.Camera.Core
+Obtains the current flash mode. This API uses an asynchronous callback to return the result.
-**Description**
-
-Gets current flash mode. This method uses an asynchronous callback to return the result.
+**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
-| Name | Type | Mandatory | Description |
-|-----------|---------------------------|-----------|------------------------------------------------|
-| callback | AsyncCallback | Yes | Callback used to return the current flash mode |
+| Name | Type | Mandatory| Description |
+| -------- | --------------------------------------- | ---- | ---------------------------------------- |
+| callback | AsyncCallback<[FlashMode](#flashmode)\> | Yes | Callback used to return the current flash mode.|
**Example**
@@ -640,21 +598,19 @@ cameraInput.getFlashMode((err, flashMode) => {
})
```
-### getFlashMode(): Promise;
-
-**System Capabilities:**
+### getFlashMode
-SystemCapability.Multimedia.Camera.Core
+getFlashMode(): Promise
-**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 |
-|-----------------------|---------------------------------------------------|
-| Promise | Promise used to return the flash mode |
+| Type | Description |
+| --------------------------------- | --------------------------------------- |
+| Promise<[FlashMode](#flashmode)\> | Promise used to return the current flash mode.|
**Example**
@@ -664,22 +620,20 @@ cameraInput.getFlashMode().then((flashMode) => {
})
```
-### isFocusModeSupported(afMode: FocusMode, callback: AsyncCallback): void;
+### isFocusModeSupported
-**System Capabilities:**
+isFocusModeSupported(afMode: FocusMode, callback: AsyncCallback): void
-SystemCapability.Multimedia.Camera.Core
+Checks whether a specified focus mode is supported. This API uses an asynchronous callback to return the result.
-**Description**
-
-Checks whether a specified focus mode is supported. This method uses an asynchronous callback to return the result.
+**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
-| Name | Type | Mandatory | Description |
-|-----------|------------------------|-----------|----------------------------------------------------|
-| afMode | FocusMode | Yes | Focus mode |
-| callback | AsyncCallback | Yes | Callback used to return the device focus support status |
+| Name | Type | Mandatory| Description |
+| -------- | ----------------------- | ---- | -------------------------------------- |
+| afMode | [FocusMode](#focusmode) | Yes | Focus mode. |
+| callback | AsyncCallback | Yes | Callback used to return the focus mode support status. The value **true** means that the specified focus mode is supported.|
**Example**
@@ -693,27 +647,25 @@ cameraInput.isFocusModeSupported(afMode, (err, status) => {
})
```
-### isFocusModeSupported(afMode: FocusMode): Promise