提交 9e64c0ff 编写于 作者: W wusongqing

updated docs

Signed-off-by: Nwusongqing <wusongqing@huawei.com>
上级 1632d97f
# Audio Management # Audio Management
> **NOTE** > **NOTE**<br/>
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
This module provides the following common audio-related functions: This module provides the following common audio-related functions:
- [AudioManager](#audiomanager): Audio management. - [AudioManager](#audiomanager): audio management.
- [AudioRenderer](#audiorenderer8): Audio rendering, used to play Pulse Code Modulation (PCM) audio data. - [AudioRenderer](#audiorenderer8): audio rendering, used to play Pulse Code Modulation (PCM) audio data.
- [AudioCapturer](#audiocapturer8): Audio capture, used to record PCM audio data. - [AudioCapturer](#audiocapturer8): audio capture, used to record PCM audio data.
## Modules to Import ## Modules to Import
...@@ -15,22 +15,21 @@ This module provides the following common audio-related functions: ...@@ -15,22 +15,21 @@ This module provides the following common audio-related functions:
import audio from '@ohos.multimedia.audio'; import audio from '@ohos.multimedia.audio';
``` ```
## audio.getAudioManager ## audio.getAudioManager
getAudioManager(): AudioManager getAudioManager(): AudioManager
Obtains an **AudioManager** instance. Obtains an **AudioManager** instance.
**System capability:** SystemCapability.Multimedia.Audio.Core **System capability**: SystemCapability.Multimedia.Audio.Core
**Return value:**
**Return value**
| Type | Description | | Type | Description |
| ----------------------------- | -------------------- | | ----------------------------- | ------------ |
| [AudioManager](#audiomanager) | AudioManager object. | | [AudioManager](#audiomanager) | **AudioManager** instance.|
**Example:**
**Example**
``` ```
var audioManager = audio.getAudioManager(); var audioManager = audio.getAudioManager();
``` ```
...@@ -39,17 +38,18 @@ var audioManager = audio.getAudioManager(); ...@@ -39,17 +38,18 @@ var audioManager = audio.getAudioManager();
createAudioRenderer(options: AudioRendererOptions, callback: AsyncCallback\<AudioRenderer>): void createAudioRenderer(options: AudioRendererOptions, callback: AsyncCallback\<AudioRenderer>): void
Obtains an **AudioRenderer** instance. This API uses an asynchronous callback to return the renderer instance. Obtains an **AudioRenderer** instance. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description |
| :--------- | :---------------------------------------------- | :-------- | :--------------------------------------------------- | | Name | Type | Mandatory| Description |
| -------- | ----------------------------------------------- | ---- | ---------------- |
| options | [AudioRendererOptions](#audiorendereroptions8) | Yes | Renderer configurations. | | options | [AudioRendererOptions](#audiorendereroptions8) | Yes | Renderer configurations. |
| callback | AsyncCallback<[AudioRenderer](#audiorenderer8)> | Yes | Callback used to return the audio renderer instance. | | callback | AsyncCallback<[AudioRenderer](#audiorenderer8)> | Yes | Callback used to return the **AudioRenderer** instance.|
**Example:** **Example**
``` ```
import audio from '@ohos.multimedia.audio'; import audio from '@ohos.multimedia.audio';
...@@ -81,26 +81,28 @@ audio.createAudioRenderer(audioRendererOptions,(err, data) => { ...@@ -81,26 +81,28 @@ audio.createAudioRenderer(audioRendererOptions,(err, data) => {
} }
}); });
``` ```
## audio.createAudioRenderer<sup>8+</sup> ## audio.createAudioRenderer<sup>8+</sup>
createAudioRenderer(options: AudioRendererOptions): Promise<AudioRenderer> createAudioRenderer(options: AudioRendererOptions): Promise<AudioRenderer\>
Obtains an **AudioRenderer** instance. This API uses a promise to return the renderer instance. Obtains an **AudioRenderer** instance. 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 |
| :--------- | :--------------------------------------------- | :-------- | :---------------------------|
| options | [AudioRendererOptions](#audiorendereroptions8) | Yes | Renderer configurations. |
**Return value:** | Name | Type | Mandatory| Description |
| :------ | :--------------------------------------------- | :--- | :----------- |
| options | [AudioRendererOptions](#audiorendereroptions8) | Yes | Renderer configurations.|
**Return value**
| Type | Description | | Type | Description |
| ----------------------------------------- | --------------------------------------------------- | | ----------------------------------------- | ---------------- |
| Promise<[AudioRenderer](#audiorenderer8)> | Promise used to return the audio renderer instance. | | Promise<[AudioRenderer](#audiorenderer8)> | Promise used to return the **AudioRenderer** instance.|
**Example:** **Example**
``` ```
import audio from '@ohos.multimedia.audio'; import audio from '@ohos.multimedia.audio';
...@@ -136,17 +138,18 @@ audio.createAudioRenderer(audioRendererOptions).then((data) => { ...@@ -136,17 +138,18 @@ audio.createAudioRenderer(audioRendererOptions).then((data) => {
createAudioCapturer(options: AudioCapturerOptions, callback: AsyncCallback<AudioCapturer\>): void createAudioCapturer(options: AudioCapturerOptions, callback: AsyncCallback<AudioCapturer\>): void
Obtains an **AudioCapturer** instance. This API uses an asynchronous callback to return the capturer instance. Obtains an **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Audio.Capturer
**System capability:** SystemCapability.Multimedia.Audio.Capturer **Parameters**
**Parameters:** | Name | Type | Mandatory| Description |
| Name | Type | Mandatory | Description | | :------- | :---------------------------------------------- | :--- | :--------------- |
| :--------- | :---------------------------------------------- | :-------- | :--------------------------------------------------- | | options | [AudioCapturerOptions](#audiocaptureroptions8) | Yes | Capturer configurations.|
| options | [AudioCapturerOptions](#audiocaptureroptions8) | Yes | Capturer configurations. | | callback | AsyncCallback<[AudioCapturer](#audiocapturer8)> | Yes | Callback used to return the **AudioCapturer** instance.|
| callback | AsyncCallback<[AudioCapturer](#audiocapturer8)> | Yes | Callback used to return the audio capturer instance. |
**Example:** **Example**
``` ```
import audio from '@ohos.multimedia.audio'; import audio from '@ohos.multimedia.audio';
...@@ -182,22 +185,23 @@ audio.createAudioCapturer(audioCapturerOptions,(err, data) => { ...@@ -182,22 +185,23 @@ audio.createAudioCapturer(audioCapturerOptions,(err, data) => {
createAudioCapturer(options: AudioCapturerOptions): Promise<AudioCapturer\> createAudioCapturer(options: AudioCapturerOptions): Promise<AudioCapturer\>
Obtains an **AudioCapturer** instance. This API uses a promise to return the capturer instance. Obtains an **AudioCapturer** instance. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Audio.Capturer
**System capability:** SystemCapability.Multimedia.Audio.Capturer **Parameters**
**Parameters:** | Name | Type | Mandatory| Description |
| Name | Type | Mandatory | Description | | :------ | :--------------------------------------------- | :--- | :--------------- |
| :--------- | :-------------------------------------------- | :-------- | :-------------------------- | | options | [AudioCapturerOptions](#audiocaptureroptions8) | Yes | Capturer configurations.|
| options | [AudioCapturerOptions](#audiocaptureroptions8) | Yes | Capturer configurations. |
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ----------------------------------------- | --------------------------------------------------- | | ----------------------------------------- | -------------- |
| Promise<[AudioCapturer](#audiocapturer8)> | Promise used to return the audio capturer instance. | | Promise<[AudioCapturer](#audiocapturer8)> | Promise used to return the **AudioCapturer** instance.|
**Example:** **Example**
``` ```
import audio from '@ohos.multimedia.audio'; import audio from '@ohos.multimedia.audio';
...@@ -220,7 +224,7 @@ var audioCapturerOptions = { ...@@ -220,7 +224,7 @@ var audioCapturerOptions = {
} }
var audioCapturer; var audioCapturer;
audio.createAudioCapturer(audioCapturerOptions).then((data) => { audio.createAudioRenderer(audioCapturerOptions).then((data) => {
audioCapturer = data; audioCapturer = data;
console.info('AudioCapturer Created : Success : Stream Type: SUCCESS'); console.info('AudioCapturer Created : Success : Stream Type: SUCCESS');
}).catch((err) => { }).catch((err) => {
...@@ -230,56 +234,58 @@ audio.createAudioCapturer(audioCapturerOptions).then((data) => { ...@@ -230,56 +234,58 @@ audio.createAudioCapturer(audioCapturerOptions).then((data) => {
## AudioVolumeType ## AudioVolumeType
Enumerates audio stream types. Enumerates the audio stream types.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
| Name | Default Value | Description | | Name | Default Value| Description |
| ---------------------------- | -------------- | --------------------------------- | | ---------------------------- | ------ | ---------- |
| VOICE_CALL<sup>8+</sup> | 0 | Audio stream for voice calls. | | VOICE_CALL<sup>8+</sup> | 0 | Audio stream for voice calls.|
| RINGTONE | 2 | Audio stream for ringtones. | | RINGTONE | 2 | Audio stream for ringtones. |
| MEDIA | 3 | Audio stream for media purpose. | | MEDIA | 3 | Audio stream for media purpose. |
| VOICE_ASSISTANT<sup>8+</sup> | 9 | Audio stream for voice assistant. | | VOICE_ASSISTANT<sup>8+</sup> | 9 | Audio stream for voice assistant.|
## DeviceFlag ## DeviceFlag
Enumerates audio device flags. Enumerates the audio device flags.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
| Name | Default Value | Description | | Name | Default Value| Description |
| ------------------- | ------------- | -------------- | | ------------------- | ------ | ---------- |
| OUTPUT_DEVICES_FLAG | 1 | Output device. | | OUTPUT_DEVICES_FLAG | 1 | Output device.|
| INPUT_DEVICES_FLAG | 2 | Input device. | | INPUT_DEVICES_FLAG | 2 | Input device.|
| ALL_DEVICES_FLAG | 3 | All devices. | | ALL_DEVICES_FLAG | 3 | All devices.|
## DeviceRole ## DeviceRole
Enumerates audio device roles. Enumerates the audio device roles.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
| Name | Default Value| Description |
| ------------- | ------ | -------------- |
| INPUT_DEVICE | 1 | Input role.|
| OUTPUT_DEVICE | 2 | Output role.|
| Name | Default Value | Description |
| ------------- | ------------- | ------------ |
| INPUT_DEVICE | 1 | Input role. |
| OUTPUT_DEVICE | 2 | Output role. |
## DeviceType ## DeviceType
Enumerates audio device types. Enumerates the audio device types.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
| Name | Default Value | Description | | Name | Default Value| Description |
| ---------------- | ------------- | ------------------------------------------------------------------------ | | ---------------- | ------ | --------------------------------------------------------- |
| INVALID | 0 | Invalid device. | | INVALID | 0 | Invalid device. |
| EARPIECE | 1 | Earpiece. | | EARPIECE | 1 | Earpiece. |
| SPEAKER | 2 | Speaker. | | SPEAKER | 2 | Speaker. |
| WIRED_HEADSET | 3 | Wired headset. | | WIRED_HEADSET | 3 | Wired headset with a microphone. |
| WIRED_HEADPHONES | 4 | Wired headset without microphone. | | WIRED_HEADPHONES | 4 | Wired headset without microphone. |
| BLUETOOTH_SCO | 7 | Bluetooth device using Synchronous Connection Oriented (SCO) links. | | BLUETOOTH_SCO | 7 | Bluetooth device using Synchronous Connection Oriented (SCO) links. |
| BLUETOOTH_A2DP | 8 | Bluetooth device using Advanced Audio Distribution Profile (A2DP) links. | | BLUETOOTH_A2DP | 8 | Bluetooth device using Advanced Audio Distribution Profile (A2DP) links.|
| MIC | 15 | Microphone. | | MIC | 15 | Microphone. |
| USB_HEADSET | 22 | USB Type-C headset. | | USB_HEADSET | 22 | USB Type-C headset. |
...@@ -287,203 +293,195 @@ Enumerates audio device types. ...@@ -287,203 +293,195 @@ Enumerates audio device types.
Enumerates the active device types. Enumerates the active device types.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
| Name | Default Value | Description | | Name | Default Value| Description |
| ------------- | ------------- | ---------------------------------------------------------------------- | | ------------- | ------ | ---------------------------------------------------- |
| SPEAKER | 2 | Speaker. | | SPEAKER | 2 | Speaker. |
| BLUETOOTH_SCO | 7 | Bluetooth device using the SCO links. | | BLUETOOTH_SCO | 7 | Bluetooth device using the SCO links.|
## AudioRingMode ## AudioRingMode
Enumerates ringer modes. Enumerates the ringer modes.
**System capability:** SystemCapability.Multimedia.Audio.Communication **System capability**: SystemCapability.Multimedia.Audio.Communication
| Name | Default Value | Description | | Name | Default Value| Description |
| ------------------- | ------------- | ---------------- | | ------------------- | ------ | ---------- |
| RINGER_MODE_SILENT | 0 | Silent mode. | | RINGER_MODE_SILENT | 0 | Silent mode.|
| RINGER_MODE_VIBRATE | 1 | Vibration mode. | | RINGER_MODE_VIBRATE | 1 | Vibration mode.|
| RINGER_MODE_NORMAL | 2 | Normal mode. | | RINGER_MODE_NORMAL | 2 | Normal mode.|
## AudioSampleFormat<sup>8+</sup> ## AudioSampleFormat<sup>8+</sup>
Enumerates the audio sample formats. Enumerate the audio sample formats.
**System capability:** SystemCapability.Multimedia.Audio.Core **System capability**: SystemCapability.Multimedia.Audio.Core
| Name | Default Value | Description | | Name | Default Value| Description |
| :-------------------- | :------------ | :------------------------------------ | | --------------------- | ------ | -------------------------- |
| SAMPLE_FORMAT_INVALID | -1 | Invalid format. | | SAMPLE_FORMAT_INVALID | -1 | Invalid format. |
| SAMPLE_FORMAT_U8 | 0 | Unsigned 8 bit integer. | | SAMPLE_FORMAT_U8 | 0 | Unsigned 8-bit integer. |
| SAMPLE_FORMAT_S16LE | 1 | Signed 16 bit integer, little endian. | | SAMPLE_FORMAT_S16LE | 1 | Signed 16-bit integer, little endian.|
| SAMPLE_FORMAT_S24LE | 2 | Signed 24 bit integer, little endian. | | SAMPLE_FORMAT_S24LE | 2 | Signed 24-bit integer, little endian.|
| SAMPLE_FORMAT_S32LE | 3 | Signed 32 bit integer, little endian. | | SAMPLE_FORMAT_S32LE | 3 | Signed 32-bit integer, little endian.|
## AudioChannel<sup>8+</sup> ## AudioChannel<sup>8+</sup>
Enumerates the audio channels. Enumerates the audio channels.
**System capability:** SystemCapability.Multimedia.Audio.Core **System capability**: SystemCapability.Multimedia.Audio.Core
| Name | Default Value | Description | | Name | Default Value | Description |
| :-------- | :------------ | :--------------- | | --------- | -------- | -------- |
| CHANNEL_1 | 0x1 << 0 | Channel count 1. | | CHANNEL_1 | 0x1 << 0 | Mono.|
| CHANNEL_2 | 0x1 << 1 | Channel count 2. | | CHANNEL_2 | 0x1 << 1 | Dual-channel.|
## AudioSamplingRate<sup>8+</sup> ## AudioSamplingRate<sup>8+</sup>
Enumerates the audio sampling rates. Enumerates the audio sampling rates.
**System capability:** SystemCapability.Multimedia.Audio.Core **System capability**: SystemCapability.Multimedia.Audio.Core
| Name | Default Value | Description | | Name | Default Value| Description |
| :---------------- | :------------ | :------------------- | | ----------------- | ------ | --------------- |
| SAMPLE_RATE_8000 | 8000 | Sampling rate 8000. | | SAMPLE_RATE_8000 | 8000 | The sampling rate is 8000. |
| SAMPLE_RATE_11025 | 11025 | Sampling rate 11025. | | SAMPLE_RATE_11025 | 11025 | The sampling rate is 11025.|
| SAMPLE_RATE_12000 | 12000 | Sampling rate 12000. | | SAMPLE_RATE_12000 | 12000 | The sampling rate is 12000.|
| SAMPLE_RATE_16000 | 16000 | Sampling rate 16000. | | SAMPLE_RATE_16000 | 16000 | The sampling rate is 16000.|
| SAMPLE_RATE_22050 | 22050 | Sampling rate 22050. | | SAMPLE_RATE_22050 | 22050 | The sampling rate is 22050.|
| SAMPLE_RATE_24000 | 24000 | Sampling rate 24000. | | SAMPLE_RATE_24000 | 24000 | The sampling rate is 24000.|
| SAMPLE_RATE_32000 | 32000 | Sampling rate 32000. | | SAMPLE_RATE_32000 | 32000 | The sampling rate is 32000.|
| SAMPLE_RATE_44100 | 44100 | Sampling rate 44100. | | SAMPLE_RATE_44100 | 44100 | The sampling rate is 44100.|
| SAMPLE_RATE_48000 | 48000 | Sampling rate 48000. | | SAMPLE_RATE_48000 | 48000 | The sampling rate is 48000.|
| SAMPLE_RATE_64000 | 64000 | Sampling rate 64000. | | SAMPLE_RATE_64000 | 64000 | The sampling rate is 64000.|
| SAMPLE_RATE_96000 | 96000 | Sampling rate 96000. | | SAMPLE_RATE_96000 | 96000 | The sampling rate is 96000.|
## AudioEncodingType<sup>8+</sup> ## AudioEncodingType<sup>8+</sup>
Enumerates the audio encoding types. Enumerates the audio encoding types.
**System capability:** SystemCapability.Multimedia.Audio.Core **System capability**: SystemCapability.Multimedia.Audio.Core
| Name | Default Value | Description | | Name | Default Value| Description |
| :-------------------- | :------------- | :---------------- | | --------------------- | ------ | --------- |
| ENCODING_TYPE_INVALID | -1 | Invalid. | | ENCODING_TYPE_INVALID | -1 | Invalid. |
| ENCODING_TYPE_RAW | 0 | PCM encoding. | | ENCODING_TYPE_RAW | 0 | PCM encoding.|
## ContentType ## ContentType
Enumerates the content types. Enumerates the audio content types.
**System capability:** SystemCapability.Multimedia.Audio.Core **System capability**: SystemCapability.Multimedia.Audio.Core
| 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_RINGTONE<sup>8+</sup> | 5 | Ringtone content. |
| Name | Default Value| Description |
| ---------------------------------- | ------ | ---------- |
| CONTENT_TYPE_UNKNOWN | 0 | Unknown content.|
| CONTENT_TYPE_SPEECH | 1 | Speech. |
| CONTENT_TYPE_MUSIC | 2 | Music. |
| CONTENT_TYPE_MOVIE | 3 | Movie. |
| CONTENT_TYPE_SONIFICATION | 4 | Sonification content.|
| CONTENT_TYPE_RINGTONE<sup>8+</sup> | 5 | Ringtone. |
## StreamUsage ## StreamUsage
Enumerates the stream usage. Enumerates the audio stream usage.
**System capability:** SystemCapability.Multimedia.Audio.Core
| Name | Default Value | Description | **System capability**: SystemCapability.Multimedia.Audio.Core
| :--------------------------------- | :------------ | :-------------------------------- |
| STREAM_USAGE_UNKNOWN | 0 | Unknown usage. |
| STREAM_USAGE_MEDIA | 1 | Media usage. |
| STREAM_USAGE_VOICE_COMMUNICATION | 2 | Voice communication usage. |
| STREAM_USAGE_NOTIFICATION_RINGTONE | 6 | Notification or ringtone usage. |
| Name | Default Value| Description |
| ---------------------------------- | ------ | ---------- |
| STREAM_USAGE_UNKNOWN | 0 | Unknown usage.|
| STREAM_USAGE_MEDIA | 1 | Used for media. |
| STREAM_USAGE_VOICE_COMMUNICATION | 2 | Used for voice communication.|
| STREAM_USAGE_NOTIFICATION_RINGTONE | 6 | Used for notification.|
## AudioState<sup>8+</sup> ## AudioState<sup>8+</sup>
Enumerates the audio states. Enumerates the audio states.
**System capability:** SystemCapability.Multimedia.Audio.Core **System capability**: SystemCapability.Multimedia.Audio.Core
| Name | Default Value | Description | | Name | Default Value| Description |
| :------------- | :------------ | :--------------------------- | | -------------- | ------ | ---------------- |
| STATE_INVALID | -1 | Invalid state. | | STATE_INVALID | -1 | Invalid state. |
| STATE_NEW | 0 | Creating new instance state. | | STATE_NEW | 0 | Creating instance state.|
| STATE_PREPARED | 1 | Prepared state. | | STATE_PREPARED | 1 | Prepared. |
| STATE_RUNNING | 2 | Running state. | | STATE_RUNNING | 2 | Running. |
| STATE_STOPPED | 3 | Stopped state. | | STATE_STOPPED | 3 | Stopped. |
| STATE_RELEASED | 4 | Released state. | | STATE_RELEASED | 4 | Released. |
| STATE_PAUSED | 5 | Paused state. | | STATE_PAUSED | 5 | Paused. |
## AudioRendererRate<sup>8+</sup> ## AudioRendererRate<sup>8+</sup>
Enumerates the audio renderer rates. Enumerates the audio renderer rates.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
| Name | Default Value | Description | | Name | Default Value| Description |
| :----------------- | :------------ | :------------ | | ------------------ | ------ | ---------- |
| RENDER_RATE_NORMAL | 0 | Normal rate. | | RENDER_RATE_NORMAL | 0 | Normal rate.|
| RENDER_RATE_DOUBLE | 1 | Double rate. | | RENDER_RATE_DOUBLE | 1 | Double rate. |
| RENDER_RATE_HALF | 2 | Half rate. | | RENDER_RATE_HALF | 2 | Half rate. |
## InterruptType ## InterruptType
Enumerates the interrupt types. Enumerates the audio interruption types.
**System capability:** SystemCapability.Multimedia.Audio.Renderer
| Name | Default Value | Description | **System capability**: SystemCapability.Multimedia.Audio.Renderer
| :------------------- | :------------ | :----------------------------------- |
| INTERRUPT_TYPE_BEGIN | 1 | Audio playback interruption started. |
| INTERRUPT_TYPE_END | 2 | Audio playback interruption ended. |
| Name | Default Value| Description |
| -------------------- | ------ | ---------------------- |
| INTERRUPT_TYPE_BEGIN | 1 | Audio interruption started.|
| INTERRUPT_TYPE_END | 2 | Audio interruption ended.|
## InterruptForceType<sup>9+</sup> ## InterruptForceType<sup>9+</sup>
Enumerates the interrupt force types. Enumerates the types of force that causes audio interruption.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
| Name | Default Value | Description | | Name | Default Value| Description |
| :-------------- | :------------ | :----------------------------------------- | | --------------- | ------ | ------------------------------------ |
| INTERRUPT_FORCE | 0 | Forced action taken by system. | | INTERRUPT_FORCE | 0 | Forced action taken by the system. |
| INTERRUPT_SHARE | 1 | App can choose to take action or ignore. | | INTERRUPT_SHARE | 1 | The application can choose to take action or ignore.|
## InterruptHint ## InterruptHint
Enumerates the interrupt hints. Enumerates the hints provided along with audio interruption.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
| Name | Default Value | Description | | Name | Default Value| Description |
| :--------------------------------- | :------------ | :--------------------------- | | ---------------------------------- | ------ | -------------------------------------------- |
| INTERRUPT_HINT_NONE<sup>8+</sup> | 0 | None. | | INTERRUPT_HINT_NONE<sup>8+</sup> | 0 | None. |
| INTERRUPT_HINT_RESUME | 1 | Resume the playback. | | INTERRUPT_HINT_RESUME | 1 | Resume the playback. |
| INTERRUPT_HINT_PAUSE | 2 | Paused/Pause the playback. | | INTERRUPT_HINT_PAUSE | 2 | Paused/Pause the playback. |
| INTERRUPT_HINT_STOP | 3 | Stopped/Stop the playback. | | INTERRUPT_HINT_STOP | 3 | Stopped/Stop the playback. |
| INTERRUPT_HINT_DUCK | 4 | Ducked the playback. | | INTERRUPT_HINT_DUCK | 4 | Ducked the playback. (In ducking, the audio volume is reduced, but not silenced.)|
| INTERRUPT_HINT_UNDUCK<sup>8+</sup> | 5 | Unducked the playback. | | INTERRUPT_HINT_UNDUCK<sup>8+</sup> | 5 | Unducked the playback. |
## InterruptActionType ## InterruptActionType
Enumerates the interrupt event return types. Enumerates the returned event types for audio interruption events.
This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR. **System capability**: SystemCapability.Multimedia.Audio.Renderer
**System capability:** SystemCapability.Multimedia.Audio.Renderer | Name | Default Value| Description |
| -------------- | ------ | ------------------ |
| Name | Default Value | Description | | TYPE_ACTIVATED | 0 | Focus gain event.|
| :------------- | :------------ | :---------------------------------------- | | TYPE_INTERRUPT | 1 | Audio interruption event.|
| TYPE_ACTIVATED | 0 | Audio interrupt activated. |
| TYPE_INTERRUPT | 1 | Audio interrupted. |
## AudioStreamInfo<sup>8+</sup> ## AudioStreamInfo<sup>8+</sup>
Describes audio stream information. Describes audio stream information.
**System capability:** SystemCapability.Multimedia.Audio.Core **System capability**: SystemCapability.Multimedia.Audio.Core
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------------ | :---------------------------------------- | :-------- | :-------------------- | | ------------ | ---------------------------------------- | ---- | ------------------ |
| samplingRate | [AudioSamplingRate](#audiosamplingrate8) | Yes | Sampling rate. | | samplingRate | [AudioSamplingRate](#audiosamplingrate8) | Yes | Audio sampling rate.|
| channels | [AudioChannel](#audiochannel8) | Yes | Audio channels. | | channels | [AudioChannel](#audiochannel8) | Yes | Number of audio channels.|
| sampleFormat | [AudioSampleFormat](#audiosampleformat8) | Yes | Audio sample format. | | sampleFormat | [AudioSampleFormat](#audiosampleformat8) | Yes | Audio sample format. |
| encodingType | [AudioEncodingType](#audioencodingtype8) | Yes | Audio encoding type. | | encodingType | [AudioEncodingType](#audioencodingtype8) | Yes | Audio encoding type. |
...@@ -491,171 +489,166 @@ Describes audio stream information. ...@@ -491,171 +489,166 @@ Describes audio stream information.
Describes audio renderer information. Describes audio renderer information.
**System capability:** SystemCapability.Multimedia.Audio.Core **System capability**: SystemCapability.Multimedia.Audio.Core
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------------ | :-------------------------- | :-------- | :-------------------- | | ------------- | --------------------------- | ---- | ---------------- |
| contentType | [ContentType](#contenttype) | Yes | Content type. | | content | [ContentType](#contenttype) | Yes | Audio content type. |
| usage | [StreamUsage](#streamusage) | Yes | Stream usage. | | usage | [StreamUsage](#streamusage) | Yes | Audio stream usage.|
| rendererFlags | number | Yes | Audio renderer flags. | | rendererFlags | number | Yes | Audio renderer flags.|
## AudioRendererOptions<sup>8+</sup> ## AudioRendererOptions<sup>8+</sup>
Describes audio renderer configuration options. Describes audio renderer configurations.
**System capability:** SystemCapability.Multimedia.Audio.Renderer
| Name | Type | Mandatory | Description |
| :------------ | :-----------------------------------------| :-------- | :-------------------- |
| streamInfo | [AudioStreamInfo](#audiostreaminfo8) | Yes | Stream information. |
| rendererInfo | [AudioRendererInfo](#audiorendererinfo8) | Yes | Renderer information. |
## AudioCapturerInfo<sup>8+</sup><a name="audiocapturerinfo"></a>
Describes audio capturer information.
**System capability:** SystemCapability.Multimedia.Audio.Core
| Name | Type | Mandatory | Description |
| :---------------| :------------------------- | :-------- | :-------------------- |
| source | [SourceType](#sourcetype) | Yes | Audio source type. |
| capturerFlags | number | Yes | Audio capturer flags. |
## AudioCapturerOptions<sup>8+</sup>
Describes audio capturer configuration options.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Renderer
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------------ | :-----------------------------------------| :-------- | :-------------------- | | ------------ | ---------------------------------------- | ---- | ---------------- |
| streamInfo | [AudioStreamInfo](#audiostreaminfo8) | Yes | Stream information. | | streamInfo | [AudioStreamInfo](#audiostreaminfo8) | Yes | Audio stream information.|
| capturerInfo | [AudioCapturerInfo](#audiocapturerinfo8) | Yes | Capturer information. | | rendererInfo | [AudioRendererInfo](#audiorendererinfo8) | Yes | Audio renderer information.|
## InterruptEvent<sup>9+</sup> ## InterruptEvent<sup>9+</sup>
Describes the interrupt event received by the app when playback is interrupted. Describes the interruption event received by the application when playback is interrupted.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :-------- | :-------------------------------------------- | :-------- | :---------------------------------------------------------------- | | --------- | ------------------------------------------ | ---- | ------------------------------------ |
| eventType | [InterruptType](#interrupttype) | Yes | Whether the interruption has started or finished. | | eventType | [InterruptType](#interrupttype) | Yes | Whether the interruption has started or ended. |
| forceType | [InterruptForceType](#interruptforcetype9) | Yes | Whether the action is taken by system or to be taken by the app. | | forceType | [InterruptForceType](#interruptforcetype9) | Yes | Whether the interruption is taken by the system or to be taken by the application.|
| hintType | [InterruptHint](#interrupthint) | Yes | Type of action. | | hintType | [InterruptHint](#interrupthint) | Yes | Hint provided along the interruption. |
## AudioInterrupt ## AudioInterrupt
The parameters passed in by the audio listener event. Describes input parameters of audio interruption events.
This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR. **System capability**: SystemCapability.Multimedia.Audio.Renderer
**System capability:** SystemCapability.Multimedia.Audio.Renderer | Name | Type | Mandatory| Description |
| Name | Type | Mandatory | Description |
| --------------- | --------------------------- | ---- | ------------------------------------------------------------ | | --------------- | --------------------------- | ---- | ------------------------------------------------------------ |
| streamUsage | [StreamUsage](#streamusage) | Yes | Audio stream usage type. | | streamUsage | [StreamUsage](#streamusage) | Yes | Audio stream usage. |
| contentType | [ContentType](#contenttype) | Yes | Audio interrupt media type. | | contentType | [ContentType](#contenttype) | Yes | Audio content type. |
| pauseWhenDucked | boolean | Yes | Whether audio playback can be paused when audio is interrupted (true means audio playback can be paused during audio interruptions and false means the opposite). | | pauseWhenDucked | boolean | Yes | Whether audio playback can be paused during audio interruption. The value **true** means that audio playback can be paused during audio interruption, and **false** means the opposite.|
## InterruptAction ## InterruptAction
Callback method for the audio interrupt or audio interrupt activated event. Describes the callback invoked for audio interruption or focus gain events.
This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ------------------------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ | | ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ |
| actionType | [InterruptActionType](#interruptactiontype) | Yes | Event return type. TYPE_ACTIVATED is the audio interrupt activated event, and TYPE_INTERRUPT is the audio interrupt event. | | actionType | [InterruptActionType](#interruptactiontype) | Yes | Returned event type. The value **TYPE_ACTIVATED** means the focus gain event, and **TYPE_INTERRUPT** means the audio interruption event.|
| type | [InterruptType](#interrupttype) | No | Interrupt event type. | | type | [InterruptType](#interrupttype) | No | Type of the audio interruption event. |
| hint | [InterruptHint](#interrupthint) | No | Interrupt event prompts. | | hint | [InterruptHint](interrupthint) | No | Hint provided along with the audio interruption event. |
| activated | boolean | No | Acquire/release focus. true indicates that the focus acquisition/release is successful, and false indicates that the focus acquisition/release fails. | | activated | boolean | No | Whether the focus is gained or released. The value **true** means that the focus is gained or released, and **false** means that the focus fails to be gained or released.|
## VolumeEvent<sup>8+</sup> ## VolumeEvent<sup>8+</sup>
Describes the volume event received by the app when the volume is changed.
Describes the event received by the application when the volume is changed.
This is a system API and cannot be called by third-party applications. This is a system API and cannot be called by third-party applications.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :--------- | :---------------------------------- | :-------- | :--------------------------------------- | | ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Volume type of the current stream. | | volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
| volume | number | Yes | Volume level. | | volume | number | Yes | Volume level. The value range can be obtained by calling **getMinVolume** and **getMaxVolume**.|
| updateUi | boolean | Yes | Whether to show the volume change in UI. | | updateUi | boolean | Yes | Whether to show the volume change in UI. |
## DeviceChangeAction ## DeviceChangeAction
Describes the device change type and device information. Describes the device connection status and device information.
**System capability:** SystemCapability.Multimedia.Audio.Device
| Name | Type | Mandatory | Description | **System capability**: SystemCapability.Multimedia.Audio.Device
| :------------------ | :------------------------------------------------ | :-------- | :------------------ |
| type | [DeviceChangeType](#devicechangetype) | Yes | Device change type. |
| deviceDescriptors | [AudioDeviceDescriptors](#audiodevicedescriptors) | Yes | Device information. |
| Name | Type | Mandatory| Description |
| :---------------- | :------------------------------------------------ | :--- | :----------------- |
| type | [DeviceChangeType](#DeviceChangeType) | Yes | Device connection status.|
| deviceDescriptors | [AudioDeviceDescriptors](#AudioDeviceDescriptors) | Yes | Device information. |
## DeviceChangeType ## DeviceChangeType
Enumerates device change types. Enumerates the device connection statuses.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
| Name | Default Value | Description | | Name | Default Value| Description |
| :--------------------- | :------------ | :-------------------- | | :--------- | :----- | :------------- |
| CONNECT | 0 | Device connection. | | CONNECT | 0 | Connected. |
| DISCONNECT | 1 | Device disconnection. | | DISCONNECT | 1 | Disconnected.|
## SourceType<sup>8+</sup><a name="sourcetype"></a> ## AudioCapturerOptions<sup>8+</sup>
Enumerates source types. Describes audio capturer configurations.
**System capability:** SystemCapability.Multimedia.Audio.Core **System capability**: SystemCapability.Multimedia.Audio.Capturer
| Name | Default Value | Description | | Name | Type | Mandatory| Description |
| :----------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------ | :------------------------------- | | ------------ | --------------------------------------- | ---- | ---------------- |
| SOURCE_TYPE_INVALID | -1 | Invalid source type. | | streamInfo | [AudioStreamInfo](#audiostreaminfo8) | Yes | Audio stream information.|
| SOURCE_TYPE_MIC | 0 | Mic source type. | | capturerInfo | [AudioCapturerInfo](#audiocapturerinfo) | Yes | Audio capturer information.|
| 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. |
## AudioCapturerInfo<sup>8+</sup><a name="audiocapturerinfo"></a>
Describes audio capturer information.
**System capability**: SystemCapability.Multimedia.Audio.Core
| Name | Type | Mandatory| Description |
| :------------ | :------------------------ | :--- | :--------------- |
| source | [SourceType](#sourcetype) | Yes | Audio source type. |
| capturerFlags | number | Yes | Audio capturer flags.|
## SourceType<sup>8+</sup><a name="sourcetype"></a>
Enumerates the audio source types.
**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.|
## AudioScene<sup>8+</sup><a name="audioscene"></a> ## AudioScene<sup>8+</sup><a name="audioscene"></a>
Enumerates audio scenes. Enumerates the audio scenes.
**System capability:** SystemCapability.Multimedia.Audio.Communication **System capability**: SystemCapability.Multimedia.Audio.Communication
| Name | Default Value | Description | | Name | Default Value| Description |
| :------------------------------------------------------------------------------------ | :------------ | :---------------------- | | :--------------------- | :----- | :-------------------------------------------- |
| AUDIO_SCENE_DEFAULT | 0 | Default audio scene. | | AUDIO_SCENE_DEFAULT | 0 | Default audio scene. |
| AUDIO_SCENE_RINGING(system API, not supported by third-party applications) | 1 | Ringing audio scene. | | AUDIO_SCENE_RINGING | 1 | Ringing audio scene.<br>This is a system API and cannot be called by third-party applications.|
| AUDIO_SCENE_PHONE_CALL(system API, not supported by third-party applications) | 2 | Phone call audio scene. | | AUDIO_SCENE_PHONE_CALL | 2 | Phone call audio scene.<br>This is a system API and cannot be called by third-party applications.|
| AUDIO_SCENE_VOICE_CHAT | 3 | Voice chat audio scene. | | AUDIO_SCENE_VOICE_CHAT | 3 | Voice chat audio scene. |
## AudioManager ## AudioManager
Implements audio volume and audio device management. Before calling the interface of AudioManager, you need to create an instance through [getAudioManager](#audiogetaudiomanager). Implements audio volume and audio device management. Before calling any API in **AudioManager**, you must use [getAudioManager](#audiogetaudiomanager) to create an **AudioManager** instance.
### setVolume ### setVolume
setVolume\(volumeType: AudioVolumeType, volume: number, callback: AsyncCallback<void\>\): void setVolume(volumeType: AudioVolumeType, volume: number, callback: AsyncCallback&lt;void&gt;): void
Sets the volume for a stream. This API uses an asynchronous callback to return the result. Sets the volume for a stream. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------- | --------- | ---------------------------------------------------------------------------------------- | | ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Volume stream type. | | volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
| volume | number | Yes | Volume to set. The value range can be obtained by calling getMinVolume and getMaxVolume. | | volume | number | Yes | Volume to set. The value range can be obtained by calling **getMinVolume** and **getMaxVolume**.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. |
**Example:** **Example**
``` ```
audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10, (err) => { audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10, (err) => {
...@@ -666,28 +659,29 @@ audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10, (err) => { ...@@ -666,28 +659,29 @@ audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10, (err) => {
console.log('Callback invoked to indicate a successful volume setting.'); console.log('Callback invoked to indicate a successful volume setting.');
}); });
``` ```
### setVolume ### setVolume
setVolume\(volumeType: AudioVolumeType, volume: number\): Promise<void\> setVolume(volumeType: AudioVolumeType, volume: number): Promise&lt;void&gt;
Sets the volume for a stream. This API uses a promise to return the result. Sets the volume for a stream. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------- | --------- | ---------------------------------------------------------------------------------------- | | ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Volume stream type. | | volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
| volume | number | Yes | Volume to set. The value range can be obtained by calling getMinVolume and getMaxVolume. | | volume | number | Yes | Volume to set. The value range can be obtained by calling **getMinVolume** and **getMaxVolume**.|
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ----------------------------------- | | ------------------- | ----------------------------- |
| Promise<void> | Promise used to return the result. | | Promise&lt;void&gt; | Promise used to return the result.|
**Example:** **Example**
``` ```
audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(() => { audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(() => {
...@@ -697,20 +691,20 @@ audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(() => { ...@@ -697,20 +691,20 @@ audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(() => {
### getVolume ### getVolume
getVolume\(volumeType: AudioVolumeType, callback: AsyncCallback<number\>\): void getVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
Obtains the volume of a stream. This API uses an asynchronous callback to return the query result. Obtains the volume of a stream. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------- | --------- | ------------------------------------ | | ---------- | ----------------------------------- | ---- | ------------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | | volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
| callback | AsyncCallback<number> | Yes | Callback used to return the volume. | | callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the volume.|
**Example:** **Example**
``` ```
audioManager.getVolume(audio.AudioVolumeType.MEDIA, (err, value) => { audioManager.getVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
...@@ -722,28 +716,27 @@ audioManager.getVolume(audio.AudioVolumeType.MEDIA, (err, value) => { ...@@ -722,28 +716,27 @@ audioManager.getVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
}); });
``` ```
### getVolume ### getVolume
getVolume\(volumeType: AudioVolumeType\): Promise<number\> getVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
Obtains the volume of a stream. This API uses a promise to return the query result. Obtains the volume of a stream. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------- | --------- | ------------------------------------ | | ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | | volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type.|
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ----------------------------------- | | --------------------- | ------------------------- |
| Promise<number> | Promise used to return the result. | | Promise&lt;number&gt; | Promise used to return the volume.|
**Example:** **Example**
``` ```
audioManager.getVolume(audio.AudioVolumeType.MEDIA).then((value) => { audioManager.getVolume(audio.AudioVolumeType.MEDIA).then((value) => {
...@@ -753,20 +746,20 @@ audioManager.getVolume(audio.AudioVolumeType.MEDIA).then((value) => { ...@@ -753,20 +746,20 @@ audioManager.getVolume(audio.AudioVolumeType.MEDIA).then((value) => {
### getMinVolume ### getMinVolume
getMinVolume\(volumeType: AudioVolumeType, callback: AsyncCallback<number\>\): void getMinVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
Obtains the minimum volume allowed for a stream. This API uses an asynchronous callback to return the query result. Obtains the minimum volume allowed for a stream. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------- | --------- | ------------------------------------ | | ---------- | ----------------------------------- | ---- | ------------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | | volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
| callback | AsyncCallback<number> | Yes | Callback used to return the volume. | | callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the minimum volume.|
**Example:** **Example**
``` ```
audioManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err, value) => { audioManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
...@@ -778,28 +771,27 @@ audioManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err, value) => { ...@@ -778,28 +771,27 @@ audioManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
}); });
``` ```
### getMinVolume ### getMinVolume
getMinVolume\(volumeType: AudioVolumeType\): Promise<number\><a name="section41556389511"></a> getMinVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
Obtains the minimum volume allowed for a stream. This API uses a promise to return the query result. Obtains the minimum volume allowed for a stream. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------- | --------- | ------------------------------------ | | ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | | volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type.|
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ----------------------------------- | | --------------------- | ------------------------- |
| Promise<number> | Promise used to return the result. | | Promise&lt;number&gt; | Promise used to return the minimum volume.|
**Example:** **Example**
``` ```
audioManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value) => { audioManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value) => {
...@@ -809,20 +801,20 @@ audioManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value) => { ...@@ -809,20 +801,20 @@ audioManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value) => {
### getMaxVolume ### getMaxVolume
getMaxVolume\(volumeType: AudioVolumeType, callback: AsyncCallback<number\>\): void getMaxVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
Obtains the maximum volume allowed for a stream. This API uses an asynchronous callback to return the query result. Obtains the maximum volume allowed for a stream. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------- | --------- | ------------------------------------ | | ---------- | ----------------------------------- | ---- | ---------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | | volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
| callback | AsyncCallback<number> | Yes | Callback used to return the volume. | | callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the maximum volume.|
**Example:** **Example**
``` ```
audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA, (err, value) => { audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
...@@ -834,28 +826,27 @@ audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA, (err, value) => { ...@@ -834,28 +826,27 @@ audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
}); });
``` ```
### getMaxVolume ### getMaxVolume
getMaxVolume\(volumeType: AudioVolumeType\): Promise<number\> getMaxVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
Obtains the maximum volume allowed for a stream. This API uses a promise to return the query result. Obtains the maximum volume allowed for a stream. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------- | --------- | ------------------------------------ | | ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | | volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type.|
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ----------------------------------- | | --------------------- | ----------------------------- |
| Promise<number> | Promise used to return the result. | | Promise&lt;number&gt; | Promise used to return the maximum volume.|
**Example:** **Example**
``` ```
audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data) => { audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data) => {
...@@ -865,21 +856,21 @@ audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data) => { ...@@ -865,21 +856,21 @@ audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data) => {
### mute ### mute
mute\(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback<void\>\): void mute(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback&lt;void&gt;): void
Mutes a stream. This API uses an asynchronous callback to return the result. Mutes or unmutes a stream. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------- | --------- | ------------------------------------------------------------------------------------------ | | ---------- | ----------------------------------- | ---- | ------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | | volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
| mute | boolean | Yes | Mute status to set. The value true means to mute the stream, and false means the opposite. | | mute | boolean | Yes | Mute status to set. The value **true** means to mute the stream, and **false** means the opposite.|
| callback | AsyncCallback<number> | Yes | Callback used to return the volume. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. |
**Example:** **Example**
``` ```
audioManager.mute(audio.AudioVolumeType.MEDIA, true, (err) => { audioManager.mute(audio.AudioVolumeType.MEDIA, true, (err) => {
...@@ -891,29 +882,29 @@ audioManager.mute(audio.AudioVolumeType.MEDIA, true, (err) => { ...@@ -891,29 +882,29 @@ audioManager.mute(audio.AudioVolumeType.MEDIA, true, (err) => {
}); });
``` ```
### mute ### mute
mute\(volumeType: AudioVolumeType, mute: boolean\): Promise<void\> mute(volumeType: AudioVolumeType, mute: boolean): Promise&lt;void&gt;
Mutes a stream. This API uses a promise to return the result. Mutes or unmutes a stream. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------- | --------- | ------------------------------------------------------------------------------------------ | | ---------- | ----------------------------------- | ---- | ------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | | volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
| mute | boolean | Yes | Mute status to set. The value true means to mute the stream, and false means the opposite. | | mute | boolean | Yes | Mute status to set. The value **true** means to mute the stream, and **false** means the opposite.|
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ----------------------------------- | | ------------------- | ----------------------------- |
| Promise<void> | Promise used to return the result. | | Promise&lt;void&gt; | Promise used to return the result.|
**Example**
**Example:**
``` ```
audioManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => { audioManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => {
...@@ -924,20 +915,20 @@ audioManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => { ...@@ -924,20 +915,20 @@ audioManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => {
### isMute ### isMute
isMute\(volumeType: AudioVolumeType, callback: AsyncCallback<boolean\>\): void isMute(volumeType: AudioVolumeType, callback: AsyncCallback&lt;boolean&gt;): void
Checks whether a stream is muted. This API uses an asynchronous callback to return the query result. Checks whether a stream is muted. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------- | | ---------- | ----------------------------------- | ---- | ----------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | | volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
| callback | AsyncCallback<boolean> | Yes | Callback used to return the mute status of the stream. The value true means that the stream is muted, and false means the opposite.| | callback | AsyncCallback&lt;boolean&gt; | Yes | Callback used to return the mute status of the stream. The value **true** means that the stream is muted, and **false** means the opposite.|
**Example:** **Example**
``` ```
audioManager.isMute(audio.AudioVolumeType.MEDIA, (err, value) => { audioManager.isMute(audio.AudioVolumeType.MEDIA, (err, value) => {
...@@ -952,25 +943,25 @@ audioManager.isMute(audio.AudioVolumeType.MEDIA, (err, value) => { ...@@ -952,25 +943,25 @@ audioManager.isMute(audio.AudioVolumeType.MEDIA, (err, value) => {
### isMute ### isMute
isMute\(volumeType: AudioVolumeType\): Promise<boolean\> isMute(volumeType: AudioVolumeType): Promise&lt;boolean&gt;
Checks whether a stream is muted. This API uses a promise to return the result. Checks whether a stream is muted. This method uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------- | --------- | ------------------- | | ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | | volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type.|
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ----------------------------------------------------------------------------------------------------------------------------------- | | ---------------------- | ------------------------------------------------------ |
| Promise<boolean> | Promise used to return the mute status of the stream. The value true means that the stream is muted, and false means the opposite. | | Promise&lt;boolean&gt; | Promise used to return the mute status of the stream. The value **true** means that the stream is muted, and **false** means the opposite.|
**Example:** **Example**
``` ```
audioManager.isMute(audio.AudioVolumeType.MEDIA).then((value) => { audioManager.isMute(audio.AudioVolumeType.MEDIA).then((value) => {
...@@ -980,20 +971,20 @@ audioManager.isMute(audio.AudioVolumeType.MEDIA).then((value) => { ...@@ -980,20 +971,20 @@ audioManager.isMute(audio.AudioVolumeType.MEDIA).then((value) => {
### isActive ### isActive
isActive\(volumeType: AudioVolumeType, callback: AsyncCallback<boolean\>\) isActive(volumeType: AudioVolumeType, callback: AsyncCallback&lt;boolean&gt;): void
Checks whether a stream is active. This API uses an asynchronous callback to return the query result. Checks whether a stream is active. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------- | | ---------- | ----------------------------------- | ---- | ------------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | | volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
| callback | AsyncCallback<boolean> | Yes | Callback used to return the active status of the stream. The value true means that the stream is active, and false means the opposite.| | callback | AsyncCallback&lt;boolean&gt; | Yes | Callback used to return the active status of the stream. The value **true** means that the stream is active, and **false** means the opposite.|
**Example:** **Example**
``` ```
audioManager.isActive(audio.AudioVolumeType.MEDIA, (err, value) => { audioManager.isActive(audio.AudioVolumeType.MEDIA, (err, value) => {
...@@ -1005,28 +996,27 @@ audioManager.isActive(audio.AudioVolumeType.MEDIA, (err, value) => { ...@@ -1005,28 +996,27 @@ audioManager.isActive(audio.AudioVolumeType.MEDIA, (err, value) => {
}); });
``` ```
### isActive ### isActive
isActive\(volumeType: AudioVolumeType\): Promise<boolean\> isActive(volumeType: AudioVolumeType): Promise&lt;boolean&gt;
Checks whether a stream is active. This API uses a promise to return the query result. Checks whether a stream is active. This method uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------- | --------- | ------------------ | | ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | | volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type.|
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- | | ---------------------- | -------------------------------------------------------- |
| Promise<boolean> | Promise used to return the active status of the stream. The value true means that the stream is active, and false means the opposite. | | Promise&lt;boolean&gt; | Promise used to return the active status of the stream. The value **true** means that the stream is active, and **false** means the opposite.|
**Example:** **Example**
``` ```
audioManager.isActive(audio.AudioVolumeType.MEDIA).then((value) => { audioManager.isActive(audio.AudioVolumeType.MEDIA).then((value) => {
...@@ -1034,23 +1024,22 @@ audioManager.isActive(audio.AudioVolumeType.MEDIA).then((value) => { ...@@ -1034,23 +1024,22 @@ audioManager.isActive(audio.AudioVolumeType.MEDIA).then((value) => {
}); });
``` ```
### setRingerMode ### setRingerMode
setRingerMode\(mode: AudioRingMode, callback: AsyncCallback<void\>\): void setRingerMode(mode: AudioRingMode, callback: AsyncCallback&lt;void&gt;): void
Sets the ringer mode. This API uses an asynchronous callback to return the result. Sets the ringer mode. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Communication **System capability**: SystemCapability.Multimedia.Audio.Communication
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------- | --------- | ----------------------------------- | | -------- | ------------------------------- | ---- | ------------------------ |
| mode | [AudioRingMode](#audioringmode) | Yes | Ringer mode. | | mode | [AudioRingMode](#audioringmode) | Yes | Ringer mode. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result.|
**Example:** **Example**
``` ```
audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL, (err) => { audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL, (err) => {
...@@ -1062,28 +1051,27 @@ audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL, (err) => { ...@@ -1062,28 +1051,27 @@ audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL, (err) => {
}); });
``` ```
### setRingerMode ### setRingerMode
setRingerMode\(mode: AudioRingMode\): Promise<void\> setRingerMode(mode: AudioRingMode): Promise&lt;void&gt;
Sets the ringer mode. This API uses a promise to return the result. Sets the ringer mode. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Communication **System capability**: SystemCapability.Multimedia.Audio.Communication
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| ---------- | ----------------------------------- | --------- | ----------------------------------- | | ------ | ------------------------------- | ---- | -------------- |
| mode | [AudioRingMode](#audioringmode) | Yes | Ringer mode. | | mode | [AudioRingMode](#audioringmode) | Yes | Ringer mode.|
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ----------------------------------- | | ------------------- | ------------------------------- |
| Promise<void> | Promise used to return the result. | | Promise&lt;void&gt; | Promise used to return the result.|
**Example:** **Example**
``` ```
audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() => { audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() => {
...@@ -1094,19 +1082,19 @@ audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() => { ...@@ -1094,19 +1082,19 @@ audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() => {
### getRingerMode ### getRingerMode
getRingerMode\(callback: AsyncCallback<AudioRingMode\>\): void getRingerMode(callback: AsyncCallback&lt;AudioRingMode&gt;): void
Obtains the ringer mode. This API uses an asynchronous callback to return the query result. Obtains the ringer mode. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Communication **System capability**: SystemCapability.Multimedia.Audio.Communication
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------------------- | --------- | ---------------------------------------- | | -------- | ---------------------------------------------------- | ---- | ------------------------ |
| callback | AsyncCallback<[AudioRingMode](#audioringmode)> | Yes | Callback used to return the ringer mode. | | callback | AsyncCallback&lt;[AudioRingMode](#audioringmode)&gt; | Yes | Callback used to return the ringer mode.|
**Example:** **Example**
``` ```
audioManager.getRingerMode((err, value) => { audioManager.getRingerMode((err, value) => {
...@@ -1121,19 +1109,19 @@ audioManager.getRingerMode((err, value) => { ...@@ -1121,19 +1109,19 @@ audioManager.getRingerMode((err, value) => {
### getRingerMode ### getRingerMode
getRingerMode\(\): Promise<AudioRingMode\> getRingerMode(): Promise&lt;AudioRingMode&gt;
Obtains the ringer mode. This API uses a promise to return the query result. Obtains the ringer mode. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Communication **System capability**: SystemCapability.Multimedia.Audio.Communication
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ---------------------------------------------- | --------------------------------------- | | ---------------------------------------------- | ------------------------------- |
| Promise<[AudioRingMode](#audioringmode)> | Promise used to return the ringer mode. | | Promise&lt;[AudioRingMode](#audioringmode)&gt; | Promise used to return the ringer mode.|
**Example:** **Example**
``` ```
audioManager.getRingerMode().then((value) => { audioManager.getRingerMode().then((value) => {
...@@ -1141,24 +1129,23 @@ audioManager.getRingerMode().then((value) => { ...@@ -1141,24 +1129,23 @@ audioManager.getRingerMode().then((value) => {
}); });
``` ```
### setAudioParameter ### setAudioParameter
setAudioParameter\(key: string, value: string, callback: AsyncCallback<void\>\): void setAudioParameter(key: string, value: string, callback: AsyncCallback&lt;void&gt;): void
Sets an audio parameter. This API uses an asynchronous callback to return the result. Sets an audio parameter. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Core **System capability**: SystemCapability.Multimedia.Audio.Core
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| --------- | ----------------------| --------- | ------------------------------------- | | -------- | ------------------------- | ---- | ------------------------ |
| key | string | Yes | Key of the audio parameter to set. | | key | string | Yes | Key of the audio parameter to set. |
| value | string | Yes | Value of the audio parameter to set. | | value | string | Yes | Value of the audio parameter to set. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result.|
**Example:** **Example**
``` ```
audioManager.setAudioParameter('PBits per sample', '8 bit', (err) => { audioManager.setAudioParameter('PBits per sample', '8 bit', (err) => {
...@@ -1170,29 +1157,28 @@ audioManager.setAudioParameter('PBits per sample', '8 bit', (err) => { ...@@ -1170,29 +1157,28 @@ audioManager.setAudioParameter('PBits per sample', '8 bit', (err) => {
}); });
``` ```
### setAudioParameter ### setAudioParameter
setAudioParameter\(key: string, value: string\): Promise<void\> setAudioParameter(key: string, value: string): Promise&lt;void&gt;
Sets an audio parameter. This API uses a promise to return the result. Sets an audio parameter. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Core **System capability**: SystemCapability.Multimedia.Audio.Core
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| --------- | ----------------------| --------- | ------------------------------------- | | ------ | ------ | ---- | ---------------------- |
| key | string | Yes | Key of the audio parameter to set. | | key | string | Yes | Key of the audio parameter to set.|
| value | string | Yes | Value of the audio parameter to set. | | value | string | Yes | Value of the audio parameter to set.|
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ----------------------------------- | | ------------------- | ------------------------------- |
| Promise<void> | Promise used to return the result. | | Promise&lt;void&gt; | Promise used to return the result.|
**Example:** **Example**
``` ```
audioManager.setAudioParameter('PBits per sample', '8 bit').then(() => { audioManager.setAudioParameter('PBits per sample', '8 bit').then(() => {
...@@ -1200,23 +1186,22 @@ audioManager.setAudioParameter('PBits per sample', '8 bit').then(() => { ...@@ -1200,23 +1186,22 @@ audioManager.setAudioParameter('PBits per sample', '8 bit').then(() => {
}); });
``` ```
### getAudioParameter ### getAudioParameter
getAudioParameter\(key: string, callback: AsyncCallback<string\>\) getAudioParameter(key: string, callback: AsyncCallback&lt;string&gt;): void
Obtains the value of an audio parameter. This API uses an asynchronous callback to return the query result. Obtains the value of an audio parameter. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Core **System capability**: SystemCapability.Multimedia.Audio.Core
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| --------- | ----------------------| --------- | ---------------------------------------------------------- | | -------- | --------------------------- | ---- | ---------------------------- |
| key | string | Yes | Key of the audio parameter whose value is to be obtained. | | key | string | Yes | Key of the audio parameter whose value is to be obtained. |
| callback | AsyncCallback<string> | Yes | Callback used to return the value of the audio parameter. | | callback | AsyncCallback&lt;string&gt; | Yes | Callback used to return the value of the audio parameter.|
**Example:** **Example**
``` ```
audioManager.getAudioParameter('PBits per sample', (err, value) => { audioManager.getAudioParameter('PBits per sample', (err, value) => {
...@@ -1228,28 +1213,27 @@ audioManager.getAudioParameter('PBits per sample', (err, value) => { ...@@ -1228,28 +1213,27 @@ audioManager.getAudioParameter('PBits per sample', (err, value) => {
}); });
``` ```
### getAudioParameter ### getAudioParameter
getAudioParameter\(key: string\): Promise<string\> getAudioParameter(key: string): Promise&lt;string&gt;
Obtains the value of an audio parameter. This API uses a promise to return the query result. Obtains the value of an audio parameter. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Core **System capability**: SystemCapability.Multimedia.Audio.Core
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| --------- | ----------------------| --------- | ----------------------------------------------------------- | | ------ | ------ | ---- | ---------------------- |
| key | string | Yes | Key of the audio parameter whose value is to be obtained. | | key | string | Yes | Key of the audio parameter whose value is to be obtained.|
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ----------------------------------- | | --------------------- | ----------------------------------- |
| Promise<string> | Promise used to return the value of the audio parameter. | | Promise&lt;string&gt; | Promise used to return the value of the audio parameter.|
**Example:** **Example**
``` ```
audioManager.getAudioParameter('PBits per sample').then((value) => { audioManager.getAudioParameter('PBits per sample').then((value) => {
...@@ -1257,24 +1241,22 @@ audioManager.getAudioParameter('PBits per sample').then((value) => { ...@@ -1257,24 +1241,22 @@ audioManager.getAudioParameter('PBits per sample').then((value) => {
}); });
``` ```
### getDevices ### getDevices
getDevices\(deviceFlag: DeviceFlag, callback: AsyncCallback<AudioDeviceDescriptors\>\): void getDevices(deviceFlag: DeviceFlag, callback: AsyncCallback&lt;AudioDeviceDescriptors&gt;): void
Obtains the audio devices with a specific flag. This API uses an asynchronous callback to return the query result. Obtains the audio devices with a specific flag. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| --------- | ---------------------------------------------------------------- | --------- | ----------------------------------------- | | ---------- | ------------------------------------------------------------ | ---- | -------------------- |
| deviceFlag | [DeviceFlag](#deviceflag) | Yes | Audio device flag. | | deviceFlag | [DeviceFlag](#deviceflag) | Yes | Audio device flag. |
| callback | AsyncCallback<[AudioDeviceDescriptors](#audiodevicedescriptors)> | Yes | Callback used to return the device list. | | callback | AsyncCallback&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | Yes | Callback used to return the device list.|
**Example:**
**Example**
``` ```
audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err, value) => { audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err, value) => {
if (err) { if (err) {
...@@ -1285,29 +1267,27 @@ audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err, value) => { ...@@ -1285,29 +1267,27 @@ audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err, value) => {
}); });
``` ```
### getDevices ### getDevices
getDevices\(deviceFlag: DeviceFlag\): Promise<AudioDeviceDescriptors\> getDevices(deviceFlag: DeviceFlag): Promise&lt;AudioDeviceDescriptors&gt;
Obtains the audio devices with a specific flag. This API uses a promise to return the query result. Obtains the audio devices with a specific flag. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| --------- | --------------------------- | --------- | ------------------- | | ---------- | ------------------------- | ---- | ---------------- |
| deviceFlag | [DeviceFlag](#deviceflag) | Yes | Audio device flag. | | deviceFlag | [DeviceFlag](#deviceflag) | Yes | Audio device flag.|
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ----------------------------------------------------------- | ---------------------------------------- | | ------------------------------------------------------------ | ------------------------- |
| Promise<[AudioDeviceDescriptors](#audiodevicedescriptors)> | Promise used to return the device list. | | Promise&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | Promise used to return the device list.|
**Example:** **Example**
``` ```
audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => { audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => {
...@@ -1317,24 +1297,24 @@ audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => { ...@@ -1317,24 +1297,24 @@ audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => {
### setDeviceActive ### setDeviceActive
setDeviceActive\(deviceType: DeviceType, active: boolean, callback: AsyncCallback<void\>\): void setDeviceActive(deviceType: ActiveDeviceType, active: boolean, callback: AsyncCallback&lt;void&gt;): void
Sets a device to the active state. This API uses an asynchronous callback to return the result. Sets a device to the active state. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| --------- | ---------------------------------------| --------- | ---------------------------------------------------------------------------------------------------------------- | | ---------- | ------------------------------------- | ---- | ------------------------ |
| deviceType | [ActiveDeviceType](#activedevicetype) | Yes | Audio device type. | | deviceType | [ActiveDeviceType](#activedevicetype) | Yes | Audio device type. |
| active | boolean | Yes | Active status to set. The value true means to set the device to the active status, and false means the opposite. | | active | boolean | Yes | Active state to set. The value **true** means to set the device to the active state, and **false** means the opposite. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result.|
**Example:** **Example**
``` ```
audioManager.setDeviceActive(audio.ActiveDeviceType.SPEAKER, true, (err) => { audioManager.setDeviceActive(audio.DeviceType.SPEAKER, true, (err) => {
if (err) { if (err) {
console.error('Failed to set the active status of the device. ${err.message}'); console.error('Failed to set the active status of the device. ${err.message}');
return; return;
...@@ -1343,58 +1323,55 @@ audioManager.setDeviceActive(audio.ActiveDeviceType.SPEAKER, true, (err) => { ...@@ -1343,58 +1323,55 @@ audioManager.setDeviceActive(audio.ActiveDeviceType.SPEAKER, true, (err) => {
}); });
``` ```
### setDeviceActive ### setDeviceActive
setDeviceActive\(deviceType: DeviceType, active: boolean\): Promise<void\> setDeviceActive(deviceType: ActiveDeviceType, active: boolean): Promise&lt;void&gt;
Sets a device to the active state. This API uses a promise to return the result. Sets a device to the active state. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| --------- | ---------------------------------------| --------- | ---------------------------------------------------------------------------------------------------------------- | | ---------- | ------------------------------------- | ---- | ------------------ |
| deviceType | [ActiveDeviceType](#activedevicetype) | Yes | Audio device type. | | deviceType | [ActiveDeviceType](#activedevicetype) | Yes | Audio device type.|
| active | boolean | Yes | Active status to set. The value true means to set the device to the active status, and false means the opposite. | | active | boolean | Yes | Active state to set. The value **true** means to set the device to the active state, and **false** means the opposite. |
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ----------------------------------- | | ------------------- | ------------------------------- |
| Promise<void> | Promise used to return the result. | | Promise&lt;void&gt; | Promise used to return the result.|
**Example**
**Example:**
``` ```
audioManager.setDeviceActive(audio.ActiveDeviceType.SPEAKER, true).then(() => { audioManager.setDeviceActive(audio.DeviceType.SPEAKER, true).then(() => {
console.log('Promise returned to indicate that the device is set to the active status.'); console.log('Promise returned to indicate that the device is set to the active status.');
}); });
``` ```
### isDeviceActive ### isDeviceActive
isDeviceActive\(deviceType: DeviceType, callback: AsyncCallback<boolean\>\): void isDeviceActive(deviceType: ActiveDeviceType, callback: AsyncCallback&lt;boolean&gt;): void
Checks whether a device is active. This API uses an asynchronous callback to return the query result. Checks whether a device is active. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| --------- | ---------------------------------------| --------- | -------------------------------------------------------- | | ---------- | ------------------------------------- | ---- | ------------------------ |
| deviceType | [ActiveDeviceType](#activedevicetype) | Yes | Audio device type. | | deviceType | [ActiveDeviceType](#activedevicetype) | Yes | Audio device type. |
| callback | AsyncCallback<boolean> | Yes | Callback used to return the active status of the device. | | callback | AsyncCallback&lt;boolean&gt; | Yes | Callback used to return the active state of the device.|
**Example:** **Example**
``` ```
audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER, (err, value) => { audioManager.isDeviceActive(audio.DeviceType.SPEAKER, (err, value) => {
if (err) { if (err) {
console.error('Failed to obtain the active status of the device. ${err.message}'); console.error('Failed to obtain the active status of the device. ${err.message}');
return; return;
...@@ -1406,49 +1383,48 @@ audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER, (err, value) => { ...@@ -1406,49 +1383,48 @@ audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER, (err, value) => {
### isDeviceActive ### isDeviceActive
isDeviceActive\(deviceType: DeviceType\): Promise<boolean\> isDeviceActive(deviceType: ActiveDeviceType): Promise&lt;boolean&gt;
Checks whether a device is active. This API uses a promise to return the query result. Checks whether a device is active. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| --------- | ---------------------------------------| --------- | ----------------------------------------- | | ---------- | ------------------------------------- | ---- | ------------------ |
| deviceType | [ActiveDeviceType](#activedevicetype) | Yes | Audio device type. | | deviceType | [ActiveDeviceType](#activedevicetype) | Yes | Audio device type.|
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ----------------------------------- | | ---------------------- | ------------------------------- |
| Promise<boolean> | Promise used to return the active status of the device. | | Promise&lt;boolean&gt; | Promise used to return the active state of the device.|
**Example:** **Example**
``` ```
audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER).then((value) => { audioManager.isDeviceActive(audio.DeviceType.SPEAKER).then((value) => {
console.log('Promise returned to indicate that the active status of the device is obtained.' + value); console.log('Promise returned to indicate that the active status of the device is obtained.' + value);
}); });
``` ```
### setMicrophoneMute ### setMicrophoneMute
setMicrophoneMute\(mute: boolean, callback: AsyncCallback<void\>\): void setMicrophoneMute(mute: boolean, callback: AsyncCallback&lt;void&gt;): void
Mutes or unmutes the microphone. This API uses an asynchronous callback to return the result. Mutes or unmutes the microphone. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| --------- | -------------------- | --------- | ---------------------------------------------------------------------------------------------- | | -------- | ------------------------- | ---- | --------------------------------------------- |
| mute | boolean | Yes | Mute status to set. The value true means to mute the microphone, and false means the opposite. | | mute | boolean | Yes | Mute status to set. The value **true** means to mute the microphone, and **false** means the opposite.|
| callback | AsyncCallback<void> | Yes | Callback used to return the result. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. |
**Example:** **Example**
``` ```
audioManager.setMicrophoneMute(true, (err) => { audioManager.setMicrophoneMute(true, (err) => {
...@@ -1460,30 +1436,27 @@ audioManager.setMicrophoneMute(true, (err) => { ...@@ -1460,30 +1436,27 @@ audioManager.setMicrophoneMute(true, (err) => {
}); });
``` ```
### setMicrophoneMute ### setMicrophoneMute
setMicrophoneMute\(mute: boolean\): Promise<void\> setMicrophoneMute(mute: boolean): Promise&lt;void&gt;
Mutes or unmutes the microphone. This API uses a promise to return the result. Mutes or unmutes the microphone. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| --------- | -------------------- | --------- | ---------------------------------------------------------------------------------------------- | | ------ | ------- | ---- | --------------------------------------------- |
| mute | boolean | Yes | Mute status to set. The value true means to mute the microphone, and false means the opposite. | | mute | boolean | Yes | Mute status to set. The value **true** means to mute the microphone, and **false** means the opposite.|
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ----------------------------------- | | ------------------- | ------------------------------- |
| Promise<void> | Promise used to return the result. | | Promise&lt;void&gt; | Promise used to return the result.|
</table>
**Example:** **Example**
``` ```
audioManager.setMicrophoneMute(true).then(() => { audioManager.setMicrophoneMute(true).then(() => {
...@@ -1491,25 +1464,23 @@ audioManager.setMicrophoneMute(true).then(() => { ...@@ -1491,25 +1464,23 @@ audioManager.setMicrophoneMute(true).then(() => {
}); });
``` ```
### isMicrophoneMute ### isMicrophoneMute
isMicrophoneMute\(callback: AsyncCallback<boolean\>\): void isMicrophoneMute(callback: AsyncCallback&lt;boolean&gt;): void
Checks whether the microphone is muted. This API uses an asynchronous callback to return the query result. Checks whether the microphone is muted. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| --------- | -------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------- | | -------- | ---------------------------- | ---- | ------------------------------------------------------- |
| callback | AsyncCallback<boolean> | Yes | Callback used to return the mute status of the microphone. The value true means that the microphone is muted, and false means the opposite. | | callback | AsyncCallback&lt;boolean&gt; | Yes | Callback used to return the mute status of the microphone. The value **true** means that the microphone is muted, and **false** means the opposite.|
**Example:** **Example**
``` ```
var audioManager = audio.getAudioManager();
audioManager.isMicrophoneMute((err, value) => { audioManager.isMicrophoneMute((err, value) => {
if (err) { if (err) {
console.error('Failed to obtain the mute status of the microphone. ${err.message}'); console.error('Failed to obtain the mute status of the microphone. ${err.message}');
...@@ -1519,25 +1490,24 @@ audioManager.isMicrophoneMute((err, value) => { ...@@ -1519,25 +1490,24 @@ audioManager.isMicrophoneMute((err, value) => {
}); });
``` ```
### isMicrophoneMute ### isMicrophoneMute
isMicrophoneMute\(\): Promise<boolean\> isMicrophoneMute(): Promise&lt;boolean&gt;
Checks whether the microphone is muted. This API uses a promise to return the query result. Checks whether the microphone is muted. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
**Return value:** **Return value**
| Type | Description | | 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. | | Promise&lt;boolean&gt; | Promise used to return the mute status of the microphone. The value **true** means that the microphone is muted, and **false** means the opposite.|
**Example**
**Example:**
``` ```
var audioManager = audio.getAudioManager();
audioManager.isMicrophoneMute().then((value) => { audioManager.isMicrophoneMute().then((value) => {
console.log('Promise returned to indicate that the mute status of the microphone is obtained.', + value); console.log('Promise returned to indicate that the mute status of the microphone is obtained.', + value);
}); });
...@@ -1547,20 +1517,20 @@ audioManager.isMicrophoneMute().then((value) => { ...@@ -1547,20 +1517,20 @@ audioManager.isMicrophoneMute().then((value) => {
on(type: 'volumeChange', callback: Callback\<VolumeEvent>): void on(type: 'volumeChange', callback: Callback\<VolumeEvent>): void
Subscribes to system volume change events. This API uses a callback to get volume change events. Subscribes to system volume change events.
This is a system API and cannot be called by third-party applications. This is a system API and cannot be called by third-party applications.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :--------------------------------------| :-------------| :------------------------------------------------------------------------------------------------------------------------------------------------------------ | | -------- | -------------------------------------- | ---- | ------------------------------------------------------------ |
| type | string | Yes | Type of the event to subscribe to. The value 'volumeChange' means the system volume change event, which is triggered when a system volume change is detected. | | type | string | Yes | Type of event to subscribe to. The value **volumeChange** means the system volume change event, which is triggered when a system volume change is detected.|
| callback | Callback<[VolumeEvent](#volumeevent8)> | Yes | Callback used to get the system volume change event. | | callback | Callback<[VolumeEvent](#volumeevent8)> | Yes | Callback used to return the system volume change event. |
**Example:** **Example**
``` ```
audioManager.on('volumeChange', (volumeEvent) => { audioManager.on('volumeChange', (volumeEvent) => {
...@@ -1570,25 +1540,24 @@ audioManager.on('volumeChange', (volumeEvent) => { ...@@ -1570,25 +1540,24 @@ audioManager.on('volumeChange', (volumeEvent) => {
}); });
``` ```
### on('ringerModeChange')<sup>8+</sup> ### on('ringerModeChange')<sup>8+</sup>
on(type: 'ringerModeChange', callback: Callback\<AudioRingMode>): void on(type: 'ringerModeChange', callback: Callback\<AudioRingMode>): void
Subscribes to ringer mode change events. This API uses a callback to get ringer mode changes. Subscribes to ringer mode change events.
This is a system API and cannot be called by third-party applications. This is a system API and cannot be called by third-party applications.
**System capability:** SystemCapability.Multimedia.Audio.Communication **System capability**: SystemCapability.Multimedia.Audio.Communication
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :----------------------------------------- | :-------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------- | | -------- | ----------------------------------------- | ---- | ------------------------------------------------------------ |
| type | string | Yes | Type of the event to subscribe to. The value 'ringerModeChange' means the ringer mode change event, which is triggered when a ringer mode change is detected. | | type | string | Yes | Type of event to subscribe to. The value **ringerModeChange** means the ringer mode change event, which is triggered when a ringer mode change is detected.|
| callback | Callback<[AudioRingMode](#audioringmode)> | Yes | Callback used to get the updated ringer mode. | | callback | Callback<[AudioRingMode](#audioringmode)> | Yes | Callback used to return the updated ringer mode. |
**Example:** **Example**
``` ```
audioManager.on('ringerModeChange', (ringerMode) => { audioManager.on('ringerModeChange', (ringerMode) => {
...@@ -1600,18 +1569,18 @@ audioManager.on('ringerModeChange', (ringerMode) => { ...@@ -1600,18 +1569,18 @@ audioManager.on('ringerModeChange', (ringerMode) => {
on(type: 'deviceChange', callback: Callback<DeviceChangeAction\>): void on(type: 'deviceChange', callback: Callback<DeviceChangeAction\>): void
Subscribes to device change events. When a device is connected/disconnected, registered clients will receive the callback. Subscribes to device change events. When a device is connected or disconnected, registered clients will receive the callback.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :-------------------------------------------------- | :---------| :---------------------------------------------------------------------------------------------------------------------------------------------- | | :------- | :--------------------------------------------------- | :--- | :----------------------------------------- |
| type | string | Yes | Type of the event to subscribe to. The value 'deviceChange' means the device change event, which is triggered when a device change is detected. | | type | string | Yes | Type of event to subscribe to. The value **deviceChange** means the device change event, which is triggered when a device connection status change is detected.|
| callback | Callback<[DeviceChangeAction](#devicechangeaction)> | Yes | Callback used to obtain the device update details. | | callback | Callback<[DeviceChangeAction](#DeviceChangeAction)\> | Yes | Callback used to return the device update details. |
**Example:** **Example**
``` ```
audioManager.on('deviceChange', (deviceChanged) => { audioManager.on('deviceChange', (deviceChanged) => {
...@@ -1626,20 +1595,18 @@ audioManager.on('deviceChange', (deviceChanged) => { ...@@ -1626,20 +1595,18 @@ audioManager.on('deviceChange', (deviceChanged) => {
off(type: 'deviceChange', callback?: Callback<DeviceChangeAction\>): void off(type: 'deviceChange', callback?: Callback<DeviceChangeAction\>): void
Unsubscribes from audio device connection change events. Unsubscribes from device change events.
This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR. **System capability**: SystemCapability.Multimedia.Audio.Device
**System capability:** SystemCapability.Multimedia.Audio.Device **Parameters**
**Parameters:** | 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. |
| Name | Type | Mandatory | Description | **Example**
| :------- | :-------------------------------------------------- | :---------| :-------------------------------------------------- |
| type | string | Yes | Type of the event to unsubscribe from. |
| callback | Callback<[DeviceChangeAction](#devicechangeaction)> | No | Callback used to obtain the device update details. |
**Example:**
``` ```
audioManager.off('deviceChange', (deviceChanged) => { audioManager.off('deviceChange', (deviceChanged) => {
...@@ -1647,26 +1614,23 @@ audioManager.off('deviceChange', (deviceChanged) => { ...@@ -1647,26 +1614,23 @@ audioManager.off('deviceChange', (deviceChanged) => {
}); });
``` ```
### on('interrupt') ### on('interrupt')
on(type: 'interrupt', interrupt: AudioInterrupt, callback: Callback\<InterruptAction>): void on(type: 'interrupt', interrupt: AudioInterrupt, callback: Callback\<InterruptAction>): void
Subscribes to audio interrupt events. When the application's audio is interrupted by another playback event, the application will receive the callback. Subscribes to audio interruption events. When the application's audio is interrupted by another playback event, the application will receive the callback.
This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| --------- | --------------------------------------------- | ---- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | --------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
| type | string | Yes | Type of event to subscribe to. The value 'interrupt' means the audio interrupt event, which is triggered when the audio playback of the current application is interrupted by another application.| | type | string | Yes | Type of event to subscribe to. The value **interrupt** means the audio interruption event, which is triggered when the audio playback of the current application is interrupted by another application.|
| interrupt | AudioInterrupt | Yes | Audio interrupt event type. | | interrupt | AudioInterrupt | Yes | Audio interruption event type. |
| callback | Callback<[InterruptAction](#interruptaction)> | Yes | Audio interrupt event callback method. | | callback | Callback<[InterruptAction](#interruptaction)> | Yes | Callback invoked for the audio interruption event. |
**Example:** **Example**
``` ```
var interAudioInterrupt = { var interAudioInterrupt = {
...@@ -1674,7 +1638,7 @@ var interAudioInterrupt = { ...@@ -1674,7 +1638,7 @@ var interAudioInterrupt = {
contentType:0, contentType:0,
pauseWhenDucked:true pauseWhenDucked:true
}; };
audioManager.on('interrupt', interAudioInterrupt, (InterruptAction) => { this.audioManager.on('interrupt', interAudioInterrupt, (InterruptAction) => {
if (InterruptAction.actionType === 0) { if (InterruptAction.actionType === 0) {
console.log("An event to gain the audio focus starts."); console.log("An event to gain the audio focus starts.");
console.log("Focus gain event:" + JSON.stringify(InterruptAction)); console.log("Focus gain event:" + JSON.stringify(InterruptAction));
...@@ -1690,21 +1654,19 @@ audioManager.on('interrupt', interAudioInterrupt, (InterruptAction) => { ...@@ -1690,21 +1654,19 @@ audioManager.on('interrupt', interAudioInterrupt, (InterruptAction) => {
off(type: 'interrupt', interrupt: AudioInterrupt, callback?: Callback\<InterruptAction>): void off(type: 'interrupt', interrupt: AudioInterrupt, callback?: Callback\<InterruptAction>): void
Unsubscribes from audio interrupt events. Unsubscribes from audio interruption events.
This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR. **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 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. |
| Name | Type | Mandatory | Description | **Example**
| --------- | --------------------------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| 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. |
**Example:**
``` ```
var interAudioInterrupt = { var interAudioInterrupt = {
...@@ -1712,7 +1674,7 @@ var interAudioInterrupt = { ...@@ -1712,7 +1674,7 @@ var interAudioInterrupt = {
contentType:0, contentType:0,
pauseWhenDucked:true pauseWhenDucked:true
}; };
audioManager.off('interrupt', interAudioInterrupt, (InterruptAction) => { this.audioManager.off('interrupt', interAudioInterrupt, (InterruptAction) => {
if (InterruptAction.actionType === 0) { if (InterruptAction.actionType === 0) {
console.log("An event to release the audio focus starts."); console.log("An event to release the audio focus starts.");
console.log("Focus release event:" + JSON.stringify(InterruptAction)); console.log("Focus release event:" + JSON.stringify(InterruptAction));
...@@ -1720,25 +1682,24 @@ audioManager.off('interrupt', interAudioInterrupt, (InterruptAction) => { ...@@ -1720,25 +1682,24 @@ audioManager.off('interrupt', interAudioInterrupt, (InterruptAction) => {
}); });
``` ```
### setAudioScene<sup>8+</sup> ### setAudioScene<sup>8+</sup>
setAudioScene\(scene: AudioScene, callback: AsyncCallback<void\>\): void setAudioScene\(scene: AudioScene, callback: AsyncCallback<void\>\): void
Sets the audio scene mode to change audio strategies. This API uses an asynchronous callback to return the result. Sets an audio scene. This API uses an asynchronous callback to return the result.
This is a system API and cannot be called by third-party applications. This is a system API and cannot be called by third-party applications.
**System capability:** SystemCapability.Multimedia.Audio.Communication **System capability**: SystemCapability.Multimedia.Audio.Communication
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :------------------------------------ | :-------- | :---------------------------------- | | :------- | :----------------------------------- | :--- | :------------------- |
| scene | <a href="#audioscene">AudioScene</a> | Yes | Audio scene mode. | | scene | <a href="#audioscene">AudioScene</a> | Yes | Audio scene to set. |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | | callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example:** **Example**
``` ```
audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL, (err) => { audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL, (err) => {
...@@ -1750,57 +1711,53 @@ audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL, (err) => { ...@@ -1750,57 +1711,53 @@ audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL, (err) => {
}); });
``` ```
### setAudioScene<sup>8+</sup> ### setAudioScene<sup>8+</sup>
setAudioScene\(scene: AudioScene\): Promise<void\> setAudioScene\(scene: AudioScene\): Promise<void\>
Sets the audio scene mode to change audio strategies. This API uses a promise to return the result. Sets an audio scene. This API uses a promise to return the result.
This is a system API and cannot be called by third-party applications. This is a system API and cannot be called by third-party applications.
**System capability:** SystemCapability.Multimedia.Audio.Communication **System capability**: SystemCapability.Multimedia.Audio.Communication
**Parameters:**
| Name | Type | Mandatory | Description | **Parameters**
| :------- | :-------------------------------------- | :-------- | :---------------- |
| scene | <a href="#audioscene">AudioScene</a> | Yes | Audio scene mode. |
| Name| Type | Mandatory| Description |
| :----- | :----------------------------------- | :--- | :------------- |
| scene | <a href="#audioscene">AudioScene</a> | Yes | Audio scene to set.|
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :------------- | :---------------------------------- | | :------------- | :------------------- |
| Promise<void\> | Promise used to return the result. | | Promise<void\> | Promise used to return the result.|
**Example:** **Example**
``` ```
audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL).then(() => { audioManager.setAudioScene(audio.AudioSceneMode.AUDIO_SCENE_PHONE_CALL).then(() => {
console.log('Promise returned to indicate a successful setting of the audio scene mode.'); console.log('Promise returned to indicate a successful setting of the audio scene mode.');
}).catch ((err) => { }).catch ((err) => {
console.log('Failed to set the audio scene mode'); console.log('Failed to set the audio scene mode');
}); });
``` ```
### getAudioScene<sup>8+</sup> ### getAudioScene<sup>8+</sup>
getAudioScene\(callback: AsyncCallback<AudioScene\>\): void getAudioScene\(callback: AsyncCallback<AudioScene\>\): void
Obtains the audio scene mode. This API uses an asynchronous callback to return the query result. Obtains the audio scene. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Communication **System capability**: SystemCapability.Multimedia.Audio.Communication
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :-------------------------------------------------- | :-------- | :-------------------------------------------- | | :------- | :-------------------------------------------------- | :--- | :--------------------------- |
| callback | AsyncCallback<<a href="#audioscene">AudioScene</a>> | Yes | Callback used to return the audio scene mode. | | callback | AsyncCallback<<a href="#audioscene">AudioScene</a>> | Yes | Callback used to return the audio scene.|
**Example:** **Example**
``` ```
audioManager.getAudioScene((err, value) => { audioManager.getAudioScene((err, value) => {
...@@ -1817,18 +1774,17 @@ audioManager.getAudioScene((err, value) => { ...@@ -1817,18 +1774,17 @@ audioManager.getAudioScene((err, value) => {
getAudioScene\(\): Promise<AudioScene\> getAudioScene\(\): Promise<AudioScene\>
Obtains the audio scene mode. This API uses a promise to return the query result. Obtains the audio scene. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Communication **System capability**: SystemCapability.Multimedia.Audio.Communication
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :-------------------------------------------- | :------------------------------------------- | | :-------------------------------------------- | :--------------------------- |
| Promise<<a href="#audioscene">AudioScene</a>> | Promise used to return the audio scene mode. | | Promise<<a href="#audioscene">AudioScene</a>> | Promise used to return the audio scene.|
**Example:** **Example**
``` ```
audioManager.getAudioScene().then((value) => { audioManager.getAudioScene().then((value) => {
...@@ -1842,20 +1798,18 @@ audioManager.getAudioScene().then((value) => { ...@@ -1842,20 +1798,18 @@ audioManager.getAudioScene().then((value) => {
Describes an audio device. Describes an audio device.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
| Name | Type | Readable | Writable | Description | | Name | Type | Readable| Writable| Description |
| ---------- | ------------------------- | -------- | -------- | ------------------ | | ---------- | ------------------------- | ---- | ---- | ---------- |
| deviceRole | [DeviceRole](#devicerole) | Yes | No | Audio device role. | | deviceRole | [DeviceRole](#devicerole) | Yes | No | Device role.|
| deviceType | [DeviceType](#devicetype) | Yes | No | Audio device type. | | deviceType | [DeviceType](#devicetype) | Yes | No | Device type.|
## AudioDeviceDescriptors ## AudioDeviceDescriptors
Array of [AudioDeviceDescriptor](#audiodevicedescriptor), which is read-only. Array of [AudioDeviceDescriptor](#audiodevicedescriptor), which is read-only.
**System capability:** SystemCapability.Multimedia.Audio.Device **Example**
**Example:**
``` ```
import audio from '@ohos.multimedia.audio'; import audio from '@ohos.multimedia.audio';
...@@ -1880,45 +1834,40 @@ promise.then(function (value) { ...@@ -1880,45 +1834,40 @@ promise.then(function (value) {
} }
}); });
``` ```
## AudioRenderer<sup>8+</sup>
Provides related APIs for audio rendering. Before calling the AudioRenderer API, you need to create an instance through [createAudioRenderer](#audiocreateaudiorenderer8).
**System capability:** SystemCapability.Multimedia.Audio.Renderer ## AudioRenderer<sup>8+</sup>
### state<sup>8+</sup>
readonly state: AudioState Provides APIs for audio rendering. Before calling any API in **AudioRenderer**, you must use [createAudioRenderer](#audiocreateaudiorenderer8) to create an **AudioRenderer** instance.
Defines the current render state. ### Attributes
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
| Name | Type | Readable | Writable | Description | | Name | Type | Readable| Writable| Description |
| :---- | :-------------------------- | :------- | :------- | :------------------ | | ----- | -------------------------- | ---- | ---- | ------------------ |
| state | [AudioState](#audiostate8) | Yes | No | Audio render state. | | state<sup>8+</sup> | [AudioState](#audiostate8) | Yes | No | Audio renderer state.|
**Example:** **Example**
``` ```
var state = audioRenderer.state; var state = audioRenderer.state;
``` ```
### getRendererInfo<sup>8+</sup> ### getRendererInfo<sup>8+</sup>
getRendererInfo(callback: AsyncCallback<AudioRendererInfo\>): void getRendererInfo(callback: AsyncCallback<AudioRendererInfo\>): void
Obtains the renderer information provided while creating a renderer instance. This API uses an asynchronous callback to return the result. Obtains the renderer information of this **AudioRenderer** instance. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :------------------------------------------------------- | :-------- | :------------------------------------------------ | | :------- | :------------------------------------------------------- | :--- | :--------------------- |
| callback | AsyncCallback<[AudioRendererInfo](#audiorendererinfo8)> | Yes | Callback used to return the renderer information. | | callback | AsyncCallback<[AudioRendererInfo](#audiorendererinfo8)\> | Yes | Callback used to return the renderer information.|
**Example:** **Example**
``` ```
audioRenderer.getRendererInfo((err, rendererInfo) => { audioRenderer.getRendererInfo((err, rendererInfo) => {
...@@ -1929,25 +1878,23 @@ audioRenderer.getRendererInfo((err, rendererInfo) => { ...@@ -1929,25 +1878,23 @@ audioRenderer.getRendererInfo((err, rendererInfo) => {
}); });
``` ```
### getRendererInfo<sup>8+</sup> ### getRendererInfo<sup>8+</sup>
getRendererInfo(): Promise<AudioRendererInfo\> getRendererInfo(): Promise<AudioRendererInfo\>
Obtains the renderer information provided while creating a renderer instance. This API uses a promise to return the result. Obtains the renderer information of this **AudioRenderer** instance. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :-------------------------------------------------- | :----------------------------------------------- | | -------------------------------------------------- | ------------------------------- |
| Promise<[AudioRendererInfo](#audiorendererinfo8)> | Promise used to return the renderer information. | | Promise<[AudioRendererInfo](#audiorendererinfo8)\> | Promise used to return the renderer information.|
**Example:** **Example**
``` ```
var resultFlag = true;
audioRenderer.getRendererInfo().then((rendererInfo) => { audioRenderer.getRendererInfo().then((rendererInfo) => {
console.log('Renderer GetRendererInfo:'); console.log('Renderer GetRendererInfo:');
console.log('Renderer content:' + rendererInfo.content); console.log('Renderer content:' + rendererInfo.content);
...@@ -1957,24 +1904,23 @@ audioRenderer.getRendererInfo().then((rendererInfo) => { ...@@ -1957,24 +1904,23 @@ audioRenderer.getRendererInfo().then((rendererInfo) => {
console.log('AudioFrameworkRenderLog: RendererInfo :ERROR: '+err.message); console.log('AudioFrameworkRenderLog: RendererInfo :ERROR: '+err.message);
resultFlag = false; resultFlag = false;
}); });
``` ```
### getStreamInfo<sup>8+</sup> ### getStreamInfo<sup>8+</sup>
getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void
Obtains the renderer stream information. This API uses an asynchronous callback to return the result. Obtains the stream information of this **AudioRenderer** instance. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :------------------------------------------------------ | :-------- | :---------------------------------------------- | | :------- | :--------------------------------------------------- | :--- | :------------------- |
| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | Yes | Callback used to return the stream information. | | callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | Yes | Callback used to return the stream information.|
**Example:** **Example**
``` ```
audioRenderer.getStreamInfo((err, streamInfo) => { audioRenderer.getStreamInfo((err, streamInfo) => {
...@@ -1990,17 +1936,17 @@ audioRenderer.getStreamInfo((err, streamInfo) => { ...@@ -1990,17 +1936,17 @@ audioRenderer.getStreamInfo((err, streamInfo) => {
getStreamInfo(): Promise<AudioStreamInfo\> getStreamInfo(): Promise<AudioStreamInfo\>
Obtains the renderer stream information. This API uses a promise to return the result. Obtains the stream information of this **AudioRenderer** instance. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :------------------------------------------------- | :--------------------------------------------- | | :--------------------------------------------- | :--------------------- |
| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information. | | Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information.|
**Example:** **Example**
``` ```
audioRenderer.getStreamInfo().then((streamInfo) => { audioRenderer.getStreamInfo().then((streamInfo) => {
...@@ -2012,7 +1958,6 @@ audioRenderer.getStreamInfo().then((streamInfo) => { ...@@ -2012,7 +1958,6 @@ audioRenderer.getStreamInfo().then((streamInfo) => {
}).catch((err) => { }).catch((err) => {
console.log('ERROR: '+err.message); console.log('ERROR: '+err.message);
}); });
``` ```
### start<sup>8+</sup> ### start<sup>8+</sup>
...@@ -2021,16 +1966,15 @@ start(callback: AsyncCallback<void\>): void ...@@ -2021,16 +1966,15 @@ start(callback: AsyncCallback<void\>): void
Starts the renderer. This API uses an asynchronous callback to return the result. Starts the renderer. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :---------------------- | :-------- | :-------------------------------------- | | -------- | -------------------- | ---- | ---------- |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | | callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
| | | | |
**Example:** **Example**
``` ```
audioRenderer.start((err) => { audioRenderer.start((err) => {
...@@ -2048,15 +1992,15 @@ start(): Promise<void\> ...@@ -2048,15 +1992,15 @@ start(): Promise<void\>
Starts the renderer. This API uses a promise to return the result. Starts the renderer. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :------------- | :--------------------------------- | | -------------- | ------------------------- |
| Promise<void\> | Promise used to return the result. | | Promise\<void> | Promise used to return the result.|
**Example:** **Example**
``` ```
audioRenderer.start().then(() => { audioRenderer.start().then(() => {
...@@ -2066,23 +2010,21 @@ audioRenderer.start().then(() => { ...@@ -2066,23 +2010,21 @@ audioRenderer.start().then(() => {
}); });
``` ```
### pause<sup>8+</sup> ### pause<sup>8+</sup>
pause(callback: AsyncCallback\<void>): void pause(callback: AsyncCallback\<void>): void
Pauses rendering. This API uses an asynchronous callback to return the result. Pauses rendering. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :---------------------- | :-------- | :------------------------------------ | | -------- | -------------------- | ---- | ---------------- |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | | callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
| | | | |
**Example:** **Example**
``` ```
audioRenderer.pause((err) => { audioRenderer.pause((err) => {
...@@ -2100,15 +2042,15 @@ pause(): Promise\<void> ...@@ -2100,15 +2042,15 @@ pause(): Promise\<void>
Pauses rendering. This API uses a promise to return the result. Pauses rendering. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :------------- | :--------------------------------- | | -------------- | ------------------------- |
| Promise<void\> | Promise used to return the result. | | Promise\<void> | Promise used to return the result.|
**Example:** **Example**
``` ```
audioRenderer.pause().then(() => { audioRenderer.pause().then(() => {
...@@ -2124,16 +2066,15 @@ drain(callback: AsyncCallback\<void>): void ...@@ -2124,16 +2066,15 @@ drain(callback: AsyncCallback\<void>): void
Drains the playback buffer. This API uses an asynchronous callback to return the result. Drains the playback buffer. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :---------------------- | :-------- | :---------------------------------------| | -------- | -------------------- | ---- | ---------------- |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | | callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
| | | | |
**Example:** **Example**
``` ```
audioRenderer.drain((err) => { audioRenderer.drain((err) => {
...@@ -2151,15 +2092,15 @@ drain(): Promise\<void> ...@@ -2151,15 +2092,15 @@ drain(): Promise\<void>
Drains the playback buffer. This API uses a promise to return the result. Drains the playback buffer. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :------------- | :--------------------------------- | | -------------- | ------------------------- |
| Promise<void\> | Promise used to return the result. | | Promise\<void> | Promise used to return the result.|
**Example:** **Example**
``` ```
audioRenderer.drain().then(() => { audioRenderer.drain().then(() => {
...@@ -2169,22 +2110,21 @@ audioRenderer.drain().then(() => { ...@@ -2169,22 +2110,21 @@ audioRenderer.drain().then(() => {
}); });
``` ```
### stop<sup>8+</sup> ### stop<sup>8+</sup>
stop(callback: AsyncCallback\<void>): void stop(callback: AsyncCallback\<void>): void
Stops rendering. This API uses an asynchronous callback to return the result. Stops rendering. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :---------------------- | :-------- | :------------------------------------- | | -------- | -------------------- | ---- | ---------------- |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | | callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example:** **Example**
``` ```
audioRenderer.stop((err) => { audioRenderer.stop((err) => {
...@@ -2202,15 +2142,15 @@ stop(): Promise\<void> ...@@ -2202,15 +2142,15 @@ stop(): Promise\<void>
Stops rendering. This API uses a promise to return the result. Stops rendering. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :------------- | :--------------------------------- | | -------------- | ------------------------- |
| Promise<void\> | Promise used to return the result. | | Promise\<void> | Promise used to return the result.|
**Example:** **Example**
``` ```
audioRenderer.stop().then(() => { audioRenderer.stop().then(() => {
...@@ -2220,22 +2160,21 @@ audioRenderer.stop().then(() => { ...@@ -2220,22 +2160,21 @@ audioRenderer.stop().then(() => {
}); });
``` ```
### release<sup>8+</sup> ### release<sup>8+</sup>
release(callback: AsyncCallback\<void>): void release(callback: AsyncCallback\<void>): void
Releases the renderer. This API uses an asynchronous callback to return the result. Releases the renderer. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :---------------------- | :-------- | :------------------------------------- | | -------- | -------------------- | ---- | ---------------- |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | | callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example:** **Example**
``` ```
audioRenderer.release((err) => { audioRenderer.release((err) => {
...@@ -2253,15 +2192,15 @@ release(): Promise\<void> ...@@ -2253,15 +2192,15 @@ release(): Promise\<void>
Releases the renderer. This API uses a promise to return the result. Releases the renderer. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :------------- | :--------------------------------- | | -------------- | ------------------------- |
| Promise<void\> | Promise used to return the result. | | Promise\<void> | Promise used to return the result.|
**Example:** **Example**
``` ```
audioRenderer.release().then(() => { audioRenderer.release().then(() => {
...@@ -2277,16 +2216,16 @@ write(buffer: ArrayBuffer, callback: AsyncCallback\<number>): void ...@@ -2277,16 +2216,16 @@ write(buffer: ArrayBuffer, callback: AsyncCallback\<number>): void
Writes the buffer. This API uses an asynchronous callback to return the result. Writes the buffer. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :---------------------- | :-------- | :--------------------------------------------------------------------------------------------------- | | -------- | ---------------------- | ---- | --------------------------------------------------- |
| buffer | ArrayBuffer | Yes | Buffer to be written. | | buffer | ArrayBuffer | Yes | Buffer to be written. |
| callback | AsyncCallback<boolean\> | Yes | Returns the number of bytes written if the operation is successful; returns an error code otherwise. | | callback | AsyncCallback\<number> | Yes | Returns the number of bytes written if the operation is successful; returns an error code otherwise.|
**Example:** **Example**
``` ```
import audio from '@ohos.multimedia.audio'; import audio from '@ohos.multimedia.audio';
...@@ -2304,22 +2243,21 @@ audioRenderer.write(buf, (err, writtenbytes) => { ...@@ -2304,22 +2243,21 @@ audioRenderer.write(buf, (err, writtenbytes) => {
}); });
``` ```
### write<sup>8+</sup> ### write<sup>8+</sup>
write(buffer: ArrayBuffer): Promise\<number> write(buffer: ArrayBuffer): Promise\<number>
Writes the buffer. This API uses a promise to return the result. Writes the buffer. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :--------------- | :--------------------------------------------------------------------------------------------------- | | ---------------- | ------------------------------------------------------------ |
| Promise<number\> | Returns the number of bytes written if the operation is successful; returns an error code otherwise. | | Promise\<number> | Returns the number of bytes written if the operation is successful; returns an error code otherwise.|
**Example:** **Example**
``` ```
import audio from '@ohos.multimedia.audio'; import audio from '@ohos.multimedia.audio';
...@@ -2344,17 +2282,17 @@ audioRenderer.write(buf).then((writtenbytes) => { ...@@ -2344,17 +2282,17 @@ audioRenderer.write(buf).then((writtenbytes) => {
getAudioTime(callback: AsyncCallback\<number>): void getAudioTime(callback: AsyncCallback\<number>): void
Obtains the timestamp in Unix epoch time (starts from January 1, 1970), in nanoseconds. This API uses an asynchronous callback to return the result. Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :--------------------- | :-------- | :------------------------------------- | | -------- | ---------------------- | ---- | ---------------- |
| callback | AsyncCallback<number\> | Yes | Callback used to return the timestamp. | | callback | AsyncCallback\<number> | Yes | Callback used to return the timestamp.|
**Example:** **Example**
``` ```
audioRenderer.getAudioTime((err, timestamp) => { audioRenderer.getAudioTime((err, timestamp) => {
...@@ -2362,22 +2300,21 @@ audioRenderer.getAudioTime((err, timestamp) => { ...@@ -2362,22 +2300,21 @@ audioRenderer.getAudioTime((err, timestamp) => {
}); });
``` ```
### getAudioTime<sup>8+</sup> ### getAudioTime<sup>8+</sup>
getAudioTime(): Promise\<number> getAudioTime(): Promise\<number>
Obtains the timestamp in Unix epoch time (starts from January 1, 1970), in nanoseconds. This API uses a promise to return the result. Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :--------------- | :------------------------------------ | | ---------------- | ----------------------- |
| Promise<number\> | Promise used to return the timestamp. | | Promise\<number> | Promise used to return the timestamp.|
**Example:** **Example**
``` ```
audioRenderer.getAudioTime().then((timestamp) => { audioRenderer.getAudioTime().then((timestamp) => {
...@@ -2387,55 +2324,54 @@ audioRenderer.getAudioTime().then((timestamp) => { ...@@ -2387,55 +2324,54 @@ audioRenderer.getAudioTime().then((timestamp) => {
}); });
``` ```
### getBufferSize<sup>8+</sup> ### getBufferSize<sup>8+</sup>
getBufferSize(callback: AsyncCallback\<number>): void getBufferSize(callback: AsyncCallback\<number>): void
Obtains a reasonable minimum buffer size in bytes for rendering. This API uses an asynchronous callback to return the result. Obtains a reasonable minimum buffer size in bytes for rendering. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :--------------------- | :-------- | :--------------------------------------- | | -------- | ---------------------- | ---- | -------------------- |
| callback | AsyncCallback<number\> | Yes | Callback used to return the buffer size. | | callback | AsyncCallback\<number> | Yes | Callback used to return the buffer size.|
**Example:** **Example**
``` ```
var bufferSize = audioRenderer.getBufferSize(async(err, bufferSize) => { audioRenderer.getBufferSize((err, bufferSize) => {
if (err) { if (err) {
console.error('getBufferSize error'); console.error('getBufferSize error');
} }
}); });
let buf = new ArrayBuffer(bufferSize);
ss.readSync(buf);
``` ```
### getBufferSize<sup>8+</sup> ### getBufferSize<sup>8+</sup>
getBufferSize(): Promise\<number> getBufferSize(): Promise\<number>
Obtains a reasonable minimum buffer size in bytes for rendering. This API uses a promise to return the result. Obtains a reasonable minimum buffer size in bytes for rendering. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :--------------- | :-------------------------------------- | | ---------------- | --------------------------- |
| Promise<number\> | Promise used to return the buffer size. | | Promise\<number> | Promise used to return the buffer size.|
**Example:** **Example**
``` ```
var bufferSize; audioRenderer.getBufferSize().then((bufferSize) => {
await audioRenderer.getBufferSize().then(async function (data) => { let buf = new ArrayBuffer(bufferSize);
console.info('AudioFrameworkRenderLog: getBufferSize :SUCCESS '+data); ss.readSync(buf);
bufferSize=data;
}).catch((err) => { }).catch((err) => {
console.info('AudioFrameworkRenderLog: getBufferSize :ERROR : '+err.message); console.log('ERROR: '+err.message);
}); });
``` ```
...@@ -2445,16 +2381,16 @@ setRenderRate(rate: AudioRendererRate, callback: AsyncCallback\<void>): void ...@@ -2445,16 +2381,16 @@ setRenderRate(rate: AudioRendererRate, callback: AsyncCallback\<void>): void
Sets the render rate. This API uses an asynchronous callback to return the result. Sets the render rate. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :------------------------------------------ | :-------- | :---------------------------------- | | -------- | ---------------------------------------- | ---- | ------------------------ |
| rate | [AudioRendererRate](#audiorendererrate8) | Yes | Audio render rate. | | rate | [AudioRendererRate](#audiorendererrate8) | Yes | Audio render rate. |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | | callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example:** **Example**
``` ```
audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL, (err) => { audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL, (err) => {
...@@ -2466,28 +2402,27 @@ audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL, (err) => ...@@ -2466,28 +2402,27 @@ audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL, (err) =>
}); });
``` ```
### setRenderRate<sup>8+</sup> ### setRenderRate<sup>8+</sup>
setRenderRate(rate: AudioRendererRate): Promise\<void> setRenderRate(rate: AudioRendererRate): Promise\<void>
Sets the render rate. This API uses a promise to return the result. Sets the render rate. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| :--- | :--------------------------------------- | :-------- | :----------------- | | ------ | ---------------------------------------- | ---- | ------------ |
| rate | [AudioRendererRate](#audiorendererrate8) | Yes | Audio render rate. | | rate | [AudioRendererRate](#audiorendererrate8) | Yes | Audio render rate.|
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :------------- | :--------------------------------- | | -------------- | ------------------------- |
| Promise<void\> | Promise used to return the result. | | Promise\<void> | Promise used to return the result.|
**Example:** **Example**
``` ```
audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL).then(() => { audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL).then(() => {
...@@ -2503,15 +2438,15 @@ getRenderRate(callback: AsyncCallback\<AudioRendererRate>): void ...@@ -2503,15 +2438,15 @@ getRenderRate(callback: AsyncCallback\<AudioRendererRate>): void
Obtains the current render rate. This API uses an asynchronous callback to return the result. Obtains the current render rate. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :------------------------------------------------------- | :-------- | :--------------------------------------------- | | -------- | ------------------------------------------------------- | ---- | ------------------ |
| callback | AsyncCallback<[AudioRendererRate](#audiorendererrate8)\> | Yes | Callback used to return the audio render rate. | | callback | AsyncCallback<[AudioRendererRate](#audiorendererrate8)> | Yes | Callback used to return the audio render rate.|
**Example:** **Example**
``` ```
audioRenderer.getRenderRate((err, renderrate) => { audioRenderer.getRenderRate((err, renderrate) => {
...@@ -2519,22 +2454,21 @@ audioRenderer.getRenderRate((err, renderrate) => { ...@@ -2519,22 +2454,21 @@ audioRenderer.getRenderRate((err, renderrate) => {
}); });
``` ```
### getRenderRate<sup>8+</sup> ### getRenderRate<sup>8+</sup>
getRenderRate(): Promise\<AudioRendererRate> getRenderRate(): Promise\<AudioRendererRate>
Obtains the current render rate. This API uses a promise to return the result. Obtains the current render rate. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :-------------------------------------------------- | :-------------------------------------------- | | ------------------------------------------------- | ------------------------- |
| Promise<<[AudioRendererRate](#audiorendererrate8)\> | Promise used to return the audio render rate. | | Promise<[AudioRendererRate](#audiorendererrate8)> | Promise used to return the audio render rate.|
**Example:** **Example**
``` ```
audioRenderer.getRenderRate().then((renderRate) => { audioRenderer.getRenderRate().then((renderRate) => {
...@@ -2544,28 +2478,25 @@ audioRenderer.getRenderRate().then((renderRate) => { ...@@ -2544,28 +2478,25 @@ audioRenderer.getRenderRate().then((renderRate) => {
}); });
``` ```
### on('interrupt')<sup>9+</sup> ### on('interrupt')<sup>9+</sup>
on(type: 'interrupt', callback: Callback\<InterruptEvent>): void on(type: 'interrupt', callback: Callback\<InterruptEvent>): void
Subscribes to audio interrupt events. This API uses a callback to get interrupt events. The interrupt event is triggered when audio rendering is interrupted. Subscribes to audio interruption events. This API uses a callback to get interrupt events.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :-------------------------------------------- | :-------- | :---------------------------------------------- | | -------- | -------------------------------------------- | ---- | ------------------------------------------------------------ |
| type | string | Yes | Type of the playback event to subscribe to. | | 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 listen for interrupt callback. | | callback | Callback<[InterruptEvent](#interruptevent9)> | Yes | Callback used to return the audio interruption event. |
**Example:** **Example**
``` ```
var isPlay; audioRenderer.on('interrupt', (interruptEvent) => {
var started;
audioRenderer.on('interrupt', async(interruptEvent) => {
if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_FORCE) { if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_FORCE) {
switch (interruptEvent.hintType) { switch (interruptEvent.hintType) {
case audio.InterruptHint.INTERRUPT_HINT_PAUSE: case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
...@@ -2581,30 +2512,11 @@ audioRenderer.on('interrupt', async(interruptEvent) => { ...@@ -2581,30 +2512,11 @@ audioRenderer.on('interrupt', async(interruptEvent) => {
switch (interruptEvent.hintType) { switch (interruptEvent.hintType) {
case audio.InterruptHint.INTERRUPT_HINT_RESUME: case audio.InterruptHint.INTERRUPT_HINT_RESUME:
console.log('Resume force paused renderer or ignore'); console.log('Resume force paused renderer or ignore');
await audioRenderer.start().then(async function () { startRenderer();
console.info('AudioInterruptMusic: renderInstant started :SUCCESS ');
started = true;
}).catch((err) => {
console.info('AudioInterruptMusic: renderInstant start :ERROR : '+err.message);
started = false;
});
if (started) {
isPlay = true;
console.info('AudioInterruptMusic Renderer started : isPlay : '+isPlay);
} else {
console.error('AudioInterruptMusic Renderer start failed');
}
break; break;
case audio.InterruptHint.INTERRUPT_HINT_PAUSE: case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
console.log('Choose to pause or ignore'); console.log('Choose to pause or ignore');
if (isPlay == true) { pauseRenderer();
isPlay == false;
console.info('AudioInterruptMusic: Media PAUSE : TRUE');
}
else {
isPlay = true;
console.info('AudioInterruptMusic: Media PLAY : TRUE');
}
break; break;
} }
} }
...@@ -2615,19 +2527,19 @@ audioRenderer.on('interrupt', async(interruptEvent) => { ...@@ -2615,19 +2527,19 @@ audioRenderer.on('interrupt', async(interruptEvent) => {
on(type: 'markReach', frame: number, callback: (position: number) => {}): void on(type: 'markReach', frame: number, callback: (position: number) => {}): void
Subscribes to mark reached events. When the number of frames rendered reaches the value of the frame parameter, the callback is invoked. Subscribes to mark reached events. When the number of frames rendered reaches the value of the **frame** parameter, the callback is invoked.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :------------------------ | :-------- | :----------------------------------------------------------------------- | | :------- | :----------------------- | :--- | :---------------------------------------- |
| type | string | Yes | Type of the renderer event to subscribe to. | | type | string | Yes | Type of event to subscribe to. The value **markReach** means the mark reached event, which is triggered when the number of frames captured reaches the value of the **frame** parameter.|
| frame | number | Yes | Number of frames to trigger the event. The value must be greater than 0. | | frame | number | Yes | Number of frames to trigger the event. The value must be greater than **0**. |
| callback | (position: number) => {} | Yes | Callback invoked when the event is triggered. | | callback | (position: number) => {} | Yes | Callback invoked when the event is triggered. |
**Example:** **Example**
``` ```
audioRenderer.on('markReach', 1000, (position) => { audioRenderer.on('markReach', 1000, (position) => {
...@@ -2644,15 +2556,15 @@ off(type: 'markReach'): void ...@@ -2644,15 +2556,15 @@ off(type: 'markReach'): void
Unsubscribes from mark reached events. Unsubscribes from mark reached events.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| :------- | :------------------------ | :-------- | :----------------------------------------------- | | :----- | :----- | :--- | :------------------------------------------------ |
| type | string | Yes | Type of the renderer event to unsubscribe from. | | type | string | Yes | Type of event to unsubscribe from. The value is fixed at **markReach**.|
**Example:** **Example**
``` ```
audioRenderer.off('markReach'); audioRenderer.off('markReach');
...@@ -2662,19 +2574,19 @@ audioRenderer.off('markReach'); ...@@ -2662,19 +2574,19 @@ audioRenderer.off('markReach');
on(type: "periodReach", frame: number, callback: (position: number) => {}): void on(type: "periodReach", frame: number, callback: (position: number) => {}): void
Subscribes to period reached events. When the period of frame rendering reaches the value of frame parameter, the callback is invoked. Subscribes to period reached events. When the period of frame rendering reaches the value of the **frame** parameter, the callback is invoked.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :------------------------ | :-------- | :--------------------------------------------------------------------------------- | | :------- | :----------------------- | :--- | :------------------------------------------ |
| type | string | Yes | Type of the renderer event to subscribe to. | | type | string | Yes | Type of event to subscribe to. The value **periodReach** means the period reached event, which is triggered when the period of frame rendering reaches the value of the **frame** parameter.|
| frame | number | Yes | Period during which frame rendering is listened. The value must be greater than 0. | | frame | number | Yes | Period during which frame rendering is listened. The value must be greater than **0**. |
| callback | (position: number) => {} | Yes | Callback invoked when the event is triggered. | | callback | (position: number) => {} | Yes | Callback invoked when the event is triggered. |
**Example:** **Example**
``` ```
audioRenderer.on('periodReach', 1000, (position) => { audioRenderer.on('periodReach', 1000, (position) => {
...@@ -2690,15 +2602,15 @@ off(type: 'periodReach'): void ...@@ -2690,15 +2602,15 @@ off(type: 'periodReach'): void
Unsubscribes from period reached events. Unsubscribes from period reached events.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| :------- | :------------------------ | :-------- | :----------------------------------------------- | | :----- | :----- | :--- | :-------------------------------------------------- |
| type | string | Yes | Type of the renderer event to unsubscribe from. | | type | string | Yes | Type of event to unsubscribe from. The value is fixed at **periodReach**.|
**Example:** **Example**
``` ```
audioRenderer.off('periodReach') audioRenderer.off('periodReach')
...@@ -2710,16 +2622,16 @@ on(type: 'stateChange', callback: Callback<AudioState\>): void ...@@ -2710,16 +2622,16 @@ on(type: 'stateChange', callback: Callback<AudioState\>): void
Subscribes to state change events. Subscribes to state change events.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :------------------------- | :-------- | :--------------------------------------------------------------------------------------- | | :------- | :------------------------- | :--- | :------------------------------------------ |
| type | string | Yes | Type of the event to subscribe to. The value 'stateChange' means the state change event. | | type | string | Yes | Type of event to subscribe to. The value **stateChange** means the state change event.|
| callback | [AudioState](#audiostate8) | Yes | Callback used to return the state change. | | callback | [AudioState](#audiostate8) | Yes | Callback used to return the state change. |
**Example:** **Example**
``` ```
audioRenderer.on('stateChange', (state) => { audioRenderer.on('stateChange', (state) => {
...@@ -2734,42 +2646,37 @@ audioRenderer.on('stateChange', (state) => { ...@@ -2734,42 +2646,37 @@ audioRenderer.on('stateChange', (state) => {
## AudioCapturer<sup>8+</sup> ## AudioCapturer<sup>8+</sup>
Provides related APIs for audio capture. Before calling the API of AudioCapturer, you need to create an instance through [createAudioCapturer](#audiocreateaudiocapturer8). Provides APIs for audio capture. Before calling any API in **AudioCapturer**, you must use [createAudioCapturer](#audiocreateaudiocapturer8) to create an **AudioCapturer** instance.
### state<sup>8+</sup>
readonly state: AudioState
Defines the current capture state. ### Attributes
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
| Name | Type | Readable | Writable | Description | | Name | Type | Readable| Writable| Description |
| :---- | :------------------------- | :------- | :------- | :------------------- | | :---- | :------------------------- | :--- | :--- | :--------------- |
| state | [AudioState](#audiostate8) | Yes | No | Audio capture state. | | state<sup>8+</sup> | [AudioState](#audiostate8) | Yes| No | Audio capturer state.|
**Example:** **Example**
``` ```
var state = audioCapturer.state; var state = audioCapturer.state;
``` ```
### getCapturerInfo<sup>8+</sup> ### getCapturerInfo<sup>8+</sup>
getCapturerInfo(callback: AsyncCallback<AudioCapturerInfo\>): void getCapturerInfo(callback: AsyncCallback<AudioCapturerInfo\>): void
Obtains the capturer information provided while creating a capturer instance. This API uses an asynchronous callback to return the result. Obtains the capturer information of this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :------------------------------------------------------- | :-------- | :------------------------------------------------ | | :------- | :-------------------------------- | :--- | :----------------------------------- |
| callback | AsyncCallback<[AudioCapturerInfo](#audiocapturerinfo)\> | Yes | Callback used to return the capturer information. | | callback | AsyncCallback<AudioCapturerInfo\> | Yes | Callback used to return the capturer information.|
**Example:** **Example**
``` ```
audioCapturer.getCapturerInfo((err, capturerInfo) => { audioCapturer.getCapturerInfo((err, capturerInfo) => {
...@@ -2788,17 +2695,17 @@ audioCapturer.getCapturerInfo((err, capturerInfo) => { ...@@ -2788,17 +2695,17 @@ audioCapturer.getCapturerInfo((err, capturerInfo) => {
getCapturerInfo(): Promise<AudioCapturerInfo\> getCapturerInfo(): Promise<AudioCapturerInfo\>
Obtains the capturer information provided while creating a capturer instance. This API uses a promise to return the result. Obtains the capturer information of this **AudioCapturer** instance. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :-------------------------------------------------- | :----------------------------------------------- | | :------------------------------------------------ | :---------------------------------- |
| Promise<[AudioCapturerInfo](#audiocapturerinfo)\> | Promise used to return the capturer information. | | Promise<[AudioCapturerInfo](#audiocapturerinfo)\> | Promise used to return the capturer information.|
**Example:** **Example**
``` ```
audioCapturer.getCapturerInfo().then((audioParamsGet) => { audioCapturer.getCapturerInfo().then((audioParamsGet) => {
...@@ -2813,24 +2720,23 @@ audioCapturer.getCapturerInfo().then((audioParamsGet) => { ...@@ -2813,24 +2720,23 @@ audioCapturer.getCapturerInfo().then((audioParamsGet) => {
}).catch((err) => { }).catch((err) => {
console.log('AudioFrameworkRecLog: CapturerInfo :ERROR: '+err.message); console.log('AudioFrameworkRecLog: CapturerInfo :ERROR: '+err.message);
}); });
``` ```
### getStreamInfo<sup>8+</sup> ### getStreamInfo<sup>8+</sup>
getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void
Obtains the capturer stream information. This API uses an asynchronous callback to return the result. Obtains the stream information of this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :----------------------------------------------------------- | :-------- | :---------------------------------------------- | | :------- | :--------------------------------------------------- | :--- | :------------------------------- |
| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | Yes | Callback used to return the stream information. | | callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | Yes | Callback used to return the stream information.|
**Example:** **Example**
``` ```
audioCapturer.getStreamInfo((err, streamInfo) => { audioCapturer.getStreamInfo((err, streamInfo) => {
...@@ -2850,17 +2756,17 @@ audioCapturer.getStreamInfo((err, streamInfo) => { ...@@ -2850,17 +2756,17 @@ audioCapturer.getStreamInfo((err, streamInfo) => {
getStreamInfo(): Promise<AudioStreamInfo\> getStreamInfo(): Promise<AudioStreamInfo\>
Obtains the capturer stream information. This API uses a promise to return the result. Obtains the stream information of this **AudioCapturer** instance. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :---------------------------------------------------- | :----------------------------------------------- | | :--------------------------------------------- | :------------------------------ |
| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information. | | Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information.|
**Example:** **Example**
``` ```
audioCapturer.getStreamInfo().then((audioParamsGet) => { audioCapturer.getStreamInfo().then((audioParamsGet) => {
...@@ -2872,7 +2778,6 @@ audioCapturer.getStreamInfo().then((audioParamsGet) => { ...@@ -2872,7 +2778,6 @@ audioCapturer.getStreamInfo().then((audioParamsGet) => {
}).catch((err) => { }).catch((err) => {
console.log('getStreamInfo :ERROR: ' + err.message); console.log('getStreamInfo :ERROR: ' + err.message);
}); });
``` ```
### start<sup>8+</sup> ### start<sup>8+</sup>
...@@ -2881,15 +2786,15 @@ start(callback: AsyncCallback<void\>): void ...@@ -2881,15 +2786,15 @@ start(callback: AsyncCallback<void\>): void
Starts capturing. This API uses an asynchronous callback to return the result. Starts capturing. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :---------------------- | :-------- | :-------------------------------------- | | :------- | :------------------- | :--- | :----------------------------- |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | | callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example:** **Example**
``` ```
audioCapturer.start((err) => { audioCapturer.start((err) => {
...@@ -2908,15 +2813,15 @@ start(): Promise<void\> ...@@ -2908,15 +2813,15 @@ start(): Promise<void\>
Starts capturing. This API uses a promise to return the result. Starts capturing. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :------------- | :--------------------------------- | | :------------- | :---------------------------- |
| Promise<void\> | Promise used to return the result. | | Promise<void\> | Promise used to return the result.|
**Example:** **Example**
``` ```
audioCapturer.start().then(() => { audioCapturer.start().then(() => {
...@@ -2939,15 +2844,15 @@ stop(callback: AsyncCallback<void\>): void ...@@ -2939,15 +2844,15 @@ stop(callback: AsyncCallback<void\>): void
Stops capturing. This API uses an asynchronous callback to return the result. Stops capturing. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :---------------------- | :-------- | :------------------------------------- | | :------- | :------------------- | :--- | :----------------------------- |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | | callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example:** **Example**
``` ```
audioCapturer.stop((err) => { audioCapturer.stop((err) => {
...@@ -2966,21 +2871,21 @@ stop(): Promise<void\> ...@@ -2966,21 +2871,21 @@ stop(): Promise<void\>
Stops capturing. This API uses a promise to return the result. Stops capturing. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :------------- | :--------------------------------- | | :------------- | :---------------------------- |
| Promise<void\> | Promise used to return the result. | | Promise<void\> | Promise used to return the result.|
**Example:** **Example**
``` ```
audioCapturer.stop().then(() => { audioCapturer.stop().then(() => {
console.info('AudioFrameworkRecLog: ---------RELEASE RECORD---------'); console.info('AudioFrameworkRecLog: ---------RELEASE RECORD---------');
console.info('AudioFrameworkRecLog: Capturer stopped : SUCCESS'); console.info('AudioFrameworkRecLog: Capturer stopped : SUCCESS');
if ((audioCapturer.state == audio.AudioState.STATE_STOPPED)){ if ((audioCapturer.state == audioCapturer.AudioState.STATE_STOPPED)){
stateFlag=true; stateFlag=true;
console.info('AudioFrameworkRecLog: resultFlag : '+stateFlag); console.info('AudioFrameworkRecLog: resultFlag : '+stateFlag);
} }
...@@ -2990,22 +2895,21 @@ audioCapturer.stop().then(() => { ...@@ -2990,22 +2895,21 @@ audioCapturer.stop().then(() => {
}); });
``` ```
### release<sup>8+</sup> ### release<sup>8+</sup>
release(callback: AsyncCallback<void\>): void release(callback: AsyncCallback<void\>): void
Releases the capturer. This API uses an asynchronous callback to return the result. Releases this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :---------------------- | :-------- | :------------------------------------- | | :------- | :------------------- | :--- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | | callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Example:** **Example**
``` ```
audioCapturer.release((err) => { audioCapturer.release((err) => {
...@@ -3022,31 +2926,31 @@ audioCapturer.release((err) => { ...@@ -3022,31 +2926,31 @@ audioCapturer.release((err) => {
release(): Promise<void\> release(): Promise<void\>
Releases the capturer. This API uses a promise to return the result. Releases this **AudioCapturer** instance. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :------------- | :--------------------------------- | | :------------- | :---------------------------- |
| Promise<void\> | Promise used to return the result. | | Promise<void\> | Promise used to return the result.|
**Example:** **Example**
``` ```
audioCapturer.release().then(() => { audioCapturer.release().then(() => {
console.info('AudioFrameworkRecLog: ---------RELEASE RECORD---------'); console.info('AudioFrameworkRecLog: ---------RELEASE RECORD---------');
console.info('AudioFrameworkRecLog: Capturer release : SUCCESS'); console.info('AudioFrameworkRecLog: Capturer release : SUCCESS');
console.info('AudioFrameworkRecLog: AudioCapturer : STATE : '+audioCapturer.state); console.info('AudioFrameworkRecLog: AudioCapturer : STATE : '+audioCapturer.state);
stateFlag=true; stateFlag=true;
console.info('AudioFrameworkRecLog: stateFlag : '+stateFlag); console.info('AudioFrameworkRecLog: stateFlag : '+stateFlag);
expect(stateFlag).assertTrue();
done();
}).catch((err) => { }).catch((err) => {
console.info('AudioFrameworkRecLog: Capturer stop:ERROR : '+err.message); console.info('AudioFrameworkRecLog: Capturer stop:ERROR : '+err.message);
stateFlag=false stateFlag=false
}); });
``` ```
...@@ -3054,19 +2958,19 @@ audioCapturer.release().then(() => { ...@@ -3054,19 +2958,19 @@ audioCapturer.release().then(() => {
read(size: number, isBlockingRead: boolean, callback: AsyncCallback<ArrayBuffer\>): void read(size: number, isBlockingRead: boolean, callback: AsyncCallback<ArrayBuffer\>): void
Reads the buffer from the audio capturer. This API uses an asynchronous callback to return the result. Reads the buffer. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------------- | :-------------------------- | :-------- | :-------------------------------------------- | | :------------- | :-------------------------- | :--- | :------------------------------- |
| size | number | Yes | Number of bytes to read. | | size | number | Yes | Number of bytes to read. |
| isBlockingRead | boolean | Yes | Whether the read operation should be blocked. | | isBlockingRead | boolean | Yes | Whether to block the read operation. |
| callback | AsyncCallback<ArrayBuffer\> | Yes | Callback used to return the buffer. | | callback | AsyncCallback<ArrayBuffer\> | Yes | Callback used to return the buffer.|
**Example:** **Example**
``` ```
audioCapturer.read(bufferSize, true, async(err, buffer) => { audioCapturer.read(bufferSize, true, async(err, buffer) => {
...@@ -3081,24 +2985,24 @@ audioCapturer.read(bufferSize, true, async(err, buffer) => { ...@@ -3081,24 +2985,24 @@ audioCapturer.read(bufferSize, true, async(err, buffer) => {
read(size: number, isBlockingRead: boolean): Promise<ArrayBuffer\> read(size: number, isBlockingRead: boolean): Promise<ArrayBuffer\>
Reads the buffer from the audio capturer. This API uses a promise to return the result. Reads the buffer. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------------- | :--------- | :-------- | :-------------------------------------------- | | :------------- | :------ | :--- | :--------------- |
| size | number | Yes | Number of bytes to read. | | size | number | Yes | Number of bytes to read. |
| isBlockingRead | boolean | Yes | Whether the read operation should be blocked. | | isBlockingRead | boolean | Yes | Whether to block the read operation.|
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :-------------------- | :----------------------------------------------------------------------------------------------- | | :-------------------- | :----------------------------------------------------- |
| Promise<ArrayBuffer\> | Returns the buffer data read if the operation is successful; returns an error code otherwise. | | Promise<ArrayBuffer\> | Returns the buffer data read if the operation is successful; returns an error code otherwise.|
**Example:** **Example**
``` ```
audioCapturer.read(bufferSize, true).then((buffer) => { audioCapturer.read(bufferSize, true).then((buffer) => {
...@@ -3113,18 +3017,17 @@ audioCapturer.read(bufferSize, true).then((buffer) => { ...@@ -3113,18 +3017,17 @@ audioCapturer.read(bufferSize, true).then((buffer) => {
getAudioTime(callback: AsyncCallback<number\>): void getAudioTime(callback: AsyncCallback<number\>): void
Obtains the timestamp in Unix epoch time (starts from January 1, 1970), in nanoseconds. This API uses an asynchronous callback to return the result. Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :--------------------- | :-------- | :------------------------------------- | | :------- | :--------------------- | :--- | :----------------------------- |
| callback | AsyncCallback<number\> | Yes | Callback used to return the timestamp. | | callback | AsyncCallback<number\> | Yes | Callback used to return the timestamp.|
| | | | |
**Example:** **Example**
``` ```
audioCapturer.getAudioTime((err, timestamp) => { audioCapturer.getAudioTime((err, timestamp) => {
...@@ -3137,17 +3040,17 @@ audioCapturer.getAudioTime((err, timestamp) => { ...@@ -3137,17 +3040,17 @@ audioCapturer.getAudioTime((err, timestamp) => {
getAudioTime(): Promise<number\> getAudioTime(): Promise<number\>
Obtains the timestamp in Unix epoch time (starts from January 1, 1970), in nanoseconds. This API uses a promise to return the result. Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :--------------- | :------------------------------------ | | :--------------- | :---------------------------- |
| Promise<number\> | Promise used to return the timestamp. | | Promise<number\> | Promise used to return the timestamp.|
**Example:** **Example**
``` ```
audioCapturer.getAudioTime().then((audioTime) => { audioCapturer.getAudioTime().then((audioTime) => {
...@@ -3155,7 +3058,6 @@ audioCapturer.getAudioTime().then((audioTime) => { ...@@ -3155,7 +3058,6 @@ audioCapturer.getAudioTime().then((audioTime) => {
}).catch((err) => { }).catch((err) => {
console.info('AudioFrameworkRecLog: AudioCapturer Created : ERROR : '+err.message); console.info('AudioFrameworkRecLog: AudioCapturer Created : ERROR : '+err.message);
}); });
``` ```
...@@ -3165,16 +3067,15 @@ getBufferSize(callback: AsyncCallback<number\>): void ...@@ -3165,16 +3067,15 @@ getBufferSize(callback: AsyncCallback<number\>): void
Obtains a reasonable minimum buffer size in bytes for capturing. This API uses an asynchronous callback to return the result. Obtains a reasonable minimum buffer size in bytes for capturing. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :--------------------- | :-------- | :--------------------------------------- | | :------- | :--------------------- | :--- | :----------------------------------- |
| callback | AsyncCallback<number\> | Yes | Callback used to return the buffer size. | | callback | AsyncCallback<number\> | Yes | Callback used to return the buffer size.|
| | | | |
**Example:** **Example**
``` ```
audioCapturer.getBufferSize((err, bufferSize) => { audioCapturer.getBufferSize((err, bufferSize) => {
...@@ -3189,49 +3090,54 @@ audioCapturer.getBufferSize((err, bufferSize) => { ...@@ -3189,49 +3090,54 @@ audioCapturer.getBufferSize((err, bufferSize) => {
}); });
``` ```
### getBufferSize<sup>8+</sup> ### getBufferSize<sup>8+</sup>
getBufferSize(): Promise<number\> getBufferSize(): Promise<number\>
Obtains a reasonable minimum buffer size in bytes for capturing. This API uses a promise to return the result. Obtains a reasonable minimum buffer size in bytes for capturing. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :--------------- | :-------------------------------------- | | :--------------- | :---------------------------------- |
| Promise<number\> | Promise used to return the buffer size. | | Promise<number\> | Promise used to return the buffer size.|
**Example:** **Example**
``` ```
await audioCapturer.getBufferSize().then(async function (bufferSize) { audioCapturer.getBufferSize().then((bufferSize) => {
console.info('AudioFrameworkRecordLog: getBufferSize :SUCCESS '+ bufferSize); if (!err) {
var buffer = await audioCapturer.read(bufferSize, true); console.log('BufferSize : ' + bufferSize);
audioCapturer.read(bufferSize, true).then((buffer) => {
console.info('Buffer read is ' + buffer ); console.info('Buffer read is ' + buffer );
}).catch((err) => { }).catch((err) => {
console.info('AudioFrameworkRecordLog: getBufferSize :ERROR : '+err.message); console.info('ERROR : '+err.message);
});
}
}); });
``` ```
### on('markReach')<sup>8+</sup> ### on('markReach')<sup>8+</sup>
on(type: 'markReach', frame: number, callback: (position: number) => {}): void on(type: 'markReach', frame: number, callback: (position: number) => {}): void
Subscribes to mark reached events. When the number of frames captured reaches the value of the frame parameter, the callback is invoked. Subscribes to mark reached events. When the number of frames captured reaches the value of the **frame** parameter, the callback is invoked.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :------------------------ | :-------- | :----------------------------------------------------------------------- | | :------- | :---------------------- | :--- | :----------------------------------------- |
| type | string | Yes | Type of the capturer event to subscribe to. | | type | string | Yes | Type of event to subscribe to. The value **markReach** means the mark reached event, which is triggered when the number of frames captured reaches the value of the **frame** parameter. |
| frame | number | Yes | Number of frames to trigger the event. The value must be greater than 0. | | frame | number | Yes | Number of frames to trigger the event. The value must be greater than **0**. |
| callback | position: number) => {} | Yes | Callback invoked when the event is triggered. | | callback | position: number) => {} | Yes | Callback invoked when the event is triggered.|
**Example:** **Example**
``` ```
audioCapturer.on('markReach', 1000, (position) => { audioCapturer.on('markReach', 1000, (position) => {
...@@ -3241,22 +3147,21 @@ audioCapturer.on('markReach', 1000, (position) => { ...@@ -3241,22 +3147,21 @@ audioCapturer.on('markReach', 1000, (position) => {
}); });
``` ```
### off('markReach')<sup>8+</sup> ### off('markReach')<sup>8+</sup>
off(type: 'markReach'): void off(type: 'markReach'): void
Unsubscribes from the mark reached events. Unsubscribes from mark reached events.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| :------- | :------------------------ | :-------- | :---------------------------------------------- | | :----- | :----- | :--- | :-------------------------------------------- |
| type | string | Yes | Type of the capturer event to unsubscribe from. | | type | string | Yes | Type of event to unsubscribe from. The value **markReach** means the mark reached event, which is triggered when the number of frames captured reaches the value of the **frame** parameter.|
**Example:** **Example**
``` ```
audioCapturer.off('markReach'); audioCapturer.off('markReach');
...@@ -3266,19 +3171,19 @@ audioCapturer.off('markReach'); ...@@ -3266,19 +3171,19 @@ audioCapturer.off('markReach');
on(type: "periodReach", frame: number, callback: (position: number) => {}): void on(type: "periodReach", frame: number, callback: (position: number) => {}): void
Subscribes to period reached events. When the period of frame capturing reaches the value of frame parameter, the callback is invoked. Subscribes to mark reached events. When the period of frame capturing reaches the value of the **frame** parameter, the callback is invoked.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :------------------------ | :-------- | :--------------------------------------------------------------------------------- | | :------- | :----------------------- | :--- | :------------------------------------------ |
| type | string | Yes | Type of the capturer event to subscribe to. | | type | string | Yes | Type of event to subscribe to. The value **periodReach** means the period reached event, which is triggered when the period of frame capturing reaches the value of the **frame** parameter.|
| frame | number | Yes | Period during which frame capturing is listened. The value must be greater than 0. | | frame | number | Yes | Period during which frame rendering is listened. The value must be greater than **0**. |
| callback | (position: number) => {} | Yes | Callback invoked when the event is triggered. | | callback | (position: number) => {} | Yes | Callback invoked when the event is triggered. |
**Example:** **Example**
``` ```
audioCapturer.on('periodReach', 1000, (position) => { audioCapturer.on('periodReach', 1000, (position) => {
...@@ -3294,15 +3199,15 @@ off(type: 'periodReach'): void ...@@ -3294,15 +3199,15 @@ off(type: 'periodReach'): void
Unsubscribes from period reached events. Unsubscribes from period reached events.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| :------- | :------------------------ | :-------- | :---------------------------------------------- | | :----- | :----- | :--- | :---------------------------------------------- |
| type | string | Yes | Type of the capturer event to unsubscribe from. | | type | string | Yes | Type of event to unsubscribe from. The value **periodReach** means the period reached event, which is triggered when the period of frame capturing reaches the value of the **frame** parameter.|
**Example:** **Example**
``` ```
audioCapturer.off('periodReach') audioCapturer.off('periodReach')
...@@ -3314,16 +3219,16 @@ on(type: 'stateChange', callback: Callback<AudioState\>): void ...@@ -3314,16 +3219,16 @@ on(type: 'stateChange', callback: Callback<AudioState\>): void
Subscribes to state change events. Subscribes to state change events.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :------------------------- | :-------- | :--------------------------------------------------------------------------------------- | | :------- | :------------------------- | :--- | :------------------------------------------ |
| type | string | Yes | Type of the event to subscribe to. The value 'stateChange' means the state change event. | | type | string | Yes | Type of event to subscribe to. The value **stateChange** means the state change event.|
| callback | [AudioState](#audiostate8) | Yes | Callback used to return the state change. | | callback | [AudioState](#audiostate8) | Yes | Callback used to return the state change. |
**Example:** **Example**
``` ```
audioCapturer.on('stateChange', (state) => { audioCapturer.on('stateChange', (state) => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册