From 092e6f35c355eb6157b8aabad25f02be83304147 Mon Sep 17 00:00:00 2001 From: wusongqing Date: Thu, 12 May 2022 17:20:14 +0800 Subject: [PATCH] updated docs Signed-off-by: wusongqing --- en/application-dev/media/audio-playback.md | 310 +-- en/application-dev/media/audio-recorder.md | 257 +- en/application-dev/media/video-playback.md | 711 +++--- .../reference/apis/js-apis-audio.md | 2263 +++++++++-------- .../reference/apis/js-apis-camera.md | 2012 +++++++-------- .../reference/apis/js-apis-image.md | 30 +- .../reference/apis/js-apis-media.md | 881 ++++++- 7 files changed, 3474 insertions(+), 2990 deletions(-) diff --git a/en/application-dev/media/audio-playback.md b/en/application-dev/media/audio-playback.md index 2124319f5e..085506f3c5 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 56f72dc5a4..cd8d8ee0d9 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 946e975a2b..49f0f08442 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 4ae4ecd6a7..d1ac497ef7 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 6495d3cd2e..17de0ce539 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 -> ![icon-note.gif](public_sys-resources/icon-note.gif) **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; - -**System Capabilities:** +### isFocusModeSupported -SystemCapability.Multimedia.Camera.Core +isFocusModeSupported(afMode: FocusMode): Promise -**Description** +Checks whether a specified focus mode is supported. This API uses a promise to return the result. -Checks whether a specified focus mode is supported. This method uses a promise to return the result. +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -|-----------|----------------------------------------|-----------|-------------| -| afMode | FocusMode | Yes | Focus mode | +| Name | Type | Mandatory| Description | +| ------ | ----------------------- | ---- | ---------------- | +| afMode | [FocusMode](#focusmode) | Yes | Focus mode.| -**Return values** +**Return value** -| Type | Description | -|-----------------------|---------------------------------------------------| -| Promise | Promise used to return the focus mode support status. | +| Type | Description | +| ----------------- | ----------------------------------------------------------- | +| Promise | Promise used to return the flash mode support status. The value **true** means that the specified focus mode is supported.| **Example** @@ -723,24 +675,22 @@ cameraInput.isFocusModeSupported(afMode).then((status) => { }) ``` -### setFocusMode(afMode: FocusMode, callback: AsyncCallback): void; +### setFocusMode -**System Capabilities:** +setFocusMode(afMode: FocusMode, callback: AsyncCallback): void -SystemCapability.Multimedia.Camera.Core +Sets the focus mode. This API uses an asynchronous callback to return the result. -**Description** +Before setting the focus mode, use **[isFocusModeSupported](#isfocusmodesupported)** to check whether the focus mode is supported. -Sets focus mode. This method uses an asynchronous callback to return the result. - -Note: Before setting the focus mode, check focus mode support (isFocusModeSupported method); +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -|-----------|------------------------|-----------|------------------------------------| -| afMode | FocusMode | Yes | Focus mode | -| callback | AsyncCallback | Yes | Callback used to return the result | +| Name | Type | Mandatory| Description | +| -------- | ----------------------- | ---- | ------------------------ | +| afMode | [FocusMode](#focusmode) | Yes | Focus mode. | +| callback | AsyncCallback | Yes | Callback used to return the result.| **Example** @@ -754,29 +704,27 @@ cameraInput.setFocusMode(afMode, (err) => { }) ``` -### setFocusMode(afMode: FocusMode): Promise; - -**System Capabilities:** +### setFocusMode -SystemCapability.Multimedia.Camera.Core +setFocusMode(afMode: FocusMode): Promise -**Description** +Sets the focus mode. This API uses a promise to return the result. -Sets focus mode. This method uses a promise to return the result. +Before setting the focus mode, use **[isFocusModeSupported](#isfocusmodesupported)** to check whether the focus mode is supported. -Note: Before setting the focus mode, check focus mode support (isFocusModeSupported method); +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -|-----------|-----------------------------------------|-----------|-------------| -| afMode | FocusMode | Yes | Focus mode | +| Name | Type | Mandatory| Description | +| ------ | ----------------------- | ---- | ---------------- | +| afMode | [FocusMode](#focusmode) | Yes | Focus mode.| -**Return values** +**Return value** -| Type | Description | -|-----------------------|-----------------------------------------| -| Promise | Promise used to return the result | +| Type | Description | +| -------------- | --------------------------- | +| Promise | Promise used to return the result.| **Example** @@ -786,21 +734,19 @@ cameraInput.setFocusMode(afMode).then(() => { }) ``` -### getFocusMode(callback: AsyncCallback): void; - -**System Capabilities:** +### getFocusMode -SystemCapability.Multimedia.Camera.Core +getFocusMode(callback: AsyncCallback): void -**Description** +Obtains the current focus mode. This API uses an asynchronous callback to return the result. -Gets the current focus mode. This method uses an asynchronous callback to return the result. +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -|-----------|---------------------------|-----------|------------------------------------------------| -| callback | AsyncCallback | Yes | Callback used to return the current focus mode | +| Name | Type | Mandatory| Description | +| -------- | --------------------------------------- | ---- | -------------------------------------- | +| callback | AsyncCallback<[FocusMode](#focusmode)\> | Yes | Callback used to return the current focus mode.| **Example** @@ -814,21 +760,19 @@ cameraInput.getFocusMode((err, afMode) => { }) ``` -### getFocusMode(): Promise; +### getFocusMode -**System Capabilities:** +getFocusMode(): Promise -SystemCapability.Multimedia.Camera.Core +Obtains the current focus mode. This API uses a promise to return the result. -**Description** +**System capability**: SystemCapability.Multimedia.Camera.Core -Gets the current focus mode. This method uses a promise to return the result. +**Return value** -**Return values** - -| Type | Description | -|-----------------------|---------------------------------------------------| -| Promise | Promise used to return the focus mode | +| Type | Description | +| ------------------- | ------------------------------------- | +| Promise | Promise used to return the current focus mode.| **Example** @@ -838,21 +782,19 @@ cameraInput.getFocusMode().then((afMode) => { }) ``` -### getZoomRatioRange\(callback: AsyncCallback\>\): void; - -**System Capabilities:** +### getZoomRatioRange -SystemCapability.Multimedia.Camera.Core +getZoomRatioRange\(callback: AsyncCallback\>\): void -**Description** +Obtains the zoom ratio range. This API uses an asynchronous callback to return the result. -Gets the zoom ratios of all zoom values. This method uses an asynchronous callback to return the result. +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -|----------|--------------------------------|-----------|-------------------------------------------------| -| callback | AsyncCallback\> | Yes | Callback used to return the zoom ratio range | +| Name | Type | Mandatory| Description | +| -------- | ------------------------------ | ---- | ------------------------ | +| callback | AsyncCallback\> | Yes | Callback used to return the zoom ratio range.| **Example** @@ -866,21 +808,19 @@ cameraInput.getZoomRatioRange((err, zoomRatioRange) => { }) ``` -### getZoomRatioRange\(\): Promise\>; +### getZoomRatioRange -**System Capabilities:** +getZoomRatioRange\(\): Promise\> -SystemCapability.Multimedia.Camera.Core +Obtains the zoom ratio range. This API uses a promise to return the result. -**Description** +**System capability**: SystemCapability.Multimedia.Camera.Core -Gets the zoom ratios of all zoom values. This method uses a promise to return the result. +**Return value** -**Return values** - -| Type | Description | -|------------------------|---------------------------------------------| -| Promise\> | Promise used to return the zoom ratio range | +| Type | Description | +| ------------------------ | ------------------------------------------- | +| Promise\> | Promise used to return the zoom ratio range.| **Example** @@ -890,22 +830,20 @@ cameraInput.getZoomRatioRange().then((zoomRatioRange) => { }) ``` -### setZoomRatio(zoomRatio: number, callback: AsyncCallback): void; - -**System Capabilities:** +### setZoomRatio -SystemCapability.Multimedia.Camera.Core +setZoomRatio(zoomRatio: number, callback: AsyncCallback): void -**Description** +Sets a zoom ratio. This API uses an asynchronous callback to return the result. -Sets a zoom ratio. This method uses an asynchronous callback to return the result. +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -|-----------|------------------------|-----------|------------------------------------| -| zoomRatio | number | Yes | Zoom ratio | -| callback | AsyncCallback | Yes | Callback used to return the result | +| Name | Type | Mandatory| Description | +| --------- | -------------------- | ---- | ------------------------ | +| zoomRatio | number | Yes | Zoom ratio to set. | +| callback | AsyncCallback | Yes | Callback used to return the result.| **Example** @@ -919,27 +857,25 @@ cameraInput.setZoomRatio(zoomRatio, (err) => { }) ``` -### setZoomRatio(zoomRatio: number): Promise; +### setZoomRatio -**System Capabilities:** +setZoomRatio(zoomRatio: number): Promise -SystemCapability.Multimedia.Camera.Core +Sets a zoom ratio. This API uses a promise to return the result. -**Description** - -Sets a zoom ratio. This method uses a promise to return the result. +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -|-----------|----------|-----------|-------------| -| zoomRatio | number | Yes | zoom ratio | +| Name | Type | Mandatory| Description | +| --------- | ------ | ---- | ------------ | +| zoomRatio | number | Yes | Zoom ratio to set.| -**Return values** +**Return value** -| Type | Description | -|-----------------------|-----------------------------------------| -| Promise | Promise used to return the result | +| Type | Description | +| -------------- | --------------------------- | +| Promise | Promise used to return the result.| **Example** @@ -949,21 +885,19 @@ cameraInput.setZoomRatio(zoomRatio).then(() => { }) ``` -### getZoomRatio(callback: AsyncCallback): void; +### getZoomRatio -**System Capabilities:** +getZoomRatio(callback: AsyncCallback): void -SystemCapability.Multimedia.Camera.Core +Obtains the current zoom ratio. This API uses an asynchronous callback to return the result. -**Description** - -Gets current zoom ratio value. 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 zoom ratio value | +| Name | Type | Mandatory| Description | +| -------- | ---------------------- | ---- | ------------------------ | +| callback | AsyncCallback | Yes | Callback used to return the current zoom ratio.| **Example** @@ -977,21 +911,19 @@ cameraInput.getZoomRatio((err, zoomRatio) => { }) ``` -### getZoomRatio(): Promise; - -**System Capabilities:** +### getZoomRatio -SystemCapability.Multimedia.Camera.Core +getZoomRatio(): Promise -**Description** +Obtains the current zoom ratio. This API uses a promise to return the result. -Gets current zoom ratio value. This method uses a promise to return the result. +**System capability**: SystemCapability.Multimedia.Camera.Core -**Return values** +**Return value** -| Type | Description | -|-----------------------|---------------------------------------------------| -| Promise | Promise used to return the zoom ratio vaule | +| Type | Description | +| ---------------- | --------------------------- | +| Promise | Promise used to return the current zoom ratio.| **Example** @@ -1001,26 +933,24 @@ cameraInput.getZoomRatio().then((zoomRatio) => { }) ``` -### release\(callback: AsyncCallback\): void; +### release -**System Capabilities:** +release\(callback: AsyncCallback\): void -SystemCapability.Multimedia.Camera.Core +Releases this **CameraInput** instance. This API uses an asynchronous callback to return the result. -**Description** - -Releases this **CameraInput** instance. 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 result | +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ------------------------ | +| callback | AsyncCallback | Yes | Callback used to return the result.| **Example** ``` -cameraInput.release((err) => { +camera.release((err) => { if (err) { console.error('Failed to release the CameraInput instance ${err.message}'); return; @@ -1029,21 +959,19 @@ cameraInput.release((err) => { }); ``` -### release(): Promise; - -**System Capabilities:** +### release -SystemCapability.Multimedia.Camera.Core +release(): Promise -**Description** +Releases this **CameraInput** instance. This API uses a promise to return the result. -Releases this **CameraInput** instance. This method uses a promise to return the result. +**System capability**: SystemCapability.Multimedia.Camera.Core -**Return values** +**Return value** -| Type | Description | -|----------------|---------------------------------------------| -| Promise | Promise used to return the result | +| Type | Description | +| -------------- | --------------------------- | +| Promise | Promise used to return the result.| **Example** @@ -1053,22 +981,20 @@ cameraInput.release().then(() => { }) ``` -### on(type: 'focusStateChange', callback: Callback): void; - -**System Capabilities:** +### on('focusStateChange') -SystemCapability.Multimedia.Camera.Core +on(type: 'focusStateChange', callback: AsyncCallback): void -**Description** +Listens for focus state changes. This API uses a callback to return the focus state changes. -Listens for focus state changes. This method uses a callback to get focus state changes. +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -| :------- | :--------------------- | :-------- | :-----------------------------------------------| -| type | string | Yes | Name of the event to listen for. | -| callback | Callback | Yes | Callback used to get the focus state change. | +| Name | Type | Mandatory| Description | +| :------- | :---------------------------------------- | :--- | :------------------------------------------------------- | +| type | string | Yes | Type of event to listen for. The value is fixed at **focusStateChange**, indicating the focus state change event.| +| callback | AsyncCallback<[FocusState](#focusstate)\> | Yes | Callback used to return the focus state change. | **Example** @@ -1078,22 +1004,20 @@ cameraInput.on('focusStateChange', (focusState) => { }) ``` -### on(type: 'error', callback: Callback): void; +### on('error') -**System Capabilities:** +on(type: 'error', callback: ErrorCallback): void -SystemCapability.Multimedia.Camera.Core +Listens for **CameraInput** errors. This API uses a callback to return the errors. -**Description** - -Listens for **CameraInput** errors. This method uses a callback to get errors. +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -| :------- | :--------------------- | :-------- | :-----------------------------------------------| -| type | string | Yes | Camera input error event. | -| callback | Callback | Yes | Callback used to get the camera input errors. | +| Name | Type | Mandatory| Description | +| :------- | :------------------------------- | :--- | :---------------------------------------------- | +| type | string | Yes | Type of event to listen for. The value is fixed at **error**, indicating the camera input error event.| +| callback | ErrorCallback | Yes | Callback used to return the result. | **Example** @@ -1103,57 +1027,64 @@ cameraInput.on('error', (cameraInputError) => { }) ``` -## FlashMode -Enumerates the flash modes. +## FlashMode -**System Capabilities:** +Enumerates the flash modes. -SystemCapability.Multimedia.Camera.Core +**System capability**: SystemCapability.Multimedia.Camera.Core -| Name | Default value | Description | -|------------------------|---------------|------------------------| -| FLASH_MODE_CLOSE | 0 | Flash mode close | -| FLASH_MODE_OPEN | 1 | Flash mode open | -| FLASH_MODE_AUTO | 2 | Flash mode auto | -| FLASH_MODE_ALWAYS_OPEN | 3 | Flash mode always open | +| Name | Default Value| Description | +| ---------------------- | ------ | ------------ | +| FLASH_MODE_CLOSE | 0 | The flash is off.| +| FLASH_MODE_OPEN | 1 | The flash is on.| +| FLASH_MODE_AUTO | 2 | The flash mode is auto, indicating that the flash fires automatically depending on the shooting conditions.| +| FLASH_MODE_ALWAYS_OPEN | 3 | The flash is steady on.| -## FocusMode +## FocusMode Enumerates the focus modes. -**System Capabilities:** +**System capability**: SystemCapability.Multimedia.Camera.Core + +| Name | Default Value| Description | +| -------------------------- | ------ | ------------------ | +| FOCUS_MODE_MANUAL | 0 | Manual focus. | +| FOCUS_MODE_CONTINUOUS_AUTO | 1 | Continuous auto focus.| +| FOCUS_MODE_AUTO | 2 | Auto focus. | +| FOCUS_MODE_LOCKED | 3 | Locked focus. | -SystemCapability.Multimedia.Camera.Core +## FocusState -| Name | Default value | Description | -|----------------------------|---------------|----------------------------| -| FOCUS_MODE_MANUAL | 0 | Focus mode manual | -| FOCUS_MODE_CONTINUOUS_AUTO | 1 | Focus mode continuous auto | -| FOCUS_MODE_AUTO | 2 | Focus mode auto | -| FOCUS_MODE_LOCKED | 3 | Focus mode locked | +Enumerates the focus states. -## createCaptureSession\(context: Context, callback: AsyncCallback\): void; +**System capability**: SystemCapability.Multimedia.Camera.Core -**System Capabilities:** +| Name | Default Value| Description | +| --------------------- | ------ | ------------ | +| FOCUS_STATE_SCAN | 0 | Scanning. | +| FOCUS_STATE_FOCUSED | 1 | Focused.| +| FOCUS_STATE_UNFOCUSED | 2 | Unfocused.| -SystemCapability.Multimedia.Camera.Core +## camera.createCaptureSession -**Description** +createCaptureSession\(context: Context, callback: AsyncCallback\): void -Creates a **CaptureSession** instance. This method uses an asynchronous callback to return the instance. +Creates a **CaptureSession** instance. This API uses an asynchronous callback to return the instance. + +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -|----------|--------------------------------|-----------|-----------------------------------------------------| -| context | Context | Yes | Application context | -| callback | AsyncCallback | Yes | Callback used to return the CaptureSession instance | +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------- | ---- | -------------------------------------- | +| context | Context | Yes | Application context. | +| callback | AsyncCallback<[CaptureSession](#capturesession)\> | Yes | Callback used to return the **CaptureSession** instance.| **Example** ``` -captureSession.createCaptureSession((context), (err, captureSession) => { +camera.createCaptureSession((context), (err, captureSession) => { if (err) { console.error('Failed to create the CaptureSession instance. ${err.message}'); return; @@ -1162,55 +1093,51 @@ captureSession.createCaptureSession((context), (err, captureSession) => { }); ``` -## createCaptureSession(context: Context\): Promise; - -**System Capabilities:** +## camera.createCaptureSession -SystemCapability.Multimedia.Camera.Core +createCaptureSession(context: Context\): Promise; -**Description** +Creates a **CaptureSession** instance. This API uses a promise to return the instance. -Creates a **CaptureSession** instance. This method uses a promise to return the instance. +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| 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 CaptureSession instance. | +| Type | Description | +| ------------------------------------------- | ----------------------------------------- | +| Promise<[CaptureSession](#capturesession)\> | Promise used to return the **CaptureSession** instance.| **Example** ``` -captureSession.createCaptureSession(context).then((captureSession) => { +camera.createCaptureSession(context).then((captureSession) => { console.log('Promise returned with the CaptureSession instance'); }) ``` -## CaptureSession +## CaptureSession Implements session capture. -### beginConfig\(callback: AsyncCallback\): void; +### beginConfig -**System Capabilities:** +beginConfig\(callback: AsyncCallback\): void -SystemCapability.Multimedia.Camera.Core +Starts configuration for this **CaptureSession** instance. This API uses an asynchronous callback to return the result. -**Description** - -Starts configuration for this CaptureSession instance. 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 result | +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ------------------------ | +| callback | AsyncCallback | Yes | Callback used to return the result.| **Example** @@ -1224,21 +1151,19 @@ captureSession.beginConfig((err) => { }); ``` -### beginConfig\(\): Promise; - -**System Capabilities:** +### beginConfig -SystemCapability.Multimedia.Camera.Core +beginConfig\(\): Promise -**Description** +Starts configuration for this **CaptureSession** instance. This API uses a promise to return the result. -Starts configuration for this CaptureSession instance. This method uses a promise to return the result. +**System capability**: SystemCapability.Multimedia.Camera.Core -**Return values** +**Return value** -| Type | Description | -|---------------|---------------------------------------------| -| Promise | Promise used to return the result | +| Type | Description | +| -------------- | --------------------------- | +| Promise | Promise used to return the result.| **Example** @@ -1249,21 +1174,19 @@ captureSession.beginConfig().then(() => { }) ``` -### commitConfig\(callback: AsyncCallback\): void; +### commitConfig -**System Capabilities:** +commitConfig\(callback: AsyncCallback\): void -SystemCapability.Multimedia.Camera.Core +Commits the configuration for this **CaptureSession** instance. This API uses an asynchronous callback to return the result. -**Description** - -Commits the configuration for this CaptureSession instance. 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 result | +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ------------------------ | +| callback | AsyncCallback | Yes | Callback used to return the result.| **Example** @@ -1277,21 +1200,19 @@ captureSession.commitConfig((err) => { }); ``` -### commitConfig\(\): Promise; - -**System Capabilities:** +### commitConfig -SystemCapability.Multimedia.Camera.Core +commitConfig\(\): Promise -**Description** +Commits the configuration for this **CaptureSession** instance. This API uses a promise to return the result. -Commits the configuration for this CaptureSession instance. This method uses a promise to return the result. +**System capability**: SystemCapability.Multimedia.Camera.Core -**Return values** +**Return value** -| Type | Description | -|---------------|---------------------------------------------| -| Promise | Promise used to return the result | +| Type | Description | +| -------------- | --------------------------- | +| Promise | Promise used to return the result.| **Example** @@ -1301,22 +1222,20 @@ captureSession.commitConfig().then(() => { }) ``` -### addInput\(cameraInput: CameraInput, callback: AsyncCallback\): void; - -**System Capabilities:** +### addInput -SystemCapability.Multimedia.Camera.Core +addInput\(cameraInput: CameraInput, callback: AsyncCallback\): void -**Description** +Adds a **CameraInput** instance to this **CaptureSession** instance. This API uses an asynchronous callback to return the result. -Add a CameraInput instance to this CaptureSession instance. This method uses an asynchronous callback to return the result. +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -|-------------|----------------------|-----------|---------------------------------------------| -| cameraInput | CameraInput | Yes | CameraInput instance to add | -| callback | AsyncCallback | Yes | Callback used to return the result | +| Name | Type | Mandatory| Description | +| ----------- | --------------------------- | ---- | --------------------------- | +| cameraInput | [CameraInput](#camerainput) | Yes | **CameraInput** instance to add.| +| callback | AsyncCallback | Yes | Callback used to return the result. | **Example** @@ -1330,27 +1249,25 @@ captureSession.addInput(cameraInput, (err) => { }); ``` -### addInput\(cameraInput: CameraInput\): Promise; +### addInput -**System Capabilities:** +addInput\(cameraInput: CameraInput\): Promise -SystemCapability.Multimedia.Camera.Core +Adds a **CameraInput** instance to this **CaptureSession** instance. This API uses a promise to return the result. -**Description** - -Add a CameraInput instance to this CaptureSession instance. This method uses a promise to return the result. +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -|-------------|---------------------|-----------|-------------------------------| -| cameraInput | CameraInput | Yes | CameraInput instance to add | +| Name | Type | Mandatory| Description | +| ----------- | --------------------------- | ---- | --------------------------- | +| cameraInput | [CameraInput](#camerainput) | Yes | **CameraInput** instance to add.| -**Return values** +**Return value** -| Type | Description | -|----------------|------------------------------------| -| Promise | Promise used to return the result | +| Type | Description | +| -------------- | --------------------------- | +| Promise | Promise used to return the result.| **Example** @@ -1360,22 +1277,20 @@ captureSession.addInput(cameraInput).then(() => { }) ``` -### addOutput\(previewOutput: PreviewOutput, callback: AsyncCallback\): void; +### addOutput -**System Capabilities:** +addOutput\(previewOutput: PreviewOutput, callback: AsyncCallback\): void -SystemCapability.Multimedia.Camera.Core +Adds a **PreviewOutput** instance to this **CaptureSession** instance. This API uses an asynchronous callback to return the result. -**Description** - -Add a PreviewOutput instance to this CaptureSession instance. This method uses an asynchronous callback to return the result. +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -|---------------|----------------------|-----------|-------------------------------------| -| previewOutput | PreviewOutput | Yes | PreviewOutput instance to add | -| callback | AsyncCallback | Yes | Callback used to return the result | +| Name | Type | Mandatory| Description | +| ------------- | ------------------------------- | ---- | ----------------------------- | +| previewOutput | [PreviewOutput](#previewoutput) | Yes | **PreviewOutput** instance to add.| +| callback | AsyncCallback | Yes | Callback used to return the result. | **Example** @@ -1389,27 +1304,25 @@ captureSession.addOutput(previewOutput, (err) => { }); ``` -### addOutput\(previewOutput: PreviewOutput\): Promise; - -**System Capabilities:** +### addOutput -SystemCapability.Multimedia.Camera.Core +addOutput\(previewOutput: PreviewOutput\): Promise -**Description** +Adds a **PreviewOutput** instance to this **CaptureSession** instance. This API uses a promise to return the result. -Add a PreviewOutput instance to this CaptureSession instance. This method uses a promise to return the result. +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -|---------------|---------------------|-----------|--------------------------------| -| previewOutput | PreviewOutput | Yes | PreviewOutput instance to add | +| Name | Type | Mandatory| Description | +| ------------- | ------------------------------- | ---- | ----------------------------- | +| previewOutput | [PreviewOutput](#previewoutput) | Yes | **PreviewOutput** instance to add.| -**Return values** +**Return value** -| Type | Description | -|----------------|-----------------------------------| -| Promise | Promise used to return the result | +| Type | Description | +| -------------- | --------------------------- | +| Promise | Promise used to return the result.| **Example** @@ -1419,22 +1332,20 @@ captureSession.addOutput(previewOutput).then(() => { }) ``` -### addOutput\(photoOutput: PhotoOutput, callback: AsyncCallback\): void; - -**System Capabilities:** +### addOutput -SystemCapability.Multimedia.Camera.Core +addOutput\(photoOutput: PhotoOutput, callback: AsyncCallback\): void -**Description** +Adds a **PhotoOutput** instance to this **CaptureSession** instance. This API uses an asynchronous callback to return the result. -Add a PhotoOutput instance to this CaptureSession instance. This method uses an asynchronous callback to return the result. +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -|---------------|---------------------|-----------|-------------------------------------| -| photoOutput | PhotoOutput | Yes | PhotoOutput instance to add | -| callback | AsyncCallback | Yes | Callback used to return the result | +| Name | Type | Mandatory| Description | +| ----------- | --------------------------- | ---- | --------------------------- | +| photoOutput | [PhotoOutput](#photooutput) | Yes | **PhotoOutput** instance to add.| +| callback | AsyncCallback | Yes | Callback used to return the result. | **Example** @@ -1448,27 +1359,25 @@ captureSession.addOutput(photoOutput, (err) => { }); ``` -### addOutput\(photoOutput: PhotoOutput\): Promise; +### addOutput -**System Capabilities:** +addOutput\(photoOutput: PhotoOutput\): Promise -SystemCapability.Multimedia.Camera.Core +Adds a **PhotoOutput** instance to this **CaptureSession** instance. This API uses a promise to return the result. -**Description** - -Add a PhotoOutput instance to this CaptureSession instance. This method uses a promise to return the result. +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -|---------------|---------------------|-----------|--------------------------------| -| photoOutput | PhotoOutput | Yes | PhotoOutput instance to add | +| Name | Type | Mandatory| Description | +| ----------- | --------------------------- | ---- | --------------------------- | +| photoOutput | [PhotoOutput](#photooutput) | Yes | **PhotoOutput** instance to add.| -**Return values** +**Return value** | Type | Description | -|---------------|-----------------------------------| -| Promise | Promise used to return the result | +| -------------- | --------------------------- | +| Promise\ | Promise used to return the result.| **Example** @@ -1478,22 +1387,20 @@ captureSession.addOutput(photoOutput).then(() => { }) ``` -### addOutput\(videoOutput: VideoOutput, callback: AsyncCallback\): void; - -**System Capabilities:** +### addOutput -SystemCapability.Multimedia.Camera.Core +addOutput\(videoOutput: VideoOutput, callback: AsyncCallback\): void -**Description** +Adds a **VideoOutput** instance to this **CaptureSession** instance. This API uses an asynchronous callback to return the result. -Add a VideoOutput instance to this CaptureSession instance. This method uses an asynchronous callback to return the result. +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -|---------------|---------------------|-----------|-------------------------------------| -| videoOutput | VideoOutput | Yes | VideoOutput instance to add | -| callback | AsyncCallback | Yes | Callback used to return the result | +| Name | Type | Mandatory| Description | +| ----------- | --------------------------- | ---- | --------------------------- | +| videoOutput | [VideoOutput](#videooutput) | Yes | **VideoOutput** instance to add.| +| callback | AsyncCallback | Yes | Callback used to return the result. | **Example** @@ -1507,27 +1414,25 @@ captureSession.addOutput(videoOutput, (err) => { }); ``` -### addOutput\(videoOutput: VideoOutput\): Promise; +### addOutput -**System Capabilities:** +addOutput\(videoOutput: VideoOutput\): Promise -SystemCapability.Multimedia.Camera.Core +Adds a **VideoOutput** instance to this **CaptureSession** instance. This API uses a promise to return the result. -**Description** - -Add a VideoOutput instance to this CaptureSession instance. This method uses a promise to return the result. +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -|---------------|---------------------|-----------|--------------------------------| -| videoOutput | VideoOutput | Yes | VideoOutput instance to add | +| Name | Type | Mandatory| Description | +| ----------- | --------------------------- | ---- | --------------------------- | +| videoOutput | [VideoOutput](#videooutput) | Yes | **VideoOutput** instance to add.| -**Return values** +**Return value** -| Type | Description | -|----------------|-----------------------------------| -| Promise | Promise used to return the result | +| Type | Description | +| -------------- | --------------------------- | +| Promise\ | Promise used to return the result.| **Example** @@ -1537,22 +1442,20 @@ captureSession.addOutput(videoOutput).then(() => { }) ``` -### removeInput\(cameraInput: CameraInput, callback: AsyncCallback\): void; +### removeInput -**System Capabilities:** +removeInput\(cameraInput: CameraInput, callback: AsyncCallback\): void -SystemCapability.Multimedia.Camera.Core +Removes a **CameraInput** instance from this **CaptureSession** instance. This API uses an asynchronous callback to return the result. -**Description** - -Removes a **CameraInput** instance from this **CaptureSession** instance. This method uses an asynchronous callback to return the result. +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -|-------------|----------------------|-----------|------------------------------------| -| cameraInput | CameraInput | Yes | CameraInput instance to remove | -| callback | AsyncCallback | Yes | Callback used to return the result | +| Name | Type | Mandatory| Description | +| ----------- | --------------------------- | ---- | --------------------------- | +| cameraInput | [CameraInput](#camerainput) | Yes | **CameraInput** instance to remove.| +| callback | AsyncCallback | Yes | Callback used to return the result. | **Example** @@ -1566,27 +1469,25 @@ captureSession.removeInput(cameraInput, (err) => { }); ``` -### removeInput\(cameraInput: CameraInput\): Promise; - -**System Capabilities:** +### removeInput -SystemCapability.Multimedia.Camera.Core +removeInput\(cameraInput: CameraInput\): Promise -**Description** +Removes a **CameraInput** instance from this **CaptureSession** instance. This API uses a promise to return the result. -Removes a **CameraInput** instance from this **CaptureSession** instance. This method uses a promise to return the result. +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -|-------------|---------------------|-----------|---------------------------------| -| cameraInput | CameraInput | Yes | CameraInput instance to remove | +| Name | Type | Mandatory| Description | +| ----------- | --------------------------- | ---- | --------------------------- | +| cameraInput | [CameraInput](#camerainput) | Yes | **CameraInput** instance to remove.| -**Return values** +**Return value** -| Type | Description | -|----------------|-----------------------------------| -| Promise | Promise used to return the result | +| Type | Description | +| -------------- | --------------------------- | +| Promise\ | Promise used to return the result.| **Example** @@ -1596,22 +1497,20 @@ captureSession.removeInput(cameraInput).then(() => { }) ``` -### removeOutput\(previewOutput: PreviewOutput, callback: AsyncCallback\): void; +### removeOutput -**System Capabilities:** +removeOutput\(previewOutput: PreviewOutput, callback: AsyncCallback\): void -SystemCapability.Multimedia.Camera.Core +Removes a **PreviewOutput** instance from this **CaptureSession** instance. This API uses an asynchronous callback to return the result. -**Description** - -Removes a **PreviewOutput** instance from this **CaptureSession** instance. This method uses an asynchronous callback to return the result. +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -|---------------|----------------------|-----------|------------------------------------| -| previewOutput | PreviewOutput | Yes | PreviewOutput instance to remove | -| callback | AsyncCallback | Yes | Callback used to return the result | +| Name | Type | Mandatory| Description | +| ------------- | ------------------------------- | ---- | ----------------------------- | +| previewOutput | [PreviewOutput](#previewoutput) | Yes | **PreviewOutput** instance to remove.| +| callback | AsyncCallback | Yes | Callback used to return the result. | **Example** @@ -1625,28 +1524,26 @@ captureSession.removeOutput(previewOutput, (err) => { }); ``` -### removeOutput(previewOutput: PreviewOutput): Promise; - -**System Capabilities:** +### removeOutput -SystemCapability.Multimedia.Camera.Core +removeOutput(previewOutput: PreviewOutput): Promise -**Description** +Removes a **PreviewOutput** instance from this **CaptureSession** instance. This API uses a promise to return the result. -Removes a **PreviewOutput** instance from this **CaptureSession** instance. This method uses a promise to return the result. +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -|---------------|---------------------|-----------|-----------------------------------| -| previewOutput | PreviewOutput | Yes | PreviewOutput instance to remove | +| Name | Type | Mandatory| Description | +| ------------- | ------------------------------- | ---- | ----------------------------- | +| previewOutput | [PreviewOutput](#previewoutput) | Yes | **PreviewOutput** instance to remove.| -**Return values** +**Return value** -| Type | Description | -|---------------|---------------------------------------------| -| Promise | Promise used to return the result | +| Type | Description | +| -------------- | --------------------------- | +| Promise | Promise used to return the result.| **Example** @@ -1657,22 +1554,20 @@ captureSession.removeOutput(previewOutput).then(() => { }) ``` -### removeOutput(photoOutput: PhotoOutput, callback: AsyncCallback): void; - -**System Capabilities:** +### removeOutput -SystemCapability.Multimedia.Camera.Core +removeOutput(photoOutput: PhotoOutput, callback: AsyncCallback): void -**Description** +Removes a **PhotoOutput** instance from this **CaptureSession** instance. This API uses an asynchronous callback to return the result. -Removes a **PhotoOutput** instance from this **CaptureSession** instance. This method uses an asynchronous callback to return the result. +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -|---------------|----------------------|-----------|------------------------------------| -| photoOutput | PhotoOutput | Yes | PhotoOutput instance to remove | -| callback | AsyncCallback | Yes | Callback used to return the result | +| Name | Type | Mandatory| Description | +| ----------- | --------------------------- | ---- | --------------------------- | +| photoOutput | [PhotoOutput](#photooutput) | Yes | **PhotoOutput** instance to remove.| +| callback | AsyncCallback | Yes | Callback used to return the result. | **Example** @@ -1686,28 +1581,26 @@ captureSession.removeOutput(photoOutput, (err) => { }); ``` -### removeOutput(photoOutput: PhotoOutput): Promise; +### removeOutput -**System Capabilities:** +removeOutput(photoOutput: PhotoOutput): Promise -SystemCapability.Multimedia.Camera.Core +Removes a **PhotoOutput** instance from this **CaptureSession** instance. This API uses a promise to return the result. -**Description** - -Removes a **PhotoOutput** instance from this **CaptureSession** instance. This method uses a promise to return the result. +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -|---------------|---------------------|-----------|---------------------------------| -| photoOutput | PhotoOutput | Yes | PhotoOutput instance to remove | +| Name | Type | Mandatory| Description | +| ----------- | --------------------------- | ---- | --------------------------- | +| photoOutput | [PhotoOutput](#photooutput) | Yes | **PhotoOutput** instance to remove.| -**Return values** +**Return value** -| Type | Description | -|---------------|------------------------------------| -| Promise | Promise used to return the result | +| Type | Description | +| -------------- | --------------------------- | +| Promise | Promise used to return the result.| **Example** @@ -1718,22 +1611,20 @@ captureSession.removeOutput(photoOutput).then(() => { }) ``` -### removeOutput(videoOutput: VideoOutput, callback: AsyncCallback): void; +### removeOutput -**System Capabilities:** +removeOutput(videoOutput: VideoOutput, callback: AsyncCallback): void -SystemCapability.Multimedia.Camera.Core +Removes a **VideoOutput** instance from this **CaptureSession** instance. This API uses an asynchronous callback to return the result. -**Description** - -Removes a **VideoOutput** instance from this **CaptureSession** instance. This method uses an asynchronous callback to return the result. +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -|---------------|----------------------|-----------|------------------------------------| -| videoOutput | VideoOutput | Yes | VideoOutput instance to remove | -| callback | AsyncCallback | Yes | Callback used to return the result | +| Name | Type | Mandatory| Description | +| ----------- | --------------------------- | ---- | --------------------------- | +| videoOutput | [VideoOutput](#videooutput) | Yes | **VideoOutput** instance to remove.| +| callback | AsyncCallback | Yes | Callback used to return the result. | **Example** @@ -1747,28 +1638,26 @@ captureSession.removeOutput(videoOutput, (err) => { }); ``` -### removeOutput(videoOutput: VideoOutput): Promise; - -**System Capabilities:** +### removeOutput -SystemCapability.Multimedia.Camera.Core +removeOutput(videoOutput: VideoOutput): Promise -**Description** +Removes a **VideoOutput** instance from this **CaptureSession** instance. This API uses a promise to return the result. -Removes a **VideoOutput** instance from this **CaptureSession** instance. This method uses a promise to return the result. +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -|---------------|---------------------|-----------|---------------------------------| -| videoOutput | VideoOutput | Yes | VideoOutput instance to remove | +| Name | Type | Mandatory| Description | +| ----------- | --------------------------- | ---- | --------------------------- | +| videoOutput | [VideoOutput](#videooutput) | Yes | **VideoOutput** instance to remove.| -**Return values** +**Return value** -| Type | Description | -|----------------|---------------------------------------------| -| Promise | Promise used to return the result | +| Type | Description | +| -------------- | --------------------------- | +| Promise | Promise used to return the result.| **Example** @@ -1779,21 +1668,19 @@ captureSession.removeOutput(videoOutput).then(() => { }) ``` -### start\(callback: AsyncCallback\): void; +### start -**System Capabilities:** +start\(callback: AsyncCallback\): void -SystemCapability.Multimedia.Camera.Core +Starts this **CaptureSession** instance. This API uses an asynchronous callback to return the result. -**Description** - -Starts this **CaptureSession** instance. 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 result | +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ------------------------ | +| callback | AsyncCallback | Yes | Callback used to return the result.| **Example** @@ -1807,21 +1694,19 @@ captureSession.start((err) => { }); ``` -### start\(\): Promise; - -**System Capabilities:** +### start -SystemCapability.Multimedia.Camera.Core +start\(\): Promise -**Description** +Starts this **CaptureSession** instance. This API uses a promise to return the result. -Starts this **CaptureSession** instance. This method uses a promise to return the result. +**System capability**: SystemCapability.Multimedia.Camera.Core -**Return values** +**Return value** -| Type | Description | -|----------------|-----------------------------------| -| Promise | Promise used to return the result | +| Type | Description | +| -------------- | --------------------------- | +| Promise | Promise used to return the result.| **Example** @@ -1831,22 +1716,20 @@ captureSession.start().then(() => { }) ``` -### stop\(callback: AsyncCallback\): void; - -**System Capabilities:** +### stop -SystemCapability.Multimedia.Camera.Core +stop\(callback: AsyncCallback\): void -**Description** +Stops this **CaptureSession** instance. This API uses an asynchronous callback to return the result. -Stops this **CaptureSession** instance. This method uses an asynchronous callback to return the result. +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| 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** @@ -1860,21 +1743,19 @@ captureSession.stop((err) => { }); ``` -### stop(): Promise; +### stop -**System Capabilities:** +stop(): Promise -SystemCapability.Multimedia.Camera.Core +Stops this **CaptureSession** instance. This API uses a promise to return the result. -**Description** +**System capability**: SystemCapability.Multimedia.Camera.Core -Stops this **CaptureSession** instance. This method uses a promise to return the result. +**Return value** -**Return values** - -| Type | Description | -|----------------|-----------------------------------| -| Promise | Promise used to return the result | +| Type | Description | +| -------------- | --------------------------- | +| Promise | Promise used to return the result.| **Example** @@ -1884,21 +1765,19 @@ captureSession.stop().then(() => { }) ``` -### release\(callback: AsyncCallback\): void; +### release -**System Capabilities:** +release\(callback: AsyncCallback\): void -SystemCapability.Multimedia.Camera.Core +Releases this **CaptureSession** instance. This API uses an asynchronous callback to return the instance. -**Description** - -Releases this **CaptureSession** instance. 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 result | +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ------------------------ | +| callback | AsyncCallback | Yes | Callback used to return the result.| **Example** @@ -1912,21 +1791,19 @@ captureSession.release((err) => { }); ``` -### release(): Promise; - -**System Capabilities:** +### release -SystemCapability.Multimedia.Camera.Core +release(): Promise -**Description** +Releases this **CaptureSession** instance. This API uses a promise to return the result. -Releases this **CaptureSession** instance. This method uses a promise to return the result. +**System capability**: SystemCapability.Multimedia.Camera.Core -**Return values** +**Return value** -| Type | Description | -|----------------|---------------------------------------------| -| Promise | Promise used to return the result | +| Type | Description | +| -------------- | --------------------------- | +| Promise | Promise used to return the result.| **Example** @@ -1936,22 +1813,20 @@ captureSession.release().then(() => { }) ``` -### on(type: 'error', callback: Callback): void; +### on('error') -**System Capabilities:** +on(type: 'error', callback: ErrorCallback): void -SystemCapability.Multimedia.Camera.Core +Listens for **CaptureSession** errors. This API uses a callback to return the errors. -**Description** - -Listens for **CaptureSession** errors. This method uses a callback to get errors. +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -| :------- | :--------------------- | :-------- | :-----------------------------------------------| -| type | string | Yes | Capture session error event. | -| callback | Callback | Yes | Callback used to get the capture session errors. | +| Name | Type | Mandatory| Description | +| :------- | :---------------------------------- | :--- | :-------------------------------------------- | +| type | string | Yes | Type of event to listen for. The value is fixed at **error**, indicating the capture session error event.| +| callback | ErrorCallback | Yes | Callback used to return the capture session errors. | **Example** @@ -1961,22 +1836,20 @@ captureSession.on('error', (captureSessionError) => { }) ``` -## createPreviewOutput(surfaceId: string, callback: AsyncCallback): void; - -**System Capabilities:** +## camera.createPreviewOutput -SystemCapability.Multimedia.Camera.Core +createPreviewOutput(surfaceId: string, callback: AsyncCallback): void -**Description** +Creates a **PreviewOutput** instance. This API uses an asynchronous callback to return the instance. -Creates a **PreviewOutput** instance. This method uses an asynchronous callback to return the instance. +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -|------------|-------------------------------|-----------|----------------------------------------------------| -| surfaceId | string | Yes | Surface ID received from XComponent view | -| callback | AsyncCallback | Yes | Callback used to return the PreviewOutput instance | +| Name | Type | Mandatory| Description | +| --------- | ----------------------------------------------- | ---- | ------------------------------------- | +| surfaceId | string | Yes | Surface ID received from **XComponent**. | +| callback | AsyncCallback<[PreviewOutput](#previewoutput)\> | Yes | Callback used to return the **PreviewOutput** instance.| **Example** @@ -1990,27 +1863,25 @@ camera.createPreviewOutput((surfaceId), (err, previewOutput) => { }); ``` -## createPreviewOutput(surfaceId: string): Promise; +## camera.createPreviewOutput -**System Capabilities:** +createPreviewOutput(surfaceId: string): Promise\ -SystemCapability.Multimedia.Camera.Core +Creates a **PreviewOutput** instance. This API uses a promise to return the instance. -**Description** - -Creates a **PreviewOutput** instance. This method uses a promise to return the instance. +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -|------------|-----------------|-----------|----------------------------------------------------| -| surfaceId | string | Yes | Surface ID received from XComponent view | +| Name | Type | Mandatory| Description | +| --------- | ------ | ---- | ---------------------------------- | +| surfaceId | string | Yes | Surface ID received from **XComponent**.| -**Return values** +**Return value** -| Type | Description | -|-------------------------|---------------------------------------------------| -| Promise | Promise used to return the PreviewOutput instance | +| Type | Description | +| ----------------------------------------- | --------------------------- | +| Promise<[PreviewOutput](#previewoutput)\> | Promise used to return the **PreviewOutput** instance.| **Example** @@ -2024,21 +1895,19 @@ camera.createPreviewOutput(surfaceId).then((previewOutput) => { Implements preview output. -### release(callback: AsyncCallback): void; +### release -**System Capabilities:** +release(callback: AsyncCallback): void -SystemCapability.Multimedia.Camera.Core +Releases this **PreviewOutput** instance. This API uses an asynchronous callback to return the result. -**Description** - -Releases this **PreviewOutput** instance. 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 result | +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ------------------------ | +| callback | AsyncCallback | Yes | Callback used to return the result.| **Example** @@ -2052,21 +1921,19 @@ previewOutput.release((err) => { }); ``` -### release(): Promise; - -**System Capabilities:** +### release -SystemCapability.Multimedia.Camera.Core +release(): Promise -**Description** +Releases this **PreviewOutput** instance. This API uses a promise to return the result. -Releases this **PreviewOutput** instance. This method uses a promise to return the result. +**System capability**: SystemCapability.Multimedia.Camera.Core -**Return values** +**Return value** -| Type | Description | -|----------------|-----------------------------------| -| Promise | Promise used to return the result | +| Type | Description | +| -------------- | --------------------------- | +| Promise | Promise used to return the result.| **Example** @@ -2077,22 +1944,20 @@ previewOutput.release().then(() => { }) ``` -### on(type: 'frameStart', callback: Callback): void; - -**System Capabilities:** +### on('frameStart') -SystemCapability.Multimedia.Camera.Core +on(type: 'frameStart', callback: AsyncCallback): void -**Description** +Listens for preview frame start events. This API uses an asynchronous callback to return the result. -Listens for preview frame start events. This method uses a callback to get the event information. +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -| :------- | :---------------- | :-------- | :----------------------------------| -| type | string | Yes | Name of the event to listen for. | -| callback | Callback | Yes | Callback used to return the result | +| Name | Type | Mandatory| Description | +| :------- | :------------------- | :--- | :------------------------------------------- | +| type | string | Yes | Type of event to listen for. The value is fixed at **frameStart**, indicating the preview frame start event.| +| callback | AsyncCallback | Yes | Callback used to return the result. | **Example** @@ -2102,22 +1967,20 @@ previewOutput.on('frameStart', () => { }) ``` -### on(type: 'frameEnd', callback: Callback): void; +### on('frameEnd') -**System Capabilities:** +on(type: 'frameEnd', callback: AsyncCallback): void -SystemCapability.Multimedia.Camera.Core +Listens for preview frame end events. This API uses an asynchronous callback to return the result. -**Description** - -Listens for preview frame end event. This method uses a callback to get the event information. +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -| :------- | :---------------- | :-------- | :----------------------------------| -| type | string | Yes | Name of the event to listen for. | -| callback | Callback | Yes | Callback used to return the result | +| Name | Type | Mandatory| Description | +| :------- | :------------------- | :--- | :----------------------------------------- | +| type | string | Yes | Type of event to listen for. The value is fixed at **frameEnd**, indicating the preview frame end event.| +| callback | AsyncCallback | Yes | Callback used to return the result. | **Example** @@ -2127,22 +1990,20 @@ previewOutput.on('frameEnd', () => { }) ``` -### on(type: 'error', callback: Callback): void; - -**System Capabilities:** +### on('error') -SystemCapability.Multimedia.Camera.Core +on(type: 'error', callback: ErrorCallback): void -**Description** +Listens for **PreviewOutput** errors. This API uses a callback to return the errors. -Listens for **PreviewOutput** errors. This method uses a callback to get errors. +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -| :------- | :--------------------- | :-------- | :-----------------------------------------------| -| type | string | Yes | Preview output error event. | -| callback | Callback | Yes | Callback used to get the preview output errors. | +| Name | Type | Mandatory| Description | +| :------- | :--------------------------------- | :--- | :-------------------------------------------- | +| type | string | Yes | Type of event to listen for. The value is fixed at **error**, indicating the preview output error event.| +| callback | ErrorCallback | Yes | Callback used to return the preview output errors. | **Example** @@ -2152,22 +2013,20 @@ previewOutput.on('error', (previewOutputError) => { }) ``` -## createPhotoOutput(surfaceId: string, callback: AsyncCallback): void; +## camera.createPhotoOutput -**System Capabilities:** +createPhotoOutput(surfaceId: string, callback: AsyncCallback): void -SystemCapability.Multimedia.Camera.Core +Creates a **PhotoOutput** instance. This API uses an asynchronous callback to return the instance. -**Description** - -Creates a **PhotoOutput** instance. This method uses an asynchronous callback to return the instance. +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -|------------|-------------------------------|-----------|----------------------------------------------------| -| surfaceId | string | Yes | Surface ID received from ImageReceiver | -| callback | AsyncCallback | Yes | Callback used to return the PhotoOutput instance | +| Name | Type | Mandatory| Description | +| --------- | ------------------------------------------- | ---- | ----------------------------------- | +| surfaceId | string | Yes | Surface ID received from **ImageReceiver**. | +| callback | AsyncCallback<[PhotoOutput](#photooutput)\> | Yes | Callback used to return the **PhotoOutput** instance.| **Example** @@ -2181,27 +2040,25 @@ camera.createPhotoOutput((surfaceId), (err, photoOutput) => { }); ``` -## createPhotoOutput(surfaceId: string): Promise; - -**System Capabilities:** +## camera.createPhotoOutput -SystemCapability.Multimedia.Camera.Core +createPhotoOutput(surfaceId: string): Promise -**Description** +Creates a **PhotoOutput** instance. This API uses a promise to return the instance. -Creates a **PhotoOutput** instance. This method uses a promise to return the PhotoOutput instance. +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -|------------|-----------------|-----------|----------------------------------------------------| -| surfaceId | string | Yes | Surface ID received from ImageReceiver | +| Name | Type | Mandatory| Description | +| --------- | ------ | ---- | --------------------------------- | +| surfaceId | string | Yes | Surface ID received from **ImageReceiver**.| -**Return values** +**Return value** -| Type | Description | -|-------------------------|--------------------------------------------------| -| Promise | Promise used to return the PhotoOutput instance | +| Type | Description | +| ------------------------------------- | -------------------------------------- | +| Promise<[PhotoOutput](#photooutput)\> | Promise used to return the **PhotoOutput** instance.| **Example** @@ -2214,79 +2071,59 @@ camera.createPhotoOutput(surfaceId).then((photoOutput) => { Enumerates the image rotation angles. -**System Capabilities:** - -SystemCapability.Multimedia.Camera.Core - -| Name | Default Value | Description | -|--------------|---------------|----------------------------------------| -| ROTATION_0 | 0 | The capture image rotates 0 degrees | -| ROTATION_90 | 90 | The capture image rotates 90 degrees | -| ROTATION_180 | 180 | The capture image rotates 180 degrees | -| ROTATION_270 | 270 | The capture image rotates 270 degrees | +**System capability**: SystemCapability.Multimedia.Camera.Core +| Name | Default Value| Description | +| ------------ | ------ | --------------- | +| ROTATION_0 | 0 | The image rotates 0 degrees. | +| ROTATION_90 | 90 | The image rotates 90 degrees. | +| ROTATION_180 | 180 | The image rotates 180 degrees.| +| ROTATION_270 | 270 | The image rotates 270 degrees.| -## Location -Defines the location of a captured image. - -**System Capabilities:** - -SystemCapability.Multimedia.Camera.Core - -| Name | Type | Access | Description | -|-----------|--------|--------------|-------------| -| latitude | number | read / write | Latitude | -| longitude | number | read / write | Longitude | ## QualityLevel Enumerates the image quality levels. -**System Capabilities:** +**System capability**: SystemCapability.Multimedia.Camera.Core -SystemCapability.Multimedia.Camera.Core - -| Name | Default value | Description | -|----------------------|---------------|----------------------| -| QUALITY_LEVEL_HIGH | 0 | High image quality | -| QUALITY_LEVEL_MEDIUM | 1 | Medium image quality | -| QUALITY_LEVEL_LOW | 2 | Low image quality | +| Name | Default Value| Description | +| -------------------- | ------ | -------------- | +| QUALITY_LEVEL_HIGH | 0 | High image quality. | +| QUALITY_LEVEL_MEDIUM | 1 | Medium image quality.| +| QUALITY_LEVEL_LOW | 2 | Low image quality. | ## PhotoCaptureSetting Defines the settings for image capture. -**System Capabilities:** - -SystemCapability.Multimedia.Camera.Core +**System capability**: SystemCapability.Multimedia.Camera.Core -| Name | Type | Mandatory | Description | -|----------|---------------|-----------|---------------------| -| quality | QualityLevel | Optional | Photo image quality | -| rotation | ImageRotation | Optional | Photo rotation | +| Name | Type | Mandatory| Description | +| -------- | ------------------------------- | ---- | -------------- | +| quality | [QualityLevel](#qualitylevel) | No | Photo image quality. | +| rotation | [ImageRotation](#imagerotation) | No | Photo rotation.| ## PhotoOutput Implements photo output. -### capture(callback: AsyncCallback): void; +### capture -**System Capabilities:** +capture(callback: AsyncCallback): void -SystemCapability.Multimedia.Camera.Core +Captures a photo. This API uses an asynchronous callback to return the result. -**Description** - -Captures a photo. 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 result | +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ------------------------ | +| callback | AsyncCallback | Yes | Callback used to return the result.| **Example** @@ -2300,22 +2137,20 @@ photoOutput.capture((err) => { }); ``` -### capture(setting: PhotoCaptureSetting, callback: AsyncCallback): void; - -**System Capabilities:** +### capture -SystemCapability.Multimedia.Camera.Core +capture(setting: PhotoCaptureSetting, callback: AsyncCallback): void -**Description** +Captures a photo with the specified capture settings. This API uses an asynchronous callback to return the result. -Captures a photo with the specified capture settings. This method uses an asynchronous callback to return the result. +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -|----------|----------------------|-----------|----------------------------------------------| -| setting | PhotoCaptureSetting | Yes | Photo capture settings | -| callback | AsyncCallback | Yes | Callback used to return the result | +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------- | ---- | ------------------------ | +| setting | [PhotoCaptureSetting](#photocapturesetting) | Yes | Photo capture settings. | +| callback | AsyncCallback | Yes | Callback used to return the result.| **Example** @@ -2329,27 +2164,25 @@ photoOutput.capture(settings, (err) => { }); ``` -### capture(setting?: PhotoCaptureSetting): Promise; +### capture -**System Capabilities:** +capture(setting?: PhotoCaptureSetting): Promise -SystemCapability.Multimedia.Camera.Core +Captures a photo with the specified capture settings. This API uses a promise to return the result. -**Description** - -Captures a photo with the specified capture settings. This method uses a promise to return the result. +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -|----------|---------------------|-----------|----------------------------------------------| -| setting | PhotoCaptureSetting | No | Photo capture settings | +| Name | Type | Mandatory| Description | +| ------- | ------------------------------------------- | ---- | ---------- | +| setting | [PhotoCaptureSetting](#photocapturesetting) | No | Photo capture settings.| -**Return values** +**Return value** -| Type | Description | -|----------------|---------------------------------------------| -| Promise | Promise used to return the result | +| Type | Description | +| -------------- | --------------------------- | +| Promise | Promise used to return the result.| **Example** @@ -2360,21 +2193,19 @@ photoOutput.capture().then(() => { }) ``` -### release(callback: AsyncCallback): void; +### release -**System Capabilities:** +release(callback: AsyncCallback): void -SystemCapability.Multimedia.Camera.Core +Releases this **PhotoOutput** instance. This API uses an asynchronous callback to return the result. -**Description** - -Releases this **PhotoOutput** instance. 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 result | +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ------------------------ | +| callback | AsyncCallback | Yes | Callback used to return the result.| **Example** @@ -2388,21 +2219,19 @@ photoOutput.release((err) => { }); ``` -### release(): Promise; - -**System Capabilities:** +### release -SystemCapability.Multimedia.Camera.Core +release(): Promise -**Description** +Releases this **PhotoOutput** instance. This API uses a promise to return the result. -Releases this **PhotoOutput** instance. This method uses a promise to return the result. +**System capability**: SystemCapability.Multimedia.Camera.Core -**Return values** +**Return value** -| Type | Description | -|----------------|---------------------------------------------| -| Promise | Promise used to return the result | +| Type | Description | +| -------------- | --------------------------- | +| Promise | Promise used to return the result.| **Example** @@ -2413,22 +2242,20 @@ photoOutput.release().then(() => { }) ``` -### on(type: 'captureStart', callback: Callback): void; - -**System Capabilities:** +### on('captureStart') -SystemCapability.Multimedia.Camera.Core +on(type: 'captureStart', callback: AsyncCallback): void -**Description** +Listens for photo capture start events. This API uses a callback to return the event information. -Listens for photo capture start events. This method uses a callback to get the event information. +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -| :------- | :--------------------- | :-------- | :-----------------------------------------------| -| type | string | Yes | Name of the event to listen for. | -| callback | Callback | Yes | Callback used to get the capture ID. | +| Name | Type | Mandatory| Description | +| :------- | :--------------------- | :--- | :----------------------------------------------- | +| type | string | Yes | Type of event to listen for. The value is fixed at **captureStart**, indicating the photo capture start event.| +| callback | AsyncCallback | Yes | Callback used to return the capture ID. | **Example** @@ -2438,22 +2265,20 @@ photoOutput.on('captureStart', (captureId) => { }) ``` -### on(type: 'frameShutter', callback: Callback): void; +### on('frameShutter') -**System Capabilities:** +on(type: 'frameShutter', callback: AsyncCallback): void -SystemCapability.Multimedia.Camera.Core +Listens for frame shutter events. This API uses a callback to return the event information. -**Description** - -Listens for frame shutter events. This method uses a callback to get the event information. +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -| :------- | :--------------------- | :-------- | :-----------------------------------------------| -| type | string | Yes | Name of the event to listen for. | -| callback | Callback | Yes | Callback used to get the frame shutter information.| +| Name | Type | Mandatory| Description | +| :------- | :------------------------------- | :--- | :--------------------------------------------- | +| type | string | Yes | Type of event to listen for. The value is fixed at **frameShutter**, indicating the frame shutter event.| +| callback | AsyncCallback | Yes | Callback used to return the frame shutter information. | **Example** @@ -2464,22 +2289,20 @@ photoOutput.on('frameShutter', (frameShutterInfo) => { }) ``` -### on(type: 'captureEnd', callback: Callback): void; - -**System Capabilities:** +### on('captureEnd') -SystemCapability.Multimedia.Camera.Core +on(type: 'captureEnd', callback: AsyncCallback): void -**Description** +Listens for photo capture end events. This API uses a callback to return the event information. -Listens for photo capture end events. This method uses a callback to get the event information. +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -| :------- | :--------------------- | :-------- | :------------------------------------------------| -| type | string | Yes | Name of the event to listen for. | -| callback | Callback | Yes | Callback used to get the capture end information | +| Name | Type | Mandatory| Description | +| :------- | :----------------------------- | :--- | :--------------------------------------------- | +| type | string | Yes | Type of event to listen for. The value is fixed at **captureEnd**, indicating the photo capture end event.| +| callback | AsyncCallback | Yes | Callback used to return the capture end information. | **Example** @@ -2490,22 +2313,20 @@ photoOutput.on('captureEnd', (captureEndInfo) => { }) ``` -### on(type: 'error', callback: Callback): void; +### on('error') -**System Capabilities:** +on(type: 'error', callback: ErrorCallback): void -SystemCapability.Multimedia.Camera.Core +Listens for **PhotoOutput** errors. This API uses a callback to return the errors. -**Description** - -Listens for **PhotoOutput** errors. This method uses a callback to get errors. +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -| :------- | :--------------------- | :-------- | :-----------------------------------------------| -| type | string | Yes | Photo output error event. | -| callback | Callback | Yes | Callback used to get the photo output errors. | +| Name | Type | Mandatory| Description | +| :------- | :------------------------------- | :--- | :---------------------------------------- | +| type | string | Yes | Type of event to listen for. The value is fixed at **error**, indicating the photo output error event.| +| callback | ErrorCallback | Yes | Callback used to return the photo output errors. | **Example** @@ -2515,22 +2336,20 @@ photoOutput.on('error', (photoOutputError) => { }) ``` -## createVideoOutput(surfaceId: string, callback: AsyncCallback): void; - -**System Capabilities:** +## camera.createVideoOutput -SystemCapability.Multimedia.Camera.Core +createVideoOutput(surfaceId: string, callback: AsyncCallback): void -**Description** +Creates a **VideoOutput** instance. This API uses an asynchronous callback to return the instance. -Creates a **VideoOutput** instance. This method uses an asynchronous callback to return the instance. +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -|------------|-------------------------------|-----------|----------------------------------------------------| -| surfaceId | string | Yes | Surface ID received from VideoRecorder | -| callback | AsyncCallback | Yes | Callback used to return the VideoOutput instance | +| Name | Type | Mandatory| Description | +| --------- | ------------------------------------------- | ---- | ----------------------------------- | +| surfaceId | string | Yes | Surface ID received from **VideoRecorder**. | +| callback | AsyncCallback<[VideoOutput](#videooutput)\> | Yes | Callback used to return the **VideoOutput** instance.| **Example** @@ -2544,27 +2363,25 @@ camera.createVideoOutput((surfaceId), (err, videoOutput) => { }); ``` -## createVideoOutput(surfaceId: string): Promise; +## camera.createVideoOutput -**System Capabilities:** +createVideoOutput(surfaceId: string): Promise -SystemCapability.Multimedia.Camera.Core +Creates a **VideoOutput** instance. This API uses a promise to return the instance. -**Description** - -Creates a **VideoOutput** instance. This method uses a promise to return the VideoOutput instance. +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -|------------|-----------------|-----------|----------------------------------------------------| -| surfaceId | string | Yes | Surface ID received from VideoRecorder | +| Name | Type | Mandatory| Description | +| --------- | ------ | ---- | --------------------------------- | +| surfaceId | string | Yes | Surface ID received from **VideoRecorder**.| -**Return values** +**Return value** -| Type | Description | -|---------------------------------------|-------------------------------------------------| -| Promise<[VideoOutput](#videooutput)\> | Promise used to return the VideoOutput instance | +| Type | Description | +| ------------------------------------- | -------------------------------------- | +| Promise<[VideoOutput](#videooutput)\> | Promise used to return the **VideoOutput** instance.| **Example** @@ -2573,25 +2390,24 @@ camera.createVideoOutput(surfaceId).then((videoOutput) => { console.log('Promise returned with the VideoOutput instance'); }) ``` + ## VideoOutput Implements video output. -### start(callback: AsyncCallback): void; - -**System Capabilities:** +### start -SystemCapability.Multimedia.Camera.Core +start(callback: AsyncCallback): void -**Description** +Starts the video output. This API uses an asynchronous callback to return the result. -Starts the video output. This method uses an asynchronous callback to return the result. +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| 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** @@ -2605,21 +2421,19 @@ videoOutput.start((err) => { }); ``` -### start(): Promise; +### start -**System Capabilities:** +start(): Promise -SystemCapability.Multimedia.Camera.Core +Starts the video output. This API uses a promise to return the result. -**Description** +**System capability**: SystemCapability.Multimedia.Camera.Core -Starts the video output. This method uses a promise to return the result. +**Return value** -**Return values** - -| Type | Description | -|----------------|---------------------------------------------| -| Promise | Promise used to return the result | +| Type | Description | +| -------------- | --------------------------- | +| Promise | Promise used to return the result.| **Example** @@ -2630,21 +2444,19 @@ videoOutput.start().then(() => { }) ``` -### stop(callback: AsyncCallback): void; +### stop -**System Capabilities:** +stop(callback: AsyncCallback): void -SystemCapability.Multimedia.Camera.Core +Stops the video output. This API uses an asynchronous callback to return the result. -**Description** - -Stops the video output. 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 result | +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ------------------------ | +| callback | AsyncCallback | Yes | Callback used to return the result.| **Example** @@ -2658,21 +2470,19 @@ videoOutput.stop((err) => { }); ``` -### stop(): Promise; - -**System Capabilities:** +### stop -SystemCapability.Multimedia.Camera.Core +stop(): Promise -**Description** +Stops the video output. This API uses a promise to return the result. -Stops the video output. This method uses a promise to return the result. +**System capability**: SystemCapability.Multimedia.Camera.Core -**Return values** +**Return value** -| Type | Description | -|----------------|---------------------------------------------| -| Promise | Promise used to return the result | +| Type | Description | +| -------------- | --------------------------- | +| Promise | Promise used to return the result.| **Example** @@ -2682,21 +2492,19 @@ videoOutput.start().then(() => { }) ``` -### release(callback: AsyncCallback): void; - -**System Capabilities:** +### release -SystemCapability.Multimedia.Camera.Core +release(callback: AsyncCallback): void -**Description** +Releases this **VideoOutput** instance. This API uses an asynchronous callback to return the result. -Releases this VideoOutput instance. This method uses an asynchronous callback to return the result. +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| 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** @@ -2710,21 +2518,19 @@ videoOutput.release((err) => { }); ``` -### release(): Promise; +### release -**System Capabilities:** +release(): Promise -SystemCapability.Multimedia.Camera.Core +Releases this **VideoOutput** instance. This API uses a promise to return the result. -**Description** +**System capability**: SystemCapability.Multimedia.Camera.Core -Releases this VideoOutput instance. This method uses a promise to return the result. +**Return value** -**Return values** - -| Type | Description | -|----------------|---------------------------------------------| -| Promise | Promise used to return the result | +| Type | Description | +| -------------- | --------------------------- | +| Promise | Promise used to return the result.| **Example** @@ -2735,22 +2541,20 @@ videoOutput.release().then(() => { }) ``` -### on(type: 'frameStart', callback: Callback): void; +### on('frameStart') -**System Capabilities:** +on(type: 'frameStart', callback: AsyncCallback): void -SystemCapability.Multimedia.Camera.Core +Listens for video frame start events. This API uses a callback to return the event information. -**Description** - -Listens for video frame start events. This method uses a callback to get the event information. +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -| :------- | :---------------- | :-------- | :----------------------------------| -| type | string | Yes | Name of the event to listen for. | -| callback | Callback | Yes | Callback used to return the result | +| Name | Type | Mandatory| Description | +| :------- | :------------------- | :--- | :----------------------------------------------- | +| type | string | Yes | Type of event to listen for. The value is fixed at **frameStart**, indicating the video frame start event.| +| callback | AsyncCallback | Yes | Callback used to return the result. | **Example** @@ -2760,16 +2564,20 @@ videoOutput.on('frameStart', () => { }) ``` -### on(type: 'frameEnd', callback: Callback): void; +### on('frameEnd') + +on(type: 'frameEnd', callback: AsyncCallback): void -Listens for video frame end events. This method uses a callback to get the event information. +Listens for video frame end events. This API uses a callback to return the event information. + +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -| :------- | :---------------- | :-------- | :----------------------------------| -| type | string | Yes | Name of the event to listen for. | -| callback | Callback | Yes | Callback used to return the result | +| Name | Type | Mandatory| Description | +| :------- | :------------------- | :--- | :--------------------------------------------- | +| type | string | Yes | Type of event to listen for. The value is fixed at **frameEnd**, indicating the video frame end event.| +| callback | AsyncCallback | Yes | Callback used to return the result. | **Example** @@ -2779,16 +2587,20 @@ videoOutput.on('frameEnd', () => { }) ``` -### on(type: 'error', callback: Callback): void; +### on('error') + +on(type: 'error', callback: ErrorCallback): void -Listens for **VideoOutput** errors. This method uses a callback to get errors. +Listens for **VideoOutput** errors. This API uses a callback to return the errors. + +**System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory | Description | -| :------- | :--------------------- | :-------- | :-----------------------------------------------| -| type | string | Yes | Video output error event. | -| callback | Callback | Yes | Callback used to get the video output errors. | +| Name | Type | Mandatory| Description | +| :------- | :-------------------------- | :--- | :-------------------------------------------- | +| type | string | Yes | Type of event to listen for. The value is fixed at **error**, indicating the video output error event.| +| callback | Callback | Yes | Callback used to return the video output errors. | **Example** @@ -2796,4 +2608,4 @@ Listens for **VideoOutput** errors. This method uses a callback to get errors. videoOutput.on('error', (VideoOutputError) => { console.log('Video output error code: ' + VideoOutputError.code); }) -``` \ No newline at end of file +``` diff --git a/en/application-dev/reference/apis/js-apis-image.md b/en/application-dev/reference/apis/js-apis-image.md index 0e90ccb51d..b62b75935d 100644 --- a/en/application-dev/reference/apis/js-apis-image.md +++ b/en/application-dev/reference/apis/js-apis-image.md @@ -1,7 +1,9 @@ # Image Processing -> **NOTE** +> **NOTE**
> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. +> +> API version 9 is a canary release for trial use. The APIs of this version may be unstable. ## Modules to Import @@ -990,14 +992,40 @@ Enumerates pixel map formats. | RGBA_8888 | 3 | RGBA_8888.| | RGB_565 | 2 | RGB_565. | +## AlphaType9+ + +Enumerates alpha types. + +**System capability**: SystemCapability.Multimedia.Image + +| Name | Default Value| Description | +| -------- | ------ | ----------------------- | +| UNKNOWN | 0 | Unknown alpha type. | +| OPAQUE | 1 | There is no alpha or the image is opaque.| +| PREMUL | 2 | Premultiplied alpha. | +| UNPREMUL | 3 | Unpremultiplied alpha, that is, straight alpha. | + +## ScaleMode9+ + +Enumerates scale modes. + +**System capability**: SystemCapability.Multimedia.Image + +| Name | Default Value| Description | +| --------------- | ------ | -------------------------------------------------- | +| CENTER_CROP | 1 | Scales the image so that it fills the requested bounds of the target and crops the extra.| +| FIT_TARGET_SIZE | 2 | Reduces the image size to the dimensions of the target. | + ## InitializationOptions8+ **System capability**: SystemCapability.Multimedia.Image | Name | Type | Readable| Writable| Description | | ----------- | ---------------------------------- | ---- | ---- | -------------- | +| alphaType9+ | [AlphaType](#alphatype9) | Yes | Yes | Alpha type. | | editable | boolean | Yes | Yes | Whether the image is editable. | | pixelFormat | [PixelMapFormat](#pixelmapformat7) | Yes | Yes | Pixel map format. | +| scaleMode9+ | [ScaleMode](#scalemode9) | Yes | Yes | Scale mode. | | size | [Size](#size) | Yes | Yes | Image size.| ## DecodingOptions7+ diff --git a/en/application-dev/reference/apis/js-apis-media.md b/en/application-dev/reference/apis/js-apis-media.md index 7fdf7692a1..99f812c113 100644 --- a/en/application-dev/reference/apis/js-apis-media.md +++ b/en/application-dev/reference/apis/js-apis-media.md @@ -1,7 +1,10 @@ # Media > **NOTE** +> > The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. +> +> API version 9 is a canary release for trial use. The APIs of this version may be unstable. The multimedia subsystem provides a set of simple and easy-to-use APIs for you to access the system and use media resources. @@ -10,6 +13,7 @@ This subsystem offers various media services covering audio and video, which pro - Audio playback ([AudioPlayer](#audioplayer)) - Video playback ([VideoPlayer](#videoplayer8)) - Audio recording ([AudioRecorder](#audiorecorder)) +- Video recording ([VideoRecorder](#videorecorder9)) The following capabilities will be provided in later versions: data source audio/video playback, audio/video encoding and decoding, container encapsulation and decapsulation, and media capability query. @@ -87,21 +91,16 @@ Creates a **VideoPlayer** instance in asynchronous mode. This API uses a promise ```js let videoPlayer -function failureCallback(error) { - console.info(`video failureCallback, error:${error.message}`); -} -function catchCallback(error) { - console.info(`video catchCallback, error:${error.message}`); -} - -await media.createVideoPlayer.then((video) => { - if (typeof(video) != 'undefined') { +media.createVideoPlayer().then((video) => { + if (typeof(video) != 'undefined') { videoPlayer = video; console.info('video createVideoPlayer success'); } else { console.info('video createVideoPlayer fail'); } -}, failureCallback).catch(catchCallback); +}).catch((error) => { + console.info(`video catchCallback, error:${error.message}`); +}); ``` ## media.createAudioRecorder @@ -124,6 +123,68 @@ Creates an **AudioRecorder** instance to control audio recording. let audiorecorder = media.createAudioRecorder(); ``` +## media.createVideoRecorder9+ + +createVideoRecorder(callback: AsyncCallback\<[VideoRecorder](#videorecorder9)>): void + +Creates a **VideoRecorder** instance in asynchronous mode. This API uses a callback to return the result. + +**System capability**: SystemCapability.Multimedia.Media.VideoRecorder + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ----------------------------------------------- | ---- | ------------------------------ | +| callback | AsyncCallback<[VideoRecorder](#videorecorder9)> | Yes | Callback used to return the **VideoRecorder** instance created.| + +**Example** + +```js +let videoRecorder + +media.createVideoRecorder((error, video) => { + if (typeof(video) != 'undefined') { + videoRecorder = video; + console.info('video createVideoRecorder success'); + } else { + console.info(`video createVideoRecorder fail, error:${error.message}`); + } +}); +``` + +## media.createVideoRecorder9+ + +createVideoRecorder(): Promise<[VideoRecorder](#videorecorder9)> + +Creates a **VideoRecorder** instance in asynchronous mode. This API uses a promise to return the result. + +**System capability**: SystemCapability.Multimedia.Media.VideoRecorder + +**Return value** + +| Type | Description | +| ----------------------------------------- | ----------------------------------- | +| Promise<[VideoRecorder](#videorecorder9)> | Promise used to return the **VideoRecorder** instance created.| + +**Example** + +```js +let videoRecorder + +media.createVideoRecorder().then((video) => { + if (typeof(video) != 'undefined') { + videoRecorder = video; + console.info('video createVideoRecorder success'); + } else { + console.info('video createVideoRecorder fail'); + } +}).catch((error) => { + console.info(`video catchCallback, error:${error.message}`); +}); +``` + + + ## MediaErrorCode8+ Enumerates the media error codes. @@ -358,7 +419,7 @@ audioPlayer = undefined; getTrackDescription(callback: AsyncCallback>): void -Obtains the audio track information. This API uses a callback to return the result. +Obtains the audio track information. This API uses a callback to return the result. It can be called only after the [dataLoad](#audioplayer_on) event is triggered. **System capability**: SystemCapability.Multimedia.Media.AudioPlayer @@ -394,7 +455,7 @@ audioPlayer.getTrackDescription((error, arrlist) => { getTrackDescription(): Promise> -Obtains the audio track information. This API uses a promise to return the result. +Obtains the audio track information. This API uses a promise to return the result. It can be called only after the [dataLoad](#audioplayer_on) event is triggered. **System capability**: SystemCapability.Multimedia.Media.AudioPlayer @@ -414,20 +475,17 @@ function printfDescription(obj) { console.info('audio value is ' + property); } } -function failureCallback(error) { - console.info(`audio failureCallback, error:${error.message}`); -} -function catchCallback(error) { - console.info(`audio catchCallback, error:${error.message}`); -} -await audioPlayer.getTrackDescription.then((arrlist) => { +audioPlayer.getTrackDescription().then((arrlist) => { if (typeof (arrlist) != 'undefined') { arrayDescription = arrlist; } else { console.log('audio getTrackDescription fail'); } -}, failureCallback).catch(catchCallback); +}).catch((error) => { + console.info(`audio catchCallback, error:${error.message}`); +}); + for (let i = 0; i < arrayDescription.length; i++) { printfDescription(arrayDescription[i]); } @@ -517,13 +575,14 @@ audioPlayer.on('error', (error) => { // Set the 'error' event callback // Set the FD (local playback) of the video file selected by the user. let fdPath = 'fd://' -let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3'; -await fileIO.open(path).then(fdNumber) => { +// The stream in the path can be pushed to the device by running the "hdc file send D:\xxx\01.mp3 /data/accounts/account_0/appdata" command. +let path = '/data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3'; +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) => { +}).catch((err) => { console.info('open fd failed err is' + err); }); audioPlayer.src = fdPath; // Set the src attribute and trigger the 'dataLoad' event callback. @@ -667,15 +726,11 @@ Sets **SurfaceId**. This API uses a promise to return the result. **Example** ```js -function failureCallback(error) { - console.info(`video failureCallback, error:${error.message}`); -} -function catchCallback(error) { - console.info(`video catchCallback, error:${error.message}`); -} -await videoPlayer.setDisplaySurface(surfaceId).then(() => { +videoPlayer.setDisplaySurface(surfaceId).then(() => { console.info('setDisplaySurface success'); -}, failureCallback).catch(catchCallback); +}).catch((error) => { + console.info(`video catchCallback, error:${error.message}`); +}); ``` ### prepare8+ @@ -721,15 +776,11 @@ Prepares for video playback. This API uses a promise to return the result. **Example** ```js -function failureCallback(error) { - console.info(`video failureCallback, error:${error.message}`); -} -function catchCallback(error) { - console.info(`video catchCallback, error:${error.message}`); -} -await videoPlayer.prepare().then(() => { +videoPlayer.prepare().then(() => { console.info('prepare success'); -}, failureCallback).catch(catchCallback); +}).catch((error) => { + console.info(`video catchCallback, error:${error.message}`); +}); ``` ### play8+ @@ -775,15 +826,11 @@ Starts to play video resources. This API uses a promise to return the result. **Example** ```js -function failureCallback(error) { - console.info(`video failureCallback, error:${error.message}`); -} -function catchCallback(error) { - console.info(`video catchCallback, error:${error.message}`); -} -await videoPlayer.play().then(() => { +videoPlayer.play().then(() => { console.info('play success'); -}, failureCallback).catch(catchCallback); +}).catch((error) => { + console.info(`video catchCallback, error:${error.message}`); +}); ``` ### pause8+ @@ -829,15 +876,11 @@ Pauses video playback. This API uses a promise to return the result. **Example** ```js -function failureCallback(error) { - console.info(`video failureCallback, error:${error.message}`); -} -function catchCallback(error) { - console.info(`video catchCallback, error:${error.message}`); -} -await videoPlayer.pause().then(() => { +videoPlayer.pause().then(() => { console.info('pause success'); -}, failureCallback).catch(catchCallback); +}).catch((error) => { + console.info(`video catchCallback, error:${error.message}`); +}); ``` ### stop8+ @@ -883,15 +926,11 @@ Stops video playback. This API uses a promise to return the result. **Example** ```js -function failureCallback(error) { - console.info(`video failureCallback, error:${error.message}`); -} -function catchCallback(error) { - console.info(`video catchCallback, error:${error.message}`); -} -await videoPlayer.stop().then(() => { +videoPlayer.stop().then(() => { console.info('stop success'); -}, failureCallback).catch(catchCallback); +}).catch((error) => { + console.info(`video catchCallback, error:${error.message}`); +}); ``` ### reset8+ @@ -937,15 +976,11 @@ Switches the video resource to be played. This API uses a promise to return the **Example** ```js -function failureCallback(error) { - console.info(`video failureCallback, error:${error.message}`); -} -function catchCallback(error) { - console.info(`video catchCallback, error:${error.message}`); -} -await videoPlayer.reset().then(() => { +videoPlayer.reset().then(() => { console.info('reset success'); -}, failureCallback).catch(catchCallback); +}).catch((error) => { + console.info(`video catchCallback, error:${error.message}`); +}); ``` ### seek8+ @@ -1027,19 +1062,17 @@ Seeks to the specified playback position. If **mode** is not specified, the next **Example** ```js -function failureCallback(error) { - console.info(`video failureCallback, error:${error.message}`); -} -function catchCallback(error) { - console.info(`video catchCallback, error:${error.message}`); -} -await videoPlayer.seek(seekTime).then((seekDoneTime) => { // seekDoneTime indicates the position after the seek operation is complete. +videoPlayer.seek(seekTime).then((seekDoneTime) => { // seekDoneTime indicates the position after the seek operation is complete. console.info('seek success'); -}, failureCallback).catch(catchCallback); +}).catch((error) => { + console.info(`video catchCallback, error:${error.message}`); +}); -await videoPlayer.seek(seekTime, seekMode).then((seekDoneTime) => { +videoPlayer.seek(seekTime, seekMode).then((seekDoneTime) => { console.info('seek success'); -}, failureCallback).catch(catchCallback); +}).catch((error) => { + console.info(`video catchCallback, error:${error.message}`); +}); ``` ### setVolume8+ @@ -1092,15 +1125,11 @@ Sets the volume. This API uses a promise to return the result. **Example** ```js -function failureCallback(error) { - console.info(`video failureCallback, error:${error.message}`); -} -function catchCallback(error) { - console.info(`video catchCallback, error:${error.message}`); -} -await videoPlayer.setVolume(vol).then() => { +videoPlayer.setVolume(vol).then() => { console.info('setVolume success'); -}, failureCallback).catch(catchCallback); +}).catch((error) => { + console.info(`video catchCallback, error:${error.message}`); +}); ``` ### release8+ @@ -1146,15 +1175,11 @@ Releases the video playback resource. This API uses a promise to return the resu **Example** ```js -function failureCallback(error) { - console.info(`video failureCallback, error:${error.message}`); -} -function catchCallback(error) { - console.info(`video catchCallback, error:${error.message}`); -} -await videoPlayer.release().then() => { +videoPlayer.release().then() => { console.info('release success'); -}, failureCallback).catch(catchCallback); +}).catch((error) => { + console.info(`video catchCallback, error:${error.message}`); +}); ``` ### getTrackDescription8+ @@ -1217,21 +1242,17 @@ function printfDescription(obj) { console.info('video value is ' + property); } } -function failureCallback(error) { - console.info(`video failureCallback, error:${error.message}`); -} -function catchCallback(error) { - console.info(`video catchCallback, error:${error.message}`); -} let arrayDescription; -await videoPlayer.getTrackDescription().then((arrlist) => { +videoPlayer.getTrackDescription().then((arrlist) => { if (typeof (arrlist) != 'undefined') { arrayDescription = arrlist; } else { console.log('video getTrackDescription fail'); } -}, failureCallback).catch(catchCallback); +}).catch((error) => { + console.info(`video catchCallback, error:${error.message}`); +}); for (let i = 0; i < arrayDescription.length; i++) { printfDescription(arrayDescription[i]); } @@ -1287,15 +1308,11 @@ Sets the video playback speed. This API uses a promise to return the result. **Example** ```js -function failureCallback(error) { - console.info(`video failureCallback, error:${error.message}`); -} -function catchCallback(error) { - console.info(`video catchCallback, error:${error.message}`); -} -await videoPlayer.setSpeed(speed).then() => { +videoPlayer.setSpeed(speed).then() => { console.info('setSpeed success'); -}, failureCallback).catch(catchCallback); +}).catch((error) => { + console.info(`video catchCallback, error:${error.message}`); +}); ``` ### on('playbackCompleted')8+ @@ -1774,6 +1791,644 @@ Enumerates the audio output formats. | AMR_WB | 4 | AMR_WB.
This API is defined but not implemented yet.| | AAC_ADTS | 6 | Audio Data Transport Stream (ADTS), which is a transport stream format of AAC-based audio.| +## VideoRecorder9+ + +Implements video recording. Before calling an API of the **VideoRecorder** class, you must call [createVideoRecorder()](#mediacreatevideorecorder9) to create a [VideoRecorder](#videorecorder9) instance. + +For details about the video recording demo, see [Video Recording Development](../../media/video-recorder.md). + +### Attributes + +**System capability**: SystemCapability.Multimedia.Media.VideoRecorder + +| Name | Type | Readable| Writable| Description | +| ------------------ | -------------------------------------- | ---- | ---- | ---------------- | +| state8+ | [VideoRecordState](#videorecordstate9) | Yes | No | Video recording state.| + +### prepare9+ + +prepare(config: VideoRecorderConfig, callback: AsyncCallback\): void; + +Sets video recording parameters in asynchronous mode. This API uses a callback to return the result. + +**Required permissions:** ohos.permission.MICROPHONE + +**System capability**: SystemCapability.Multimedia.Media.VideoRecorder + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | -------------------------------------------- | ---- | ----------------------------------- | +| config | [VideoRecorderConfig](#videorecorderconfig9) | Yes | Video recording parameters to set. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Example** + +```js +let videoProfile = { + audioBitrate : 48000, + audioChannels : 2, + audioCodec : 'audio/mp4a-latm', + audioSampleRate : 48000, + fileFormat : 'mp4', + videoBitrate : 48000, + videoCodec : 'video/mp4v-es', + videoFrameWidth : 640, + videoFrameHeight : 480, + videoFrameRate : 30 +} + +let videoConfig = { + audioSourceType : 1, + videoSourceType : 0, + profile : videoProfile, + url : 'fd://xx', // The file must be created by the caller and granted with proper permissions. + orientationHint : 0, + location : { latitude : 30, longitude : 130 }, +} + +// asyncallback +let videoRecorder = null; +let events = require('events'); +let eventEmitter = new events.EventEmitter(); + +eventEmitter.on('prepare', () => { + videoRecorder.prepare(videoConfig, (err) => { + if (typeof (err) == 'undefined') { + console.info('prepare success'); + } else { + console.info('prepare failed and error is ' + err.message); + } + }); +}); + +media.createVideoRecorder((err, recorder) => { + if (typeof (err) == 'undefined' && typeof (recorder) != 'undefined') { + videoRecorder = recorder; + console.info('createVideoRecorder success'); + eventEmitter.emit('prepare'); // Trigger the 'prepare' event. + } else { + console.info('createVideoRecorder failed and error is ' + err.message); + } +}); +``` + +### prepare9+ + +prepare(config: VideoRecorderConfig): Promise\; + +Sets video recording parameters in asynchronous mode. This API uses a promise to return the result. + +**Required permissions:** ohos.permission.MICROPHONE and ohos.permission.CAMERA + +**System capability**: SystemCapability.Multimedia.Media.VideoRecorder + +**Parameters** + +| Name| Type | Mandatory| Description | +| ------ | -------------------------------------------- | ---- | ------------------------ | +| config | [VideoRecorderConfig](#videorecorderconfig9) | Yes | Video recording parameters to set.| + +**Return value** + +| Type | Description | +| -------------- | ---------------------------------------- | +| Promise\ | Promise used to return the result.| + +**Example** + +```js +let videoProfile = { + audioBitrate : 48000, + audioChannels : 2, + audioCodec : 'audio/mp4a-latm', + audioSampleRate : 48000, + fileFormat : 'mp4', + videoBitrate : 48000, + videoCodec : 'video/mp4v-es', + videoFrameWidth : 640, + videoFrameHeight : 480, + videoFrameRate : 30 +} + +let videoConfig = { + audioSourceType : 1, + videoSourceType : 0, + profile : videoProfile, + url : 'fd://xx', // The file must be created by the caller and granted with proper permissions. + orientationHint : 0, + location : { latitude : 30, longitude : 130 }, +} + +// promise +let videoRecorder = null; +media.createVideoRecorder().then((recorder) => { + if (typeof (recorder) != 'undefined') { + videoRecorder = recorder; + console.info('createVideoRecorder success'); + } else { + console.info('createVideoRecorder failed'); + } +}).catch((err) => { + console.info('catch err error message is ' + err.message); +}); + +videoRecorder.prepare(videoConfig).then(() => { + console.info('prepare success'); +}).catch((err) => { + console.info('prepare failed and catch error is ' + err.message); +}); +``` + +### getInputSurface9+ + +getInputSurface(callback: AsyncCallback\): void; + +Obtains the surface required for recording in asynchronous mode. This surface is provided for the caller. The caller obtains the **surfaceBuffer** from this surface and fills in the corresponding data. + +Note that the video data must carry the timestamp (in ns) and buffer size, and the start time of the timestamp is based on the system startup time. + +This API can be called only after [prepare()](#videorecorder_prepare1) is called. + +**System capability**: SystemCapability.Multimedia.Media.VideoRecorder + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ---------------------- | ---- | --------------------------- | +| callback | AsyncCallback\ | Yes | Callback used to obtain the result.| + +**Example** + +```js +// asyncallback +let surfaceID = null; // Surface ID passed to the external system. +videoRecorder.getInputSurface((err, surfaceId) => { + if (typeof (err) == 'undefined') { + console.info('getInputSurface success'); + surfaceID = surfaceId; + } else { + console.info('getInputSurface failed and error is ' + err.message); + } +}); +``` + +### getInputSurface9+ + +getInputSurface(): Promise\; + + Obtains the surface required for recording in asynchronous mode. This surface is provided for the caller. The caller obtains the **surfaceBuffer** from this surface and fills in the corresponding data. + +Note that the video data must carry the timestamp (in ns) and buffer size, and the start time of the timestamp is based on the system startup time. + +This API can be called only after [prepare()](#videorecorder_prepare1) is called. + +**System capability**: SystemCapability.Multimedia.Media.VideoRecorder + +**Return value** + +| Type | Description | +| ---------------- | -------------------------------- | +| Promise\ | Promise used to return the result.| + +**Example** + +```js +// promise +let surfaceID = null; // Surface ID passed to the external system. +videoRecorder.getInputSurface().then((surfaceId) => { + console.info('getInputSurface success'); + surfaceID = surfaceId; +}).catch((err) => { + console.info('getInputSurface failed and catch error is ' + err.message); +}); +``` + +### start9+ + +start(callback: AsyncCallback\): void; + +Starts video recording in asynchronous mode. This API uses a callback to return the result. + +This API can be called only after [prepare()](#videorecorder_prepare1) and [getInputSurface()](#getinputsurface8) are called, because the data source must pass data to the surface first. + +**System capability**: SystemCapability.Multimedia.Media.VideoRecorder + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ---------------------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Example** + +```js +// asyncallback +videoRecorder.start((err) => { + if (typeof (err) == 'undefined') { + console.info('start videorecorder success'); + } else { + console.info('start videorecorder failed and error is ' + err.message); + } +}); +``` + +### start9+ + +start(): Promise\; + +Starts video recording in asynchronous mode. This API uses a promise to return the result. + +This API can be called only after [prepare()](#videorecorder_prepare1) and [getInputSurface()](#getinputsurface8) are called, because the data source must pass data to the surface first. + +**System capability**: SystemCapability.Multimedia.Media.VideoRecorder + +**Return value** + +| Type | Description | +| -------------- | ------------------------------------- | +| Promise\ | Promise used to return the result.| + +**Example** + +```js +// promise +videoRecorder.start().then(() => { + console.info('start videorecorder success'); +}).catch((err) => { + console.info('start videorecorder failed and catch error is ' + err.message); +}); +``` + +### pause9+ + +pause(callback: AsyncCallback\): void; + +Pauses video recording in asynchronous mode. This API uses a callback to return the result. + +This API can be called only after [start()](#videorecorder_start1) is called. You can resume recording by calling [resume()](#videorecorder_resume1). + +**System capability**: SystemCapability.Multimedia.Media.VideoRecorder + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ---------------------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Example** + +```js +// asyncallback +videoRecorder.pause((err) => { + if (typeof (err) == 'undefined') { + console.info('pause videorecorder success'); + } else { + console.info('pause videorecorder failed and error is ' + err.message); + } +}); +``` + +### pause9+ + +pause(): Promise\; + +Pauses video recording in asynchronous mode. This API uses a promise to return the result. + +This API can be called only after [start()](#videorecorder_start1) is called. You can resume recording by calling [resume()](#videorecorder_resume1). + +**System capability**: SystemCapability.Multimedia.Media.VideoRecorder + +**Return value** + +| Type | Description | +| -------------- | ------------------------------------- | +| Promise\ | Promise used to return the result.| + +**Example** + +```js +// promise +videoRecorder.pause().then(() => { + console.info('pause videorecorder success'); +}).catch((err) => { + console.info('pause videorecorder failed and catch error is ' + err.message); +}); +``` + +### resume9+ + +resume(callback: AsyncCallback\): void; + +Resumes video recording in asynchronous mode. This API uses a callback to return the result. + +**System capability**: SystemCapability.Multimedia.Media.VideoRecorder + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ---------------------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Example** + +```js +// asyncallback +videoRecorder.resume((err) => { + if (typeof (err) == 'undefined') { + console.info('resume videorecorder success'); + } else { + console.info('resume videorecorder failed and error is ' + err.message); + } +}); +``` + +### resume9+ + +resume(): Promise\; + +Resumes video recording in asynchronous mode. This API uses a promise to return the result. + +**System capability**: SystemCapability.Multimedia.Media.VideoRecorder + +**Return value** + +| Type | Description | +| -------------- | ------------------------------------- | +| Promise\ | Promise used to return the result.| + +**Example** + +```js +// promise +videoRecorder.resume().then(() => { + console.info('resume videorecorder success'); +}).catch((err) => { + console.info('resume videorecorder failed and catch error is ' + err.message); +}); +``` + +### stop9+ + +stop(callback: AsyncCallback\): void; + +Stops video recording in asynchronous mode. This API uses a callback to return the result. + +To start another recording, you must call [prepare()](#videorecorder_prepare1) and [getInputSurface()](#getinputsurface8) again. + +**System capability**: SystemCapability.Multimedia.Media.VideoRecorder + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ---------------------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Example** + +```js +// asyncallback +videoRecorder.stop((err) => { + if (typeof (err) == 'undefined') { + console.info('stop videorecorder success'); + } else { + console.info('stop videorecorder failed and error is ' + err.message); + } +}); +``` + +### stop9+ + +stop(): Promise\; + +Stops video recording in asynchronous mode. This API uses a promise to return the result. + +To start another recording, you must call [prepare()](#videorecorder_prepare1) and [getInputSurface()](#getinputsurface8) again. + +**System capability**: SystemCapability.Multimedia.Media.VideoRecorder + +**Return value** + +| Type | Description | +| -------------- | ------------------------------------- | +| Promise\ | Promise used to return the result.| + +**Example** + +```js +// promise +videoRecorder.stop().then(() => { + console.info('stop videorecorder success'); +}).catch((err) => { + console.info('stop videorecorder failed and catch error is ' + err.message); +}); +``` + +### release9+ + +release(callback: AsyncCallback\): void; + +Releases the video recording resource in asynchronous mode. This API uses a callback to return the result. + +**System capability**: SystemCapability.Multimedia.Media.VideoRecorder + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | -------------------------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Example** + +```js +// asyncallback +videoRecorder.release((err) => { + if (typeof (err) == 'undefined') { + console.info('release videorecorder success'); + } else { + console.info('release videorecorder failed and error is ' + err.message); + } +}); +``` + +### release9+ + +release(): Promise\; + +Releases the video recording resource in asynchronous mode. This API uses a promise to return the result. + +**System capability**: SystemCapability.Multimedia.Media.VideoRecorder + +**Return value** + +| Type | Description | +| -------------- | ----------------------------------------- | +| Promise\ | Promise used to return the result.| + +**Example** + +```js +// promise +videoRecorder.release().then(() => { + console.info('release videorecorder success'); +}).catch((err) => { + console.info('release videorecorder failed and catch error is ' + err.message); +}); +``` + +### reset9+ + +reset(callback: AsyncCallback\): void; + +Resets video recording in asynchronous mode. This API uses a callback to return the result. + +To start another recording, you must call [prepare()](#videorecorder_prepare1) and [getInputSurface()](#getinputsurface8) again. + +**System capability**: SystemCapability.Multimedia.Media.VideoRecorder + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ---------------------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Example** + +```js +// asyncallback +videoRecorder.reset((err) => { + if (typeof (err) == 'undefined') { + console.info('reset videorecorder success'); + } else { + console.info('reset videorecorder failed and error is ' + err.message); + } +}); +``` + +### reset9+ + +reset(): Promise\; + +Resets video recording in asynchronous mode. This API uses a promise to return the result. + +To start another recording, you must call [prepare()](#videorecorder_prepare1) and [getInputSurface()](#getinputsurface8) again. + +**System capability**: SystemCapability.Multimedia.Media.VideoRecorder + +**Return value** + +| Type | Description | +| -------------- | ------------------------------------- | +| Promise\ | Promise used to return the result.| + +**Example** + +```js +// promise +videoRecorder.reset().then(() => { + console.info('reset videorecorder success'); +}).catch((err) => { + console.info('reset videorecorder failed and catch error is ' + err.message); +}); +``` + +### on('error')9+ + +on(type: 'error', callback: ErrorCallback): void + +Subscribes to the video recording error event. + +**System capability**: SystemCapability.Multimedia.Media.VideoRecorder + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------- | ---- | ------------------------------------------------------------ | +| type | string | Yes | Type of the event to subscribe to, which is 'error' in this API.
The 'error' event is triggered when an error occurs during video recording.| +| callback | ErrorCallback | Yes | Callback invoked when the event is triggered. | + +**Example** + +```js +videoRecorder.on('error', (error) => { // Set the 'error' event callback. + console.info(`audio error called, errName is ${error.name}`); // Print the error name. + console.info(`audio error called, errCode is ${error.code}`); // Print the error code. + console.info(`audio error called, errMessage is ${error.message}`); // Print the detailed description of the error type. +}); +// This event is reported when an error occurs during the retrieval of videoRecordState. +``` + +## VideoRecordState9+ + +Enumerates the video recording states. You can obtain the state through the **state** attribute. + +**System capability**: SystemCapability.Multimedia.Media.VideoRecorder + +| Name | Type | Description | +| -------- | ------ | ---------------------- | +| idle | string | The video recorder is idle. | +| prepared | string | The video recording parameters are set.| +| playing | string | Video recording is in progress. | +| paused | string | Video recording is paused. | +| stopped | string | Video recording is stopped. | +| error | string | Video recording is in the error state. | + +## VideoRecorderConfig9+ + +Describes the video recording parameters. + +**System capability**: SystemCapability.Multimedia.Media.VideoRecorder + +| Name | Type | Mandatory| Description | +| --------------- | ---------------------------------------------- | ---- | ------------------------------------------------------------ | +| audioSourceType | [AudioSourceType](#audiosourcetype9) | Yes | Type of the audio source for video recording. | +| videoSourceType | [VideoSourceType](#videosourcetype9) | Yes | Type of the video source for video recording. | +| profile | [VideoRecorderProfile](#videorecorderprofile9) | Yes | Video recording profile. | +| rotation | number | No | Rotation angle of the recorded video. | +| location | [Location](#location) | No | Geographical location of the recorded video. | +| url | string | Yes | Video output URL. Supported: fd://xx (fd number)
![](figures/en-us_image_url.png)
The file must be created by the caller and granted with proper permissions.| + +## AudioSourceType9+ + +Enumerates the audio source types for video recording. + +**System capability**: SystemCapability.Multimedia.Media.VideoRecorder + +| Name | Value | Description | +| ------------------------- | ---- | ---------------------- | +| AUDIO_SOURCE_TYPE_DEFAULT | 0 | Default audio input source.| +| AUDIO_SOURCE_TYPE_MIC | 1 | Mic audio input source. | + +## VideoSourceType9+ + +Enumerates the video source types for video recording. + +**System capability**: SystemCapability.Multimedia.Media.VideoRecorder + +| Name | Value | Description | +| ----------------------------- | ---- | ------------------------------- | +| VIDEO_SOURCE_TYPE_SURFACE_YUV | 0 | The input surface carries raw data.| +| VIDEO_SOURCE_TYPE_SURFACE_ES | 1 | The input surface carries ES data. | + +## VideoRecorderProfile9+ + +Describes the video recording profile. + +**System capability**: SystemCapability.Multimedia.Media.VideoRecorder + +| Name | Type | Mandatory| Description | +| ---------------- | -------------------------------------------- | ---- | ---------------- | +| audioBitrate | number | Yes | Audio encoding bit rate.| +| audioChannels | number | Yes | Number of audio channels.| +| audioCodec | [CodecMimeType](#codecmimetype8) | Yes | Audio encoding format. | +| audioSampleRate | number | Yes | Audio sampling rate. | +| fileFormat | [ContainerFormatType](#containerformattype8) | Yes | Container format of a file.| +| videoBitrate | number | Yes | Video encoding bit rate.| +| videoCodec | [CodecMimeType](#codecmimetype8) | Yes | Video encoding format. | +| videoFrameWidth | number | Yes | Width of the recorded video frame.| +| videoFrameHeight | number | Yes | Height of the recorded video frame.| +| videoFrameRate | number | Yes | Video frame rate. | + ## ContainerFormatType8+ Enumerates the container format types (CFTs). -- GitLab