diff --git a/en/application-dev/reference/apis/js-apis-audio.md b/en/application-dev/reference/apis/js-apis-audio.md index 3e402a624431cf425c664aea4a2eb2de7da97838..a9eca8e2656bc76830215358751cee5af4000e63 100644 --- a/en/application-dev/reference/apis/js-apis-audio.md +++ b/en/application-dev/reference/apis/js-apis-audio.md @@ -1,74 +1,58 @@ -# Audio +# Audio Management -> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** -> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. +> **NOTE** +> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. -## Modules to Import +This module provides the following common audio-related functions: + +- [AudioManager](#audiomanager): Audio management. +- [AudioRenderer](#audiorenderer8): Audio rendering, used to play Pulse Code Modulation (PCM) audio data. +- [AudioCapturer](#audiocapturer8): Audio capture, used to record PCM audio data. + +## Modules to Import ``` import audio from '@ohos.multimedia.audio'; ``` -## Required Permissions - -None - -## audioManager +## audio.getAudioManager -### audio.getAudioManager +getAudioManager(): AudioManager -getAudioManager\(\): AudioManager +Obtains an **AudioManager** instance. -Obtains an **AudioManager** instance. +**System capability:** SystemCapability.Multimedia.Audio.Core -**System capabilities**: SystemCapability.Multimedia.Audio.Core +**Return value:** -**Return value** +| Type | Description | +| ----------------------------- | -------------------- | +| [AudioManager](#audiomanager) | AudioManager object. | - - - - - - - - - -

Type

-

Description

-

AudioManager

-

AudioManager object.

-
- -**Example** +**Example:** ``` var audioManager = audio.getAudioManager(); ``` -## audioRenderer - -### audio.createAudioRenderer - -createAudioRenderer(options: AudioRendererOptions, callback: AsyncCallback): void +## audio.createAudioRenderer8+ -Obtains an **AudioRenderer** instance. This method uses an asynchronous callback to return the renderer instance. +createAudioRenderer(options: AudioRendererOptions, callback: AsyncCallback\): void -**System capabilities**: SystemCapability.Multimedia.Audio.Renderer +Obtains an **AudioRenderer** instance. This API uses an asynchronous callback to return the renderer instance. -**Parameters** -| Name | Type | Mandatory | Description | -| :--------- | :--------------------------- | :-------- | :--------------------------------------------------- | -| options | AudioRendererOptions | Yes | Renderer configurations. | -| callback | AsyncCallback | Yes | Callback used to return the audio renderer instance. | +**System capability:** SystemCapability.Multimedia.Audio.Renderer -**Return value** +**Parameters:** +| Name | Type | Mandatory | Description | +| :--------- | :---------------------------------------------- | :-------- | :--------------------------------------------------- | +| options | [AudioRendererOptions](#audiorendereroptions8) | Yes | Renderer configurations. | +| callback | AsyncCallback<[AudioRenderer](#audiorenderer8)> | Yes | Callback used to return the audio renderer instance. | -None - -**Example** +**Example:** ``` +import audio from '@ohos.multimedia.audio'; var audioStreamInfo = { samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100, channels: audio.AudioChannel.CHANNEL_1, @@ -89,36 +73,38 @@ var audioRendererOptions = { audio.createAudioRenderer(audioRendererOptions,(err, data) => { if (err) { - console.error(`AudioRender Created : Error: ${err.message}`); + console.error(`AudioRenderer Created : Error: ${err.message}`); } else { - console.info('AudioRender Created : Success : SUCCESS'); - audioRenderer = data; + console.info('AudioRenderer Created : Success : SUCCESS'); + let audioRenderer = data; } }); ``` -### audio.createAudioRenderer +## audio.createAudioRenderer8+ -createAudioRenderer(options: AudioRendererOptions): Promise +createAudioRenderer(options: AudioRendererOptions): Promise -Obtains an **AudioRenderer** instance. This method uses a promise to return the renderer instance. +Obtains an **AudioRenderer** instance. This API uses a promise to return the renderer instance. -**System capabilities**: SystemCapability.Multimedia.Audio.Renderer +**System capability:** SystemCapability.Multimedia.Audio.Renderer -**Parameters** -| Name | Type | Mandatory | Description | -| :--------- | :--------------------------- | :-------- | :--------------------------------------------------- | -| options | AudioRendererOptions | Yes | Renderer configurations. | +**Parameters:** +| Name | Type | Mandatory | Description | +| :--------- | :--------------------------------------------- | :-------- | :---------------------------| +| options | [AudioRendererOptions](#audiorendereroptions8) | Yes | Renderer configurations. | -**Return value** +**Return value:** -| Type | Description | -| ---------------------- | --------------------------------------------------- | -| Promise | Promise used to return the audio renderer instance. | +| Type | Description | +| ----------------------------------------- | --------------------------------------------------- | +| Promise<[AudioRenderer](#audiorenderer8)> | Promise used to return the audio renderer instance. | -**Example** +**Example:** ``` +import audio from '@ohos.multimedia.audio'; + var audioStreamInfo = { samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100, channels: audio.AudioChannel.CHANNEL_1, @@ -137,32 +123,33 @@ var audioRendererOptions = { rendererInfo: audioRendererInfo } -let audioRenderer = await audio.createAudioRenderer(audioRendererOptions); +var audioRenderer; +audio.createAudioRenderer(audioRendererOptions).then((data) => { + audioRenderer = data; + console.info('AudioFrameworkRenderLog: AudioRenderer Created : Success : Stream Type: SUCCESS'); +}).catch((err) => { + console.info('AudioFrameworkRenderLog: AudioRenderer Created : ERROR : '+err.message); +}); ``` -## audioCapturer - -### audio.createAudioCapturer - -createAudioCapturer(options: AudioCapturerOptions, callback: AsyncCallback): void - -Obtains an **AudioCapturer** instance. This method uses an asynchronous callback to return the capturer instance. +## audio.createAudioCapturer8+ -**System capabilities**: SystemCapability.Multimedia.Audio.Capturer +createAudioCapturer(options: AudioCapturerOptions, callback: AsyncCallback): void -**Parameters** -| Name | Type | Mandatory | Description | -| :--------- | :--------------------------- | :-------- | :--------------------------------------------------- | -| options | AudioCapturerOptions | Yes | Capturer configurations. | -| callback | AsyncCallback | Yes | Callback used to return the audio capturer instance. | +Obtains an **AudioCapturer** instance. This API uses an asynchronous callback to return the capturer instance. -**Return value** +**System capability:** SystemCapability.Multimedia.Audio.Capturer -None +**Parameters:** +| Name | Type | Mandatory | Description | +| :--------- | :---------------------------------------------- | :-------- | :--------------------------------------------------- | +| options | [AudioCapturerOptions](#AudioCapturerOptions) | Yes | Capturer configurations. | +| callback | AsyncCallback<[AudioCapturer](#audiocapturer8)> | Yes | Callback used to return the audio capturer instance. | -**Example** +**Example:** ``` +import audio from '@ohos.multimedia.audio'; var audioStreamInfo = { samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100, channels: audio.AudioChannel.CHANNEL_2, @@ -186,33 +173,35 @@ audio.createAudioCapturer(audioCapturerOptions,(err, data) => { } else { console.info('AudioCapturer Created : Success : SUCCESS'); - audioCapturer = data; + let audioCapturer = data; } }); ``` -### audio.createAudioCapturer +## audio.createAudioCapturer8+ -createAudioCapturer(options: AudioCapturerOptions): Promise +createAudioCapturer(options: AudioCapturerOptions): Promise -Obtains an **AudioCapturer** instance. This method uses a promise to return the capturer instance. +Obtains an **AudioCapturer** instance. This API uses a promise to return the capturer instance. -**System capabilities**: SystemCapability.Multimedia.Audio.Capturer +**System capability:** SystemCapability.Multimedia.Audio.Capturer -**Parameters** -| Name | Type | Mandatory | Description | -| :--------- | :--------------------------- | :-------- | :--------------------------------------------------- | -| options | AudioCapturerOptions | Yes | Capturer configurations. | +**Parameters:** +| Name | Type | Mandatory | Description | +| :--------- | :-------------------------------------------- | :-------- | :-------------------------- | +| options | [AudioCapturerOptions](#AudioCapturerOptions) | Yes | Capturer configurations. | -**Return value** +**Return value:** -| Type | Description | -| ---------------------- | --------------------------------------------------- | -| Promise | Promise used to return the audio capturer instance. | +| Type | Description | +| ----------------------------------------- | --------------------------------------------------- | +| Promise<[AudioCapturer](#audiocapturer8)> | Promise used to return the audio capturer instance. | -**Example** +**Example:** ``` +import audio from '@ohos.multimedia.audio'; + var audioStreamInfo = { samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100, channels: audio.AudioChannel.CHANNEL_2, @@ -226,672 +215,507 @@ var audioCapturerInfo = { } var audioCapturerOptions = { - streamInfo: AudioStreamInfo, - capturerInfo: AudioCapturerInfo + streamInfo: audioStreamInfo, + capturerInfo: audioCapturerInfo } -let audioCapturer = await audio.createAudioCapturer(audioCapturerOptions); +var audioCapturer; +audio.createAudioRenderer(audioCapturerOptions).then((data) => { + audioCapturer = data; + console.info('AudioCapturer Created : Success : Stream Type: SUCCESS'); +}).catch((err) => { + console.info('AudioCapturer Created : ERROR : '+err.message); +}); ``` -## AudioVolumeType +## AudioVolumeType Enumerates audio stream types. - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Default Value

-

Description

-

VOICE_CALL

-

0

-

Audio stream for voice calls.
System capabilities: SystemCapability.Multimedia.Audio.Volume

-

RINGTONE

-

2

-

Audio stream for ringtones.
System capabilities: SystemCapability.Multimedia.Audio.Volume

-

MEDIA

-

3

-

Audio stream for media purpose.
System capabilities: SystemCapability.Multimedia.Audio.Volume

-

VOICE_ASSISTANT

-

9

-

Audio stream for voice assistant.
System capabilities: SystemCapability.Multimedia.Audio.Volume

-
+**System capability:** SystemCapability.Multimedia.Audio.Volume +| Name | Default Value | Description | +| ---------------------------- | -------------- | --------------------------------- | +| VOICE_CALL8+ | 0 | Audio stream for voice calls. | +| RINGTONE | 2 | Audio stream for ringtones. | +| MEDIA | 3 | Audio stream for media purpose. | +| VOICE_ASSISTANT8+ | 9 | Audio stream for voice assistant. | -## DeviceFlag +## DeviceFlag Enumerates audio device flags. - - - - - - - - - - - - - - - - - - - -

Name

-

Default Value

-

Description

-

OUTPUT_DEVICES_FLAG

-

1

-

Output device.
System capabilities: SystemCapability.Multimedia.Audio.Device

-

INPUT_DEVICES_FLAG

-

2

-

Input device.
System capabilities: SystemCapability.Multimedia.Audio.Device

-

ALL_DEVICES_FLAG

-

3

-

All devices.
System capabilities: SystemCapability.Multimedia.Audio.Device

-
+**System capability:** SystemCapability.Multimedia.Audio.Device +| Name | Default Value | Description | +| ------------------- | ------------- | -------------- | +| OUTPUT_DEVICES_FLAG | 1 | Output device. | +| INPUT_DEVICES_FLAG | 2 | Input device. | +| ALL_DEVICES_FLAG | 3 | All devices. | -## DeviceRole + +## DeviceRole Enumerates audio device roles. - - - - - - - - - - - - - - - -

Name

-

Default Value

-

Description

-

INPUT_DEVICE

-

1

-

Input role.
System capabilities: SystemCapability.Multimedia.Audio.Device

-

OUTPUT_DEVICE

-

2

-

Output role.
System capabilities: SystemCapability.Multimedia.Audio.Device

-
+**System capability:** SystemCapability.Multimedia.Audio.Device +| Name | Default Value | Description | +| ------------- | ------------- | ------------ | +| INPUT_DEVICE | 1 | Input role. | +| OUTPUT_DEVICE | 2 | Output role. | -## DeviceType +## DeviceType Enumerates audio device types. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Default Value

-

Description

-

INVALID

-

0

-

Invalid device.
System capabilities: SystemCapability.Multimedia.Audio.Device

-

SPEAKER

-

2

-

Speaker.
System capabilities: SystemCapability.Multimedia.Audio.Device

-

WIRED_HEADSET

-

3

-

Wired headset.
System capabilities: SystemCapability.Multimedia.Audio.Device

-

BLUETOOTH_SCO

-

7

-

Bluetooth device using the synchronous connection oriented (SCO) link.
System capabilities: SystemCapability.Multimedia.Audio.Device

-

BLUETOOTH_A2DP

-

8

-

Bluetooth device using the advanced audio distribution profile (A2DP).
System capabilities: SystemCapability.Multimedia.Audio.Device

-

MIC

-

15

-

Microphone.
System capabilities: SystemCapability.Multimedia.Audio.Device

-

USB_HEADSET

-

22

-

USB Type-C Headset.
System capabilities: SystemCapability.Multimedia.Audio.Device

-
+**System capability:** SystemCapability.Multimedia.Audio.Device + +| Name | Default Value | Description | +| ---------------- | ------------- | ------------------------------------------------------------------------ | +| INVALID | 0 | Invalid device. | +| EARPIECE | 1 | Earpiece. | +| SPEAKER | 2 | Speaker. | +| WIRED_HEADSET | 3 | Wired headset. | +| WIRED_HEADPHONES | 4 | Wired headset without microphone. | +| BLUETOOTH_SCO | 7 | Bluetooth device using Synchronous Connection Oriented (SCO) links. | +| BLUETOOTH_A2DP | 8 | Bluetooth device using Advanced Audio Distribution Profile (A2DP) links. | +| MIC | 15 | Microphone. | +| USB_HEADSET | 22 | USB Type-C headset. | ## ActiveDeviceType Enumerates the active device types. -| Name | Default Value | Default Value | -| ------------- | ------ | ------------------------------------------------------------ | -| SPEAKER | 2 | Speaker.
**System capabilities:** SystemCapability.Multimedia.Audio.Device | -| BLUETOOTH_SCO | 7 | Bluetooth device using the SCO link.
**System capabilities:** SystemCapability.Multimedia.Audio.Device | - +**System capability:** SystemCapability.Multimedia.Audio.Device +| Name | Default Value | Description | +| ------------- | ------------- | ---------------------------------------------------------------------- | +| SPEAKER | 2 | Speaker. | +| BLUETOOTH_SCO | 7 | Bluetooth device using the SCO links. | ## AudioRingMode Enumerates ringer modes. - - - - - - - - - - - - - - - - - - - -

Name

-

Default Value

-

Description

-

RINGER_MODE_SILENT

-

0

-

Silence mode.
System capabilities: SystemCapability.Multimedia.Audio.Communication

-

RINGER_MODE_VIBRATE

-

1

-

Vibration mode.
System capabilities: SystemCapability.Multimedia.Audio.Communication

-

RINGER_MODE_NORMAL

-

2

-

Normal mode.
System capabilities: SystemCapability.Multimedia.Audio.Communication

-
+**System capability:** SystemCapability.Multimedia.Audio.Communication +| Name | Default Value | Description | +| ------------------- | ------------- | ---------------- | +| RINGER_MODE_SILENT | 0 | Silent mode. | +| RINGER_MODE_VIBRATE | 1 | Vibration mode. | +| RINGER_MODE_NORMAL | 2 | Normal mode. | + +## AudioSampleFormat8+ -## AudioSampleFormat8+ Enumerates the audio sample formats. -| Name | Default Value | Description | -| :-------------------- | :------------ | :----------------------------------------------------------------------------------------------------- | -| SAMPLE_FORMAT_INVALID | -1 | Invalid format.
System capabilities: SystemCapability.Multimedia.Audio.Core | -| SAMPLE_FORMAT_U8 | 0 | Unsigned 8 bit integer.
System capabilities: SystemCapability.Multimedia.Audio.Core | -| SAMPLE_FORMAT_S16LE | 1 | Signed 16 bit integer, little endian.
System capabilities: SystemCapability.Multimedia.Audio.Core | -| SAMPLE_FORMAT_S24LE | 2 | Signed 24 bit integer, little endian.
System capabilities: SystemCapability.Multimedia.Audio.Core | -| SAMPLE_FORMAT_S32LE | 3 | Signed 32 bit integer, little endian.
System capabilities: SystemCapability.Multimedia.Audio.Core | +**System capability:** SystemCapability.Multimedia.Audio.Core + +| Name | Default Value | Description | +| :-------------------- | :------------ | :------------------------------------ | +| SAMPLE_FORMAT_INVALID | -1 | Invalid format. | +| SAMPLE_FORMAT_U8 | 0 | Unsigned 8 bit integer. | +| SAMPLE_FORMAT_S16LE | 1 | Signed 16 bit integer, little endian. | +| SAMPLE_FORMAT_S24LE | 2 | Signed 24 bit integer, little endian. | +| SAMPLE_FORMAT_S32LE | 3 | Signed 32 bit integer, little endian. | + +## AudioChannel8+ -## AudioChannel8+ Enumerates the audio channels. -| Name | Default Value | Description | -| :----- | :------------ | :-------------------------------------------------------------------------------- | -| CHANNEL_1 | 0x1 << 0 | Channel count 1.
System capabilities: SystemCapability.Multimedia.Audio.Core | -| CHANNEL_2 | 0x1 << 1 | Channel count 2.
System capabilities: SystemCapability.Multimedia.Audio.Core | +**System capability:** SystemCapability.Multimedia.Audio.Core + +| Name | Default Value | Description | +| :-------- | :------------ | :--------------- | +| CHANNEL_1 | 0x1 << 0 | Channel count 1. | +| CHANNEL_2 | 0x1 << 1 | Channel count 2. | + +## AudioSamplingRate8+ -## AudioSamplingRate8+ Enumerates the audio sampling rates. -| Name | Default Value | Description | -| :---------------- | :------------ | :------------------------------------------------------------------------------------ | -| SAMPLE_RATE_8000 | 8000 | Sampling rate 8000.
System capabilities: SystemCapability.Multimedia.Audio.Core | -| SAMPLE_RATE_11025 | 11025 | Sampling rate 11025.
System capabilities: SystemCapability.Multimedia.Audio.Core | -| SAMPLE_RATE_12000 | 12000 | Sampling rate 12000.
System capabilities: SystemCapability.Multimedia.Audio.Core | -| SAMPLE_RATE_16000 | 16000 | Sampling rate 16000.
System capabilities: SystemCapability.Multimedia.Audio.Core | -| SAMPLE_RATE_22050 | 22050 | Sampling rate 22050.
System capabilities: SystemCapability.Multimedia.Audio.Core | -| SAMPLE_RATE_24000 | 24000 | Sampling rate 24000.
System capabilities: SystemCapability.Multimedia.Audio.Core | -| SAMPLE_RATE_32000 | 32000 | Sampling rate 32000.
System capabilities: SystemCapability.Multimedia.Audio.Core | -| SAMPLE_RATE_44100 | 44100 | Sampling rate 44100.
System capabilities: SystemCapability.Multimedia.Audio.Core | -| SAMPLE_RATE_48000 | 48000 | Sampling rate 48000.
System capabilities: SystemCapability.Multimedia.Audio.Core | -| SAMPLE_RATE_64000 | 64000 | Sampling rate 64000.
System capabilities: SystemCapability.Multimedia.Audio.Core | -| SAMPLE_RATE_96000 | 96000 | Sampling rate 96000.
System capabilities: SystemCapability.Multimedia.Audio.Core | - - -## AudioEncodingType8+ +**System capability:** SystemCapability.Multimedia.Audio.Core + +| Name | Default Value | Description | +| :---------------- | :------------ | :------------------- | +| SAMPLE_RATE_8000 | 8000 | Sampling rate 8000. | +| SAMPLE_RATE_11025 | 11025 | Sampling rate 11025. | +| SAMPLE_RATE_12000 | 12000 | Sampling rate 12000. | +| SAMPLE_RATE_16000 | 16000 | Sampling rate 16000. | +| SAMPLE_RATE_22050 | 22050 | Sampling rate 22050. | +| SAMPLE_RATE_24000 | 24000 | Sampling rate 24000. | +| SAMPLE_RATE_32000 | 32000 | Sampling rate 32000. | +| SAMPLE_RATE_44100 | 44100 | Sampling rate 44100. | +| SAMPLE_RATE_48000 | 48000 | Sampling rate 48000. | +| SAMPLE_RATE_64000 | 64000 | Sampling rate 64000. | +| SAMPLE_RATE_96000 | 96000 | Sampling rate 96000. | + + +## AudioEncodingType8+ + Enumerates the audio encoding types. -| Name | Default Value | Description | -| :-------------------- | :------------- | :------------------------------------------------------------------------------- | -| ENCODING_TYPE_INVALID | -1 | Invalid.
System capabilities: SystemCapability.Multimedia.Audio.Core | -| ENCODING_TYPE_RAW | 0 | PCM encoding.
System capabilities: SystemCapability.Multimedia.Audio.Core | +**System capability:** SystemCapability.Multimedia.Audio.Core + +| Name | Default Value | Description | +| :-------------------- | :------------- | :---------------- | +| ENCODING_TYPE_INVALID | -1 | Invalid. | +| ENCODING_TYPE_RAW | 0 | PCM encoding. | -## ContentType8+ +## ContentType + Enumerates the content types. -| Name | Default Value | Description | -| :------------------------ | :------------ | :------------------------------------------------------------------------------------- | -| CONTENT_TYPE_UNKNOWN | 0 | Unknown content.
System capabilities: SystemCapability.Multimedia.Audio.Core | -| CONTENT_TYPE_SPEECH | 1 | Speech content.
System capabilities: SystemCapability.Multimedia.Audio.Core | -| CONTENT_TYPE_MUSIC | 2 | Music content.
System capabilities: SystemCapability.Multimedia.Audio.Core | -| CONTENT_TYPE_MOVIE | 3 | Movie content.
System capabilities: SystemCapability.Multimedia.Audio.Core | -| CONTENT_TYPE_SONIFICATION | 4 | Notification content.
System capabilities: SystemCapability.Multimedia.Audio.Core | -| CONTENT_TYPE_RINGTONE | 5 | Ringtone content.
System capabilities: 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_RINGTONE8+ | 5 | Ringtone content. | -## StreamUsage8+ +## StreamUsage + Enumerates the stream usage. -| Name | Default Value | Description | -| :--------------------------------- | :------------ | :----------------------------------------------------------------------------------------------- | -| STREAM_USAGE_UNKNOWN | 0 | Unknown usage.
System capabilities: SystemCapability.Multimedia.Audio.Core | -| STREAM_USAGE_MEDIA | 1 | Media usage.
System capabilities: SystemCapability.Multimedia.Audio.Core | -| STREAM_USAGE_VOICE_COMMUNICATION | 2 | Voice communication usage.
System capabilities: SystemCapability.Multimedia.Audio.Core | -| STREAM_USAGE_NOTIFICATION_RINGTONE | 3 | Notification or ringtone usage.
System capabilities: SystemCapability.Multimedia.Audio.Core | +**System capability:** SystemCapability.Multimedia.Audio.Core + +| Name | Default Value | Description | +| :--------------------------------- | :------------ | :-------------------------------- | +| STREAM_USAGE_UNKNOWN | 0 | Unknown usage. | +| STREAM_USAGE_MEDIA | 1 | Media usage. | +| STREAM_USAGE_VOICE_COMMUNICATION | 2 | Voice communication usage. | +| STREAM_USAGE_NOTIFICATION_RINGTONE | 6 | Notification or ringtone usage. | -## AudioState8+ +## AudioState8+ + Enumerates the audio states. -| Name | Default Value | Description | -| :------------- | :------------ | :------------------------- | -| STATE_INVALID | -1 | Invalid state.
System capabilities: SystemCapability.Multimedia.Audio.Core | -| STATE_NEW | 0 | Create New instance state.
System capabilities: SystemCapability.Multimedia.Audio.Core | -| STATE_PREPARED | 1 | Prepared state.
System capabilities: SystemCapability.Multimedia.Audio.Core | -| STATE_RUNNING | 2 | Running state.
System capabilities: SystemCapability.Multimedia.Audio.Core | -| STATE_STOPPED | 3 | Stopped state.
System capabilities: SystemCapability.Multimedia.Audio.Core | -| STATE_RELEASED | 4 | Released state.
System capabilities: SystemCapability.Multimedia.Audio.Core | -| STATE_PAUSED | 5 | Paused state.
System capabilities: SystemCapability.Multimedia.Audio.Core | +**System capability:** SystemCapability.Multimedia.Audio.Core + +| Name | Default Value | Description | +| :------------- | :------------ | :--------------------------- | +| STATE_INVALID | -1 | Invalid state. | +| STATE_NEW | 0 | Creating new instance state. | +| STATE_PREPARED | 1 | Prepared state. | +| STATE_RUNNING | 2 | Running state. | +| STATE_STOPPED | 3 | Stopped state. | +| STATE_RELEASED | 4 | Released state. | +| STATE_PAUSED | 5 | Paused state. | -## AudioRendererRate8+ +## AudioRendererRate8+ + Enumerates the audio renderer rates. -| Name | Default Value | Description | -| :----------------- | :------------ | :-------------------------------------------------------------------------------- | -| RENDER_RATE_NORMAL | 0 | Normal rate.
System capabilities: SystemCapability.Multimedia.Audio.Renderer | -| RENDER_RATE_DOUBLE | 1 | Double rate.
System capabilities: SystemCapability.Multimedia.Audio.Renderer | -| RENDER_RATE_HALF | 2 | Half rate.
System capabilities: SystemCapability.Multimedia.Audio.Renderer | +**System capability:** SystemCapability.Multimedia.Audio.Renderer + +| Name | Default Value | Description | +| :----------------- | :------------ | :------------ | +| RENDER_RATE_NORMAL | 0 | Normal rate. | +| RENDER_RATE_DOUBLE | 1 | Double rate. | +| RENDER_RATE_HALF | 2 | Half rate. | +## InterruptType -## InterruptType8+ Enumerates the interrupt types. -| Name | Default Value | Description | -| :------------------- | :------------ | :-------------------------------------------------------------------------------------------------------- | -| INTERRUPT_TYPE_BEGIN | 1 | Audio playback interruption started.
System capabilities: SystemCapability.Multimedia.Audio.Renderer | -| INTERRUPT_TYPE_END | 2 | Audio playback interruption ended.
System capabilities: SystemCapability.Multimedia.Audio.Renderer | +**System capability:** SystemCapability.Multimedia.Audio.Renderer +| Name | Default Value | Description | +| :------------------- | :------------ | :----------------------------------- | +| INTERRUPT_TYPE_BEGIN | 1 | Audio playback interruption started. | +| INTERRUPT_TYPE_END | 2 | Audio playback interruption ended. | + + +## InterruptForceType9+ -## InterruptForceType8+ Enumerates the interrupt force types. -| Name | Default Value | Description | -| :-------------- | :------------ | :------------------------------------------------------------------------------------------------------------ | -| INTERRUPT_FORCE | 0 | Forced action taken by system.
System capabilities: SystemCapability.Multimedia.Audio.Renderer | -| INTERRUPT_SHARE | 1 | App can choose to take action or ignore.
System capabilities: SystemCapability.Multimedia.Audio.Renderer | +**System capability:** SystemCapability.Multimedia.Audio.Renderer +| Name | Default Value | Description | +| :-------------- | :------------ | :----------------------------------------- | +| INTERRUPT_FORCE | 0 | Forced action taken by system. | +| INTERRUPT_SHARE | 1 | App can choose to take action or ignore. | + +## InterruptHint -## InterruptHint8+ Enumerates the interrupt hints. -| Name | Default Value | Description | -| :-------------------- | :------------ | :---------------------------------------------------------------------------------------------- | -| INTERRUPT_HINT_NONE | 0 | None.
System capabilities: SystemCapability.Multimedia.Audio.Renderer | -| INTERRUPT_HINT_RESUME | 1 | Resume the playback.
System capabilities: SystemCapability.Multimedia.Audio.Renderer | -| INTERRUPT_HINT_PAUSE | 2 | Paused/Pause the playback.
System capabilities: SystemCapability.Multimedia.Audio.Renderer | -| INTERRUPT_HINT_STOP | 3 | Stopped/Stop the playback.
System capabilities: SystemCapability.Multimedia.Audio.Renderer | -| INTERRUPT_HINT_DUCK | 4 | Ducked the playback.
System capabilities: SystemCapability.Multimedia.Audio.Renderer | -| INTERRUPT_HINT_UNDUCK | 5 | Unducked the playback.
System capabilities: SystemCapability.Multimedia.Audio.Renderer | +**System capability:** SystemCapability.Multimedia.Audio.Renderer + +| Name | Default Value | Description | +| :--------------------------------- | :------------ | :--------------------------- | +| INTERRUPT_HINT_NONE8+ | 0 | None. | +| INTERRUPT_HINT_RESUME | 1 | Resume the playback. | +| INTERRUPT_HINT_PAUSE | 2 | Paused/Pause the playback. | +| INTERRUPT_HINT_STOP | 3 | Stopped/Stop the playback. | +| INTERRUPT_HINT_DUCK | 4 | Ducked the playback. | +| INTERRUPT_HINT_UNDUCK8+ | 5 | Unducked the playback. | + +## InterruptActionType + +Enumerates the interrupt event return types. + +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 + +| Name | Default Value | Description | +| :------------- | :------------ | :---------------------------------------- | +| TYPE_ACTIVATED | 0 | Audio interrupt activated. | +| TYPE_INTERRUPT | 1 | Audio interrupted. | + +## AudioStreamInfo8+ -## AudioStreamInfo8+ Describes audio stream information. -**System capabilities**: SystemCapability.Multimedia.Audio.Core +**System capability:** SystemCapability.Multimedia.Audio.Core -**Parameters** +**Parameters:** -| Name | Type | Mandatory | Description | -| :------------ | :-------------------- | :-------- | :-------------------- | -| samplingRate | AudioSamplingRate | Yes | Sampling rate. | -| channels | AudioChannel | Yes | Audio channels. | -| sampleFormat | AudioSampleFormat | Yes | Audio sample format. | -| encodingType | AudioEncodingType | Yes | Audio encoding type. | +| Name | Type | Mandatory | Description | +| :------------ | :---------------------------------------- | :-------- | :-------------------- | +| samplingRate | [AudioSamplingRate](#audiosamplingrate8) | Yes | Sampling rate. | +| channels | [AudioChannel](#audiochannel8) | Yes | Audio channels. | +| sampleFormat | [AudioSampleFormat](#audiosampleformat8) | Yes | Audio sample format. | +| encodingType | [AudioEncodingType](#audioencodingtype8) | Yes | Audio encoding type. | + +## AudioRendererInfo8+ -## AudioRendererInfo8+ Describes audio renderer information. -**System capabilities**: SystemCapability.Multimedia.Audio.Core +**System capability:** SystemCapability.Multimedia.Audio.Core + +**Parameters:** -**Parameters** +| Name | Type | Mandatory | Description | +| :------------ | :-------------------------- | :-------- | :-------------------- | +| contentType | [ContentType](#contenttype) | Yes | Content type. | +| usage | [StreamUsage](#streamusage) | Yes | Stream usage. | +| rendererFlags | number | Yes | Audio renderer flags. | -| Name | Type | Mandatory | Description | -| :------------ | :---------- | :-------- | :-------------------- | -| contentType | ContentType | Yes | Content type. | -| usage | StreamUsage | Yes | Stream usage. | -| rendererFlags | number | Yes | Audio renderer flags. | +## AudioRendererOptions8+ -## AudioRendererOptions8+ Describes audio renderer configuration options. -**System capabilities**: SystemCapability.Multimedia.Audio.Renderer +**System capability:** SystemCapability.Multimedia.Audio.Renderer -**Parameters** +**Parameters:** -| Name | Type | Mandatory | Description | -| :------------ | :---------------- | :-------- | :-------------------- | -| streamInfo | AudioStreamInfo | Yes | Stream information. | -| rendererInfo | AudioRendererInfo | Yes | Renderer information. | +| Name | Type | Mandatory | Description | +| :------------ | :-----------------------------------------| :-------- | :-------------------- | +| streamInfo | [AudioStreamInfo](#audiostreaminfo8) | Yes | Stream information. | +| rendererInfo | [AudioRendererInfo](#audiorendererinfo8) | Yes | Renderer information. | + +## InterruptEvent9+ -## InterruptEvent8+ Describes the interrupt event received by the app when playback is interrupted. -**System capabilities**: SystemCapability.Multimedia.Audio.Renderer +**System capability:** SystemCapability.Multimedia.Audio.Renderer + +**Parameters:** + +| Name | Type | Mandatory | Description | +| :-------- | :-------------------------------------------- | :-------- | :---------------------------------------------------------------- | +| eventType | [InterruptType](#interrupttype) | Yes | Whether the interruption has started or finished. | +| forceType | [InterruptForceType](#interruptforcetype9) | Yes | Whether the action is taken by system or to be taken by the app. | +| hintType | [InterruptHint](#interrupthint) | Yes | Type of action. | + +## AudioInterrupt -**Parameters** +The parameters passed in by the audio listener event. -| Name | Type | Mandatory | Description | -| :-------- | :----------------- | :-------- | :-------------------------------------------------------------------------- | -| eventType | InterruptType | Yes | Indicates whether the interruption has started or finished. | -| forceType | InterruptForceType | Yes | Indicates whether the action is taken by system or to be taken by the app. | -| hintType | InterruptHint | Yes | Indicates the kind of action. | +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 -## VolumeEvent8+ +| Name | Type | Mandatory | Description | +| --------------- | --------------------------- | ---- | ------------------------------------------------------------ | +| streamUsage | [StreamUsage](#streamusage) | Yes | Audio stream usage type. | +| contentType | [ContentType](#contenttype) | Yes | Audio interrupt media type. | +| pauseWhenDucked | boolean | Yes | Whether audio playback can be paused when audio is interrupted (true means audio playback can be paused during audio interruptions and false means the opposite). | + +## InterruptAction + +Callback method for the audio interrupt or audio interrupt activated event. + +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 + +| Name | Type | Mandatory | Description | +| ---------- | ------------------------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ | +| actionType | [InterruptActionType](#interruptactiontype) | Yes | Event return type. TYPE_ACTIVATED is the audio interrupt activated event, and TYPE_INTERRUPT is the audio interrupt event. | +| type | [InterruptType](#interrupttype) | No | Interrupt event type. | +| hint | [InterruptHint](interrupthint) | No | Interrupt event prompts. | +| activated | boolean | No | Acquire/release focus. true indicates that the focus acquisition/release is successful, and false indicates that the focus acquisition/release fails. | + +## VolumeEvent8+ Describes the volume event received by the app when the volume is changed. -**System capabilities**: SystemCapability.Multimedia.Audio.Volume +This is a system API and cannot be called by third-party applications. -**Parameters** +**System capability:** SystemCapability.Multimedia.Audio.Volume -| Name | Type | Mandatory | Description | -| :--------- | :-------------- | :-------- | :--------------------------------------- | -| volumeType | AudioVolumeType | Yes | Volume type of the current stream. | -| volume | number | Yes | Volume level. | -| updateUi | boolean | Yes | Whether to show the volume change in UI. | +**Parameters:** + +| Name | Type | Mandatory | Description | +| :--------- | :---------------------------------- | :-------- | :--------------------------------------- | +| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Volume type of the current stream. | +| volume | number | Yes | Volume level. | +| updateUi | boolean | Yes | Whether to show the volume change in UI. | ## DeviceChangeAction + Describes the device change type and device information. -**System capabilities**: SystemCapability.Multimedia.Audio.Device +**System capability:** SystemCapability.Multimedia.Audio.Device -**Parameters** +**Parameters:** -| Name | Type | Mandatory | Description | -| :------------------ | :--------------------- | :-------- | :------------------ | -| type | DeviceChangeType | Yes | Device change type. | -| deviceDescriptors | AudioDeviceDescriptors | Yes | Device information. | +| Name | Type | Mandatory | Description | +| :------------------ | :------------------------------------------------ | :-------- | :------------------ | +| type | [DeviceChangeType](#DeviceChangeType) | Yes | Device change type. | +| deviceDescriptors | [AudioDeviceDescriptors](#AudioDeviceDescriptors) | Yes | Device information. | ## DeviceChangeType + Enumerates device change types. -| Name | Default Value | Description | -| :--------------------- | :------------ | :---------------------------------------------------------------------------------------- | -| CONNECT | 0 | Device connection.
System capabilities: SystemCapability.Multimedia.Audio.Device | -| DISCONNECT | 1 | Device disconnection.
System capabilities: SystemCapability.Multimedia.Audio.Device | +**System capability:** SystemCapability.Multimedia.Audio.Device + +| Name | Default Value | Description | +| :--------------------- | :------------ | :-------------------- | +| CONNECT | 0 | Device connection. | +| DISCONNECT | 1 | Device disconnection. | ## AudioCapturerInfo8+ + Describes audio capturer information. -**System capabilities**: SystemCapability.Multimedia.Audio.Core +**System capability:** SystemCapability.Multimedia.Audio.Core -**Parameters** +**Parameters:** -| Name | Type | Mandatory | Description | -| :---------------| :----------------| :-------- | :-------------------- | -| source | SourceType | Yes | Audio source type. | -| capturerFlags | number | Yes | Audio capturer flags. | +| Name | Type | Mandatory | Description | +| :---------------| :------------------------- | :-------- | :-------------------- | +| source | [SourceType](#sourcetype) | Yes | Audio source type. | +| capturerFlags | number | Yes | Audio capturer flags. | ## SourceType8+ + Enumerates source types. -| Name | Default Value | Description | -| :--------------------- | :------------ | :------------------------------------------------------------------------------------- | -| SOURCE_TYPE_INVALID | -1 | Invalid source type.
System capabilities: SystemCapability.Multimedia.Audio.Core | -| SOURCE_TYPE_MIC | 0 | Mic source type.
System capabilities: SystemCapability.Multimedia.Audio.Core | +**System capability:** SystemCapability.Multimedia.Audio.Core + +| Name | Default Value | Description | +| :----------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------ | :------------------------------- | +| SOURCE_TYPE_INVALID | -1 | Invalid source type. | +| SOURCE_TYPE_MIC | 0 | Mic source type. | +| SOURCE_TYPE_VOICE_COMMUNICATION(This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR) | 7 | Voice communication source type. | ## AudioScene8+ + Enumerates audio scenes. -| Name | Default Value | Description | -| :--------------------- | :------------ | :------------------------------------------------------------------------------------------------- | -| AUDIO_SCENE_DEFAULT | 0 | Default audio scene.
System capabilities: SystemCapability.Multimedia.Audio.Communication | -| AUDIO_SCENE_RINGING | 1 | Ringing audio scene.
System capabilities: SystemCapability.Multimedia.Audio.Communication | -| AUDIO_SCENE_PHONE_CALL | 2 | Phone call audio scene.
System capabilities: SystemCapability.Multimedia.Audio.Communication | -| AUDIO_SCENE_VOICE_CHAT | 3 | Voice chat audio scene.
System capabilities: SystemCapability.Multimedia.Audio.Communication | - -# AudioManager - -Implements audio volume and audio device management. - -**System capabilities**: SystemCapability.Multimedia.Audio.Core - -## audioManager.setVolume - -setVolume\(volumeType: AudioVolumeType, volume: number, callback: AsyncCallback\): void - -Sets the volume for a stream. This method uses an asynchronous callback to return the result. - -**System capabilities**: SystemCapability.Multimedia.Audio.Volume - -**Parameters** - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

volumeType

-

AudioVolumeType

-

Yes

-

Audio stream type.

-

volume

-

number

-

Yes

-

Volume to set. The value range can be obtained by calling getMinVolume and getMaxVolume.

-

callback

-

AsyncCallback<void>

-

Yes

-

Callback used to return the result.

-
+**System capability:** SystemCapability.Multimedia.Audio.Communication + +| Name | Default Value | Description | +| :------------------------------------------------------------------------------------ | :------------ | :---------------------- | +| AUDIO_SCENE_DEFAULT | 0 | Default audio scene. | +| AUDIO_SCENE_RINGING(system API, not supported by third-party applications) | 1 | Ringing audio scene. | +| AUDIO_SCENE_PHONE_CALL(system API, not supported by third-party applications) | 2 | Phone call audio scene. | +| AUDIO_SCENE_VOICE_CHAT | 3 | Voice chat audio scene. | -**Return value** +## AudioManager -None +Implements audio volume and audio device management. Before calling the interface of AudioManager, you need to create an instance through [getAudioManager](#audiogetaudiomanager). -**Example** +### setVolume + +setVolume\(volumeType: AudioVolumeType, volume: number, callback: AsyncCallback\): void + +Sets the volume for a stream. This API uses an asynchronous callback to return the result. + +**System capability:** SystemCapability.Multimedia.Audio.Volume + +**Parameters:** + +| Name | Type | Mandatory | Description | +| ---------- | ----------------------------------- | --------- | ---------------------------------------------------------------------------------------- | +| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Volume stream type. | +| volume | number | Yes | Volume to set. The value range can be obtained by calling getMinVolume and getMaxVolume. | +| callback | AsyncCallback | Yes | Callback used to return the result. | + +**Example:** ``` -audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10, (err)=>{ - if (err) { - console.error('Failed to set the volume. ${err.message}'); - return; - } - console.log('Callback invoked to indicate a successful volume setting.'); +audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10, (err) => { + if (err) { + console.error('Failed to set the volume. ${err.message}'); + return; + } + console.log('Callback invoked to indicate a successful volume setting.'); }); ``` -## audioManager.setVolume - -setVolume\(volumeType: AudioVolumeType, volume: number\): Promise - -Sets the volume for a stream. This method uses a promise to return the result. - -**System capabilities**: SystemCapability.Multimedia.Audio.Volume - -**Parameters** - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

volumeType

-

AudioVolumeType

-

Yes

-

Audio stream type.

-

volume

-

number

-

Yes

-

Volume to set. The value range can be obtained by calling getMinVolume and getMaxVolume.

-
+### setVolume -**Return value** - - - - - - - - - - -

Type

-

Description

-

Promise<void>

-

Promise used to return the result.

-
+setVolume\(volumeType: AudioVolumeType, volume: number\): Promise + +Sets the volume for a stream. This API uses a promise to return the result. + +**System capability:** SystemCapability.Multimedia.Audio.Volume -**Example** +**Parameters:** + +| Name | Type | Mandatory | Description | +| ---------- | ----------------------------------- | --------- | ---------------------------------------------------------------------------------------- | +| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Volume stream type. | +| volume | number | Yes | Volume to set. The value range can be obtained by calling getMinVolume and getMaxVolume. | + +**Return value:** + +| Type | Description | +| ------------------- | ----------------------------------- | +| Promise | Promise used to return the result. | + +**Example:** ``` -audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(()=> +audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(() => { console.log('Promise returned to indicate a successful volume setting.'); -) -``` - -## audioManager.getVolume - -getVolume\(volumeType: AudioVolumeType, callback: AsyncCallback\): void - -Obtains the volume of a stream. This method uses an asynchronous callback to return the query result. - -**System capabilities**: SystemCapability.Multimedia.Audio.Volume - -**Parameters** - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

volumeType

-

AudioVolumeType

-

Yes

-

Audio stream type.

-

callback

-

AsyncCallback<number>

-

Yes

-

Callback used to return the volume.

-
+}); +``` + +### getVolume -**Return value** +getVolume\(volumeType: AudioVolumeType, callback: AsyncCallback\): void -None +Obtains the volume of a stream. This API uses an asynchronous callback to return the query result. -**Example** +**System capability:** SystemCapability.Multimedia.Audio.Volume + +**Parameters:** + +| Name | Type | Mandatory | Description | +| ---------- | ----------------------------------- | --------- | ------------------------------------ | +| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | +| callback | AsyncCallback | Yes | Callback used to return the volume. | + +**Example:** ``` audioManager.getVolume(audio.AudioVolumeType.MEDIA, (err, value) => { @@ -904,230 +728,106 @@ audioManager.getVolume(audio.AudioVolumeType.MEDIA, (err, value) => { ``` -## audioManager.getVolume +### getVolume -getVolume\(volumeType: AudioVolumeType\): Promise +getVolume\(volumeType: AudioVolumeType\): Promise -Obtains the volume of a stream. This method uses a promise to return the query result. +Obtains the volume of a stream. This API uses a promise to return the query result. -**System capabilities**: SystemCapability.Multimedia.Audio.Volume +**System capability:** SystemCapability.Multimedia.Audio.Volume -**Parameters** +**Parameters:** - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

volumeType

-

AudioVolumeType

-

Yes

-

Audio stream type.

-
+| Name | Type | Mandatory | Description | +| ---------- | ----------------------------------- | --------- | ------------------------------------ | +| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | -**Return value** - - - - - - - - - - -

Type

-

Description

-

Promise<number>

-

Promise used to return the volume.

-
+**Return value:** + +| Type | Description | +| ------------------- | ----------------------------------- | +| Promise | Promise used to return the result. | -**Example** +**Example:** ``` -audioManager.getVolume(audio.AudioVolumeType.MEDIA).then((value) => +audioManager.getVolume(audio.AudioVolumeType.MEDIA).then((value) => { console.log('Promise returned to indicate that the volume is obtained.' + value); -) -``` - - -## audioManager.getMinVolume - -getMinVolume\(volumeType: AudioVolumeType, callback: AsyncCallback\): void - -Obtains the minimum volume allowed for a stream. This method uses an asynchronous callback to return the query result. - -**System capabilities**: SystemCapability.Multimedia.Audio.Volume - -**Parameters** - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

volumeType

-

AudioVolumeType

-

Yes

-

Audio stream type.

-

callback

-

AsyncCallback<number>

-

Yes

-

Callback used to return the minimum volume.

-
+}); +``` + +### getMinVolume + +getMinVolume\(volumeType: AudioVolumeType, callback: AsyncCallback\): void + +Obtains the minimum volume allowed for a stream. This API uses an asynchronous callback to return the query result. -**Return value** +**System capability:** SystemCapability.Multimedia.Audio.Volume -None +**Parameters:** -**Example** +| Name | Type | Mandatory | Description | +| ---------- | ----------------------------------- | --------- | ------------------------------------ | +| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | +| callback | AsyncCallback | Yes | Callback used to return the volume. | + +**Example:** ``` audioManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err, value) => { if (err) { console.error('Failed to obtain the minimum volume. ${err.message}'); - return; + return; } console.log('Callback invoked to indicate that the minimum volume is obtained.' + value); }); ``` -## audioManager.getMinVolume +### getMinVolume getMinVolume\(volumeType: AudioVolumeType\): Promise -Obtains the minimum volume allowed for a stream. This method uses a promise to return the query result. - -**System capabilities**: SystemCapability.Multimedia.Audio.Volume - -**Parameters** - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

volumeType

-

AudioVolumeType

-

Yes

-

Audio stream type.

-
+Obtains the minimum volume allowed for a stream. This API uses a promise to return the query result. -**Return value** - - - - - - - - - - -

Type

-

Description

-

Promise<number>

-

Promise used to return the minimum volume.

-
+**System capability:** SystemCapability.Multimedia.Audio.Volume -**Example** - -``` -audioManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value) => - console.log('Promised returned to indicate that the minimum volume is obtained.' + value); -) -``` - - -## audioManager.getMaxVolume - -getMaxVolume\(volumeType: AudioVolumeType, callback: AsyncCallback\): void - -Obtains the maximum volume allowed for a stream. This method uses an asynchronous callback to return the query result. - -**System capabilities**: SystemCapability.Multimedia.Audio.Volume - -**Parameters** - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

volumeType

-

AudioVolumeType

-

Yes

-

Audio stream type.

-

callback

-

AsyncCallback<number>

-

Yes

-

Callback used to return the maximum volume.

-
+**Parameters:** + +| Name | Type | Mandatory | Description | +| ---------- | ----------------------------------- | --------- | ------------------------------------ | +| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | -**Return value** +**Return value:** -None +| Type | Description | +| ------------------- | ----------------------------------- | +| Promise | Promise used to return the result. | -**Example** +**Example:** + +``` +audioManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value) => { + console.log('Promised returned to indicate that the minimum volume is obtained.' + value); +}); +``` + +### getMaxVolume + +getMaxVolume\(volumeType: AudioVolumeType, callback: AsyncCallback\): void + +Obtains the maximum volume allowed for a stream. This API uses an asynchronous callback to return the query result. + +**System capability:** SystemCapability.Multimedia.Audio.Volume + +**Parameters:** + +| Name | Type | Mandatory | Description | +| ---------- | ----------------------------------- | --------- | ------------------------------------ | +| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | +| callback | AsyncCallback | Yes | Callback used to return the volume. | + +**Example:** ``` audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA, (err, value) => { @@ -1140,247 +840,109 @@ audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA, (err, value) => { ``` -## audioManager.getMaxVolume +### getMaxVolume -getMaxVolume\(volumeType: AudioVolumeType\): Promise +getMaxVolume\(volumeType: AudioVolumeType\): Promise -Obtains the maximum volume allowed for a stream. This method uses a promise to return the query result. +Obtains the maximum volume allowed for a stream. This API uses a promise to return the query result. -**System capabilities**: SystemCapability.Multimedia.Audio.Volume +**System capability:** SystemCapability.Multimedia.Audio.Volume -**Parameters** +**Parameters:** - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

volumeType

-

AudioVolumeType

-

Yes

-

Audio stream type.

-
+| Name | Type | Mandatory | Description | +| ---------- | ----------------------------------- | --------- | ------------------------------------ | +| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | -**Return value** - - - - - - - - - - -

Type

-

Description

-

Promise<number>

-

Promise used to return the maximum volume.

-
+**Return value:** + +| Type | Description | +| ------------------- | ----------------------------------- | +| Promise | Promise used to return the result. | -**Example** +**Example:** ``` -audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data)=> +audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data) => { console.log('Promised returned to indicate that the maximum volume is obtained.'); -) +}); ``` -## audioManager.mute +### mute mute\(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback\): void -Mutes a stream. This method uses an asynchronous callback to return the result. - -**System capabilities**: SystemCapability.Multimedia.Audio.Volume - -**Parameters** - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

volumeType

-

AudioVolumeType

-

Yes

-

Audio stream type.

-

mute

-

boolean

-

Yes

-

Mute status to set. The value true means to mute the stream, and false means the opposite.

-

callback

-

AsyncCallback<void>

-

Yes

-

Callback used to return the result.

-
+Mutes a stream. This API uses an asynchronous callback to return the result. -**Return value** +**System capability:** SystemCapability.Multimedia.Audio.Volume -None +**Parameters:** -**Example** +| Name | Type | Mandatory | Description | +| ---------- | ----------------------------------- | --------- | ------------------------------------------------------------------------------------------ | +| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | +| mute | boolean | Yes | Mute status to set. The value true means to mute the stream, and false means the opposite. | +| callback | AsyncCallback | Yes | Callback used to return the volume. | + +**Example:** ``` audioManager.mute(audio.AudioVolumeType.MEDIA, true, (err) => { if (err) { console.error('Failed to mute the stream. ${err.message}'); - return; + return; } console.log('Callback invoked to indicate that the stream is muted.'); }); ``` -## audioManager.mute +### mute mute\(volumeType: AudioVolumeType, mute: boolean\): Promise -Mutes a stream. This method uses a promise to return the result. - -**System capabilities**: SystemCapability.Multimedia.Audio.Volume - -**Parameters** - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

volumeType

-

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.

-
+Mutes a stream. This API uses a promise to return the result. -**Return value** - - - - - - - - - - -

Type

-

Description

-

Promise<void>

-

Promise used to return the result.

-
+**System capability:** SystemCapability.Multimedia.Audio.Volume + +**Parameters:** + +| Name | Type | Mandatory | Description | +| ---------- | ----------------------------------- | --------- | ------------------------------------------------------------------------------------------ | +| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | +| mute | boolean | Yes | Mute status to set. The value true means to mute the stream, and false means the opposite. | -**Example** +**Return value:** + +| Type | Description | +| ------------------- | ----------------------------------- | +| Promise | Promise used to return the result. | + +**Example:** ``` -audioManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => +audioManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => { console.log('Promise returned to indicate that the stream is muted.'); -) +}); ``` -## audioManager.isMute +### isMute isMute\(volumeType: AudioVolumeType, callback: AsyncCallback\): void -Checks whether a stream is muted. This method uses an asynchronous callback to return the query result. - -**System capabilities**: SystemCapability.Multimedia.Audio.Volume - -**Parameters** - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

volumeType

-

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.

-
+Checks whether a stream is muted. This API uses an asynchronous callback to return the query result. -**Return value** +**System capability:** SystemCapability.Multimedia.Audio.Volume -None +**Parameters:** -**Example** +| Name | Type | Mandatory | Description | +| ---------- | ----------------------------------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------- | +| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | +| callback | AsyncCallback | Yes | Callback used to return the mute status of the stream. The value true means that the stream is muted, and false means the opposite.| + +**Example:** ``` audioManager.isMute(audio.AudioVolumeType.MEDIA, (err, value) => { @@ -1393,230 +955,107 @@ audioManager.isMute(audio.AudioVolumeType.MEDIA, (err, value) => { ``` -## audioManager.isMute +### isMute isMute\(volumeType: AudioVolumeType\): Promise -Checks whether a stream is muted. This method uses a promise to return the result. - -**System capabilities**: SystemCapability.Multimedia.Audio.Volume - -**Parameters** - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

volumeType

-

AudioVolumeType

-

Yes

-

Audio stream type.

-
+Checks whether a stream is muted. This API uses a promise to return the result. -**Return value** - - - - - - - - - - -

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.

-
+**System capability:** SystemCapability.Multimedia.Audio.Volume + +**Parameters:** -**Example** +| Name | Type | Mandatory | Description | +| ---------- | ----------------------------------- | --------- | ------------------- | +| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | + +**Return value:** + +| Type | Description | +| ------------------- | ----------------------------------------------------------------------------------------------------------------------------------- | +| Promise | Promise used to return the mute status of the stream. The value true means that the stream is muted, and false means the opposite. | + +**Example:** ``` -audioManager.isMute(audio.AudioVolumeType.MEDIA).then((value) => +audioManager.isMute(audio.AudioVolumeType.MEDIA).then((value) => { console.log('Promise returned to indicate that the mute status of the stream is obtained.' + value); -) +}); ``` - -## audioManager.isActive +### isActive isActive\(volumeType: AudioVolumeType, callback: AsyncCallback\) -Checks whether a stream is active. This method uses an asynchronous callback to return the query result. - -**System capabilities**: SystemCapability.Multimedia.Audio.Volume - -**Parameters** - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

volumeType

-

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.

-
+Checks whether a stream is active. This API uses an asynchronous callback to return the query result. -**Return value** +**System capability:** SystemCapability.Multimedia.Audio.Volume -None +**Parameters:** -**Example** +| Name | Type | Mandatory | Description | +| ---------- | ----------------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------- | +| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | +| callback | AsyncCallback | Yes | Callback used to return the active status of the stream. The value true means that the stream is active, and false means the opposite.| + +**Example:** ``` audioManager.isActive(audio.AudioVolumeType.MEDIA, (err, value) => { if (err) { console.error('Failed to obtain the active status of the stream. ${err.message}'); - return; + return; } console.log('Callback invoked to indicate that the active status of the stream is obtained.' + value); }); ``` -## audioManager.isActive +### isActive isActive\(volumeType: AudioVolumeType\): Promise -Checks whether a stream is active. This method uses a promise to return the query result. - -**System capabilities**: SystemCapability.Multimedia.Audio.Volume - -**Parameters** - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

volumeType

-

AudioVolumeType

-

Yes

-

Audio stream type.

-
+Checks whether a stream is active. This API uses a promise to return the query result. -**Return value** - - - - - - - - - - -

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.

-
+**System capability:** SystemCapability.Multimedia.Audio.Volume + +**Parameters:** + +| Name | Type | Mandatory | Description | +| ---------- | ----------------------------------- | --------- | ------------------ | +| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | -**Example** +**Return value:** + +| Type | Description | +| ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- | +| Promise | Promise used to return the active status of the stream. The value true means that the stream is active, and false means the opposite. | + +**Example:** ``` -audioManager.isActive(audio.AudioVolumeType.MEDIA).then((value) => +audioManager.isActive(audio.AudioVolumeType.MEDIA).then((value) => { console.log('Promise returned to indicate that the active status of the stream is obtained.' + value); -) +}); ``` -## audioManager.setRingerMode +### setRingerMode setRingerMode\(mode: AudioRingMode, callback: AsyncCallback\): void -Sets the ringer mode. This method uses an asynchronous callback to return the result. - -**System capabilities**: SystemCapability.Multimedia.Audio.Communication - -**Parameters** - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

mode

-

AudioRingMode

-

Yes

-

Ringer mode.

-

callback

-

AsyncCallback<void>

-

Yes

-

Callback used to return the result.

-
+Sets the ringer mode. This API uses an asynchronous callback to return the result. -**Return value** +**System capability:** SystemCapability.Multimedia.Audio.Communication -None +**Parameters:** -**Example** +| Name | Type | Mandatory | Description | +| ---------- | ----------------------------------- | --------- | ----------------------------------- | +| mode | [AudioRingMode](#audioringmode) | Yes | Ringer mode. | +| callback | AsyncCallback | Yes | Callback used to return the result. | + +**Example:** ``` audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL, (err) => { @@ -1629,103 +1068,50 @@ audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL, (err) => { ``` -## audioManager.setRingerMode +### setRingerMode setRingerMode\(mode: AudioRingMode\): Promise -Sets the ringer mode. This method uses a promise to return the result. - -**System capabilities**: SystemCapability.Multimedia.Audio.Communication - -**Parameters** - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

mode

-

AudioRingMode

-

Yes

-

Ringer mode.

-
+Sets the ringer mode. This API uses a promise to return the result. -**Return value** - - - - - - - - - - -

Type

-

Description

-

Promise<void>

-

Promise used to return the result.

-
+**System capability:** SystemCapability.Multimedia.Audio.Communication + +**Parameters:** -**Example** +| Name | Type | Mandatory | Description | +| ---------- | ----------------------------------- | --------- | ----------------------------------- | +| mode | [AudioRingMode](#audioringmode) | Yes | Ringer mode. | + +**Return value:** + +| Type | Description | +| ------------------- | ----------------------------------- | +| Promise | Promise used to return the result. | + +**Example:** ``` -audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() => +audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() => { console.log('Promise returned to indicate a successful setting of the ringer mode.'); -) +}); ``` -## audioManager.getRingerMode +### getRingerMode getRingerMode\(callback: AsyncCallback\): void -Obtains the ringer mode. This method uses an asynchronous callback to return the query result. - -**System capabilities**: SystemCapability.Multimedia.Audio.Communication - -**Parameters** - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

callback

-

AsyncCallback<AudioRingMode>

-

Yes

-

Callback used to return the ringer mode.

-
+Obtains the ringer mode. This API uses an asynchronous callback to return the query result. + +**System capability:** SystemCapability.Multimedia.Audio.Communication -**Return value** +**Parameters:** -None +| Name | Type | Mandatory | Description | +| ---------- | ----------------------------------------------- | --------- | ---------------------------------------- | +| callback | AsyncCallback<[AudioRingMode](#audioringmode)> | Yes | Callback used to return the ringer mode. | -**Example** +**Example:** ``` audioManager.getRingerMode((err, value) => { @@ -1738,290 +1124,137 @@ audioManager.getRingerMode((err, value) => { ``` -## audioManager.getRingerMode +### getRingerMode getRingerMode\(\): Promise -Obtains the ringer mode. This method uses a promise to return the query result. - -**System capabilities**: SystemCapability.Multimedia.Audio.Communication - -**Parameters** +Obtains the ringer mode. This API uses a promise to return the query result. -None +**System capability:** SystemCapability.Multimedia.Audio.Communication -**Return value** +**Return value:** - - - - - - - - - -

Type

-

Description

-

Promise<AudioRingMode>

-

Promise used to return the ringer mode.

-
+| Type | Description | +| ---------------------------------------------- | --------------------------------------- | +| Promise<[AudioRingMode](#audioringmode)> | Promise used to return the ringer mode. | -**Example** +**Example:** ``` -audioManager.getRingerMode().then((value) => +audioManager.getRingerMode().then((value) => { console.log('Promise returned to indicate that the ringer mode is obtained.' + value); -) +}); ``` -## audioManager.setAudioParameter +### setAudioParameter setAudioParameter\(key: string, value: string, callback: AsyncCallback\): void -Sets an audio parameter. This method uses an asynchronous callback to return the result. - -**System capabilities**: SystemCapability.Multimedia.Audio.Core - -**Parameters** - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

key

-

string

-

Yes

-

Key of the audio parameter to set.

-

value

-

string

-

Yes

-

Value of the audio parameter to set.

-

callback

-

AsyncCallback<void>

-

Yes

-

Callback used to return the result.

-
+Sets an audio parameter. This API uses an asynchronous callback to return the result. + +**System capability:** SystemCapability.Multimedia.Audio.Core -**Return value** +**Parameters:** -None +| Name | Type | Mandatory | Description | +| --------- | ----------------------| --------- | ------------------------------------- | +| key | string | Yes | Key of the audio parameter to set. | +| value | string | Yes | Value of the audio parameter to set. | +| callback | AsyncCallback | Yes | Callback used to return the result. | -**Example** +**Example:** ``` audioManager.setAudioParameter('PBits per sample', '8 bit', (err) => { if (err) { console.error('Failed to set the audio parameter. ${err.message}'); - return; + return; } console.log('Callback invoked to indicate a successful setting of the audio parameter.'); }); ``` -## audioManager.setAudioParameter +### setAudioParameter setAudioParameter\(key: string, value: string\): Promise -Sets an audio parameter. This method uses a promise to return the result. - -**System capabilities**: SystemCapability.Multimedia.Audio.Core - -**Parameters** - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

key

-

string

-

Yes

-

Key of the audio parameter to set.

-

value

-

string

-

Yes

-

Value of the audio parameter to set.

-
+Sets an audio parameter. This API uses a promise to return the result. -**Return value** - - - - - - - - - - -

Type

-

Description

-

Promise<void>

-

Promise used to return the result.

-
+**System capability:** SystemCapability.Multimedia.Audio.Core + +**Parameters:** -**Example** +| Name | Type | Mandatory | Description | +| --------- | ----------------------| --------- | ------------------------------------- | +| key | string | Yes | Key of the audio parameter to set. | +| value | string | Yes | Value of the audio parameter to set. | + +**Return value:** + +| Type | Description | +| ------------------- | ----------------------------------- | +| Promise | Promise used to return the result. | + +**Example:** ``` -audioManager.setAudioParameter('PBits per sample', '8 bit').then(() => +audioManager.setAudioParameter('PBits per sample', '8 bit').then(() => { console.log('Promise returned to indicate a successful setting of the audio parameter.'); -) +}); ``` -## audioManager.getAudioParameter +### getAudioParameter getAudioParameter\(key: string, callback: AsyncCallback\) -Obtains the value of an audio parameter. This method uses an asynchronous callback to return the query result. - -**System capabilities**: SystemCapability.Multimedia.Audio.Core - -**Parameters** - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

key

-

string

-

Yes

-

Key of the audio parameter whose value is to be obtained.

-

callback

-

AsyncCallback<string>

-

Yes

-

Callback used to return the value of the audio parameter.

-
+Obtains the value of an audio parameter. This API uses an asynchronous callback to return the query result. + +**System capability:** SystemCapability.Multimedia.Audio.Core -**Return value** +**Parameters:** -None +| Name | Type | Mandatory | Description | +| --------- | ----------------------| --------- | ---------------------------------------------------------- | +| key | string | Yes | Key of the audio parameter whose value is to be obtained. | +| callback | AsyncCallback | Yes | Callback used to return the value of the audio parameter. | -**Example** +**Example:** ``` audioManager.getAudioParameter('PBits per sample', (err, value) => { if (err) { console.error('Failed to obtain the value of the audio parameter. ${err.message}'); - return; + return; } console.log('Callback invoked to indicate that the value of the audio parameter is obtained.' + value); }); ``` -## audioManager.getAudioParameter +### getAudioParameter getAudioParameter\(key: string\): Promise -Obtains the value of an audio parameter. This method uses a promise to return the query result. - -**System capabilities**: SystemCapability.Multimedia.Audio.Core - -**Parameters** - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

key

-

string

-

Yes

-

Key of the audio parameter whose value is to be obtained.

-
+Obtains the value of an audio parameter. This API uses a promise to return the query result. -**Return value** - - - - - - - - - - -

Type

-

Description

-

Promise<string>

-

Promise used to return the value of the audio parameter.

-
+**System capability:** SystemCapability.Multimedia.Audio.Core + +**Parameters:** + +| Name | Type | Mandatory | Description | +| --------- | ----------------------| --------- | ----------------------------------------------------------- | +| key | string | Yes | Key of the audio parameter whose value is to be obtained. | + +**Return value:** -**Example** +| Type | Description | +| ------------------- | ----------------------------------- | +| Promise | Promise used to return the value of the audio parameter. | + +**Example:** ``` audioManager.getAudioParameter('PBits per sample').then((value) => { @@ -2030,56 +1263,25 @@ audioManager.getAudioParameter('PBits per sample').then((value) => { ``` -## audioManager.getDevices - -getDevices\(deviceFlag: DeviceFlag, callback: AsyncCallback\): void - -Obtains the audio devices with a specific flag. This method uses an asynchronous callback to return the query result. - -**System capabilities**: SystemCapability.Multimedia.Audio.Device - -**Parameters** - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

deviceFlag

-

DeviceFlag

-

Yes

-

Audio device flag.

-

callback

-

AsyncCallback<AudioDeviceDescriptors>

-

Yes

-

Callback used to return the device list.

-
+### getDevices + +getDevices\(deviceFlag: DeviceFlag, callback: AsyncCallback\): void + +Obtains the audio devices with a specific flag. This API uses an asynchronous callback to return the query result. -**Return value** +**System capability:** SystemCapability.Multimedia.Audio.Device -None +**Parameters:** -**Example** +| Name | Type | Mandatory | Description | +| --------- | ---------------------------------------------------------------- | --------- | ----------------------------------------- | +| deviceFlag | [DeviceFlag](#deviceflag) | Yes | Audio device flag. | +| callback | AsyncCallback<[AudioDeviceDescriptors](#audiodevicedescriptors)> | Yes | Callback used to return the device list. | + +**Example:** ``` -audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err, value)=>{ +audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err, value) => { if (err) { console.error('Failed to obtain the device list. ${err.message}'); return; @@ -2090,127 +1292,57 @@ audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err, value)=>{ -## audioManager.getDevices +### getDevices -getDevices\(deviceFlag: DeviceFlag\): Promise +getDevices\(deviceFlag: DeviceFlag\): Promise -Obtains the audio devices with a specific flag. This method uses a promise to return the query result. +Obtains the audio devices with a specific flag. This API uses a promise to return the query result. -**System capabilities**: SystemCapability.Multimedia.Audio.Device +**System capability:** SystemCapability.Multimedia.Audio.Device -**Parameters** +**Parameters:** - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

deviceFlag

-

DeviceFlag

-

Yes

-

Audio device flag.

-
+| Name | Type | Mandatory | Description | +| --------- | --------------------------- | --------- | ------------------- | +| deviceFlag | [DeviceFlag](#deviceflag) | Yes | Audio device flag. | -**Return value** - - - - - - - - - - -

Type

-

Description

-

Promise<AudioDeviceDescriptors>

-

Promise used to return the device list.

-
+**Return value:** + +| Type | Description | +| ----------------------------------------------------------- | ---------------------------------------- | +| Promise<[AudioDeviceDescriptors](#audiodevicedescriptors)> | 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) => { console.log('Promise returned to indicate that the device list is obtained.'); }); ``` - -## audioManager.setDeviceActive +### setDeviceActive setDeviceActive\(deviceType: DeviceType, active: boolean, callback: AsyncCallback\): void -Sets a device to the active state. This method uses an asynchronous callback to return the result. - -**System capabilities**: SystemCapability.Multimedia.Audio.Device - -**Parameters** - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

deviceType

-

DeviceType

-

Yes

-

Audio device type.

-

active

-

boolean

-

Yes

-

Active status to set. The value true means to set the device to the active status, and false means the opposite.

-

callback

-

AsyncCallback<void>

-

Yes

-

Callback used to return the result.

-
+Sets a device to the active state. This API uses an asynchronous callback to return the result. -**Return value** +**System capability:** SystemCapability.Multimedia.Audio.Device -None +**Parameters:** -**Example** +| Name | Type | Mandatory | Description | +| --------- | ---------------------------------------| --------- | ---------------------------------------------------------------------------------------------------------------- | +| deviceType | [ActiveDeviceType](#activedevicetype) | Yes | Audio device type. | +| active | boolean | Yes | Active status to set. The value true means to set the device to the active status, and false means the opposite. | +| callback | AsyncCallback | Yes | Callback used to return the result. | + +**Example:** ``` -audioManager.setDeviceActive(audio.DeviceType.SPEAKER, true, (err)=> { +audioManager.setDeviceActive(audio.DeviceType.SPEAKER, true, (err) => { if (err) { console.error('Failed to set the active status of the device. ${err.message}'); - return; + return; } console.log('Callback invoked to indicate that the device is set to the active status.'); }); @@ -2218,184 +1350,86 @@ audioManager.setDeviceActive(audio.DeviceType.SPEAKER, true, (err)=> { -## audioManager.setDeviceActive +### setDeviceActive setDeviceActive\(deviceType: DeviceType, active: boolean\): Promise -Sets a device to the active state. This method uses a promise to return the result. - -**System capabilities**: SystemCapability.Multimedia.Audio.Device - -**Parameters** - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

deviceType

-

DeviceType

-

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.

-
+Sets a device to the active state. This API uses a promise to return the result. -**Return value** - - - - - - - - - - -

Type

-

Description

-

Promise<void>

-

Promise used to return the result.

-
+**System capability:** SystemCapability.Multimedia.Audio.Device + +**Parameters:** + +| Name | Type | Mandatory | Description | +| --------- | ---------------------------------------| --------- | ---------------------------------------------------------------------------------------------------------------- | +| deviceType | [ActiveDeviceType](#activedevicetype) | Yes | Audio device type. | +| active | boolean | Yes | Active status to set. The value true means to set the device to the active status, and false means the opposite. | -**Example** +**Return value:** + +| Type | Description | +| ------------------- | ----------------------------------- | +| Promise | Promise used to return the result. | + + +**Example:** ``` -audioManager.setDeviceActive(audio.DeviceType.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.'); }); ``` -## audioManager.isDeviceActive +### isDeviceActive isDeviceActive\(deviceType: DeviceType, callback: AsyncCallback\): void -Checks whether a device is active. This method uses an asynchronous callback to return the query result. - -**System capabilities**: SystemCapability.Multimedia.Audio.Device - -**Parameters** - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

deviceType

-

DeviceType

-

Yes

-

Audio device type.

-

callback

-

AsyncCallback<boolean>

-

Yes

-

Callback used to return the active status of the device.

-
+Checks whether a device is active. This API uses an asynchronous callback to return the query result. -**Return value** +**System capability:** SystemCapability.Multimedia.Audio.Device -None +**Parameters:** -**Example** +| Name | Type | Mandatory | Description | +| --------- | ---------------------------------------| --------- | -------------------------------------------------------- | +| deviceType | [ActiveDeviceType](#activedevicetype) | Yes | Audio device type. | +| callback | AsyncCallback | Yes | Callback used to return the active status of the device. | + +**Example:** ``` audioManager.isDeviceActive(audio.DeviceType.SPEAKER, (err, value) => { if (err) { console.error('Failed to obtain the active status of the device. ${err.message}'); - return; + return; } console.log('Callback invoked to indicate that the active status of the device is obtained.'); }); ``` -## audioManager.isDeviceActive +### isDeviceActive isDeviceActive\(deviceType: DeviceType\): Promise -Checks whether a device is active. This method uses a promise to return the query result. - -**System capabilities**: SystemCapability.Multimedia.Audio.Device - -**Parameters** - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

deviceType

-

DeviceType

-

Yes

-

Audio device type.

-
+Checks whether a device is active. This API uses a promise to return the query result. -**Return value** - - - - - - - - - - -

Type

-

Description

-

Promise<boolean>

-

Promise used to return the active status of the device.

-
+**System capability:** SystemCapability.Multimedia.Audio.Device -**Example** +**Parameters:** + +| Name | Type | Mandatory | Description | +| --------- | ---------------------------------------| --------- | ----------------------------------------- | +| deviceType | [ActiveDeviceType](#activedevicetype) | Yes | Audio device type. | + +**Return value:** + +| Type | Description | +| ------------------- | ----------------------------------- | +| Promise | Promise used to return the active status of the device. | + +**Example:** ``` audioManager.isDeviceActive(audio.DeviceType.SPEAKER).then((value) => { @@ -2404,53 +1438,22 @@ audioManager.isDeviceActive(audio.DeviceType.SPEAKER).then((value) => { ``` -## audioManager.setMicrophoneMute +### setMicrophoneMute setMicrophoneMute\(mute: boolean, callback: AsyncCallback\): void -Mutes or unmutes the microphone. This method uses an asynchronous callback to return the result. - -**System capabilities**: SystemCapability.Multimedia.Audio.Device - -**Parameters** - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

mute

-

boolean

-

Yes

-

Mute status to set. The value true means to mute the microphone, and false means the opposite.

-

callback

-

AsyncCallback<void>

-

Yes

-

Callback used 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 -**Return value** +**Parameters:** -None +| Name | Type | Mandatory | Description | +| --------- | -------------------- | --------- | ---------------------------------------------------------------------------------------------- | +| mute | boolean | Yes | Mute status to set. The value true means to mute the microphone, and false means the opposite. | +| callback | AsyncCallback | Yes | Callback used to return the result. | -**Example** +**Example:** ``` audioManager.setMicrophoneMute(true, (err) => { @@ -2463,57 +1466,29 @@ audioManager.setMicrophoneMute(true, (err) => { ``` -## audioManager.setMicrophoneMute +### setMicrophoneMute setMicrophoneMute\(mute: boolean\): Promise -Mutes or unmutes the microphone. This method uses a promise to return the result. - -**System capabilities**: SystemCapability.Multimedia.Audio.Device - -**Parameters** - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

mute

-

boolean

-

Yes

-

Mute status to set. The value true means to mute the microphone, and false means the opposite.

-
+Mutes or unmutes the microphone. This API uses a promise to return the result. + +**System capability:** SystemCapability.Multimedia.Audio.Device + +**Parameters:** + +| Name | Type | Mandatory | Description | +| --------- | -------------------- | --------- | ---------------------------------------------------------------------------------------------- | +| mute | boolean | Yes | Mute status to set. The value true means to mute the microphone, and false means the opposite. | + +**Return value:** + +| Type | Description | +| ------------------- | ----------------------------------- | +| Promise | Promise used to return the result. | -**Return value** - - - - - - - - - -

Type

-

Description

-

Promise<void>

-

Promise used to return the result.

-
-**Example** +**Example:** ``` audioManager.setMicrophoneMute(true).then(() => { @@ -2522,46 +1497,24 @@ audioManager.setMicrophoneMute(true).then(() => { ``` -## audioManager.isMicrophoneMute +### isMicrophoneMute isMicrophoneMute\(callback: AsyncCallback\): void -Checks whether the microphone is muted. This method uses an asynchronous callback to return the query result. - -**System capabilities**: SystemCapability.Multimedia.Audio.Device - -**Parameters** - - - - - - - - - - - - - - -

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.

-
+Checks whether the microphone is muted. This API uses an asynchronous callback to return the query result. + +**System capability:** SystemCapability.Multimedia.Audio.Device -**Return value** +**Parameters:** -None +| Name | Type | Mandatory | Description | +| --------- | -------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------- | +| callback | AsyncCallback | Yes | Callback used to return the mute status of the microphone. The value true means that the microphone is muted, and false means the opposite. | -**Example** +**Example:** ``` +var audioManager = audio.getAudioManager(); audioManager.isMicrophoneMute((err, value) => { if (err) { console.error('Failed to obtain the mute status of the microphone. ${err.message}'); @@ -2572,64 +1525,47 @@ audioManager.isMicrophoneMute((err, value) => { ``` -## audioManager.isMicrophoneMute +### isMicrophoneMute isMicrophoneMute\(\): Promise -Checks whether the microphone is muted. This method uses a promise to return the query result. +Checks whether the microphone is muted. This API uses a promise to return the query result. -**System capabilities**: SystemCapability.Multimedia.Audio.Device +**System capability:** SystemCapability.Multimedia.Audio.Device -**Parameters** +**Return value:** -None +| Type | Description | +| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | +| Promise | Promise used to return the mute status of the microphone. The value true means that the microphone is muted, and false means the opposite. | -**Return value** - - - - - - - - - - -

Type

-

Description

-

Promise<boolean>

-

Promise used to return the mute status of the microphone. The value true means that the microphone is muted, and false means the opposite.

-
- -**Example** +**Example:** ``` +var audioManager = audio.getAudioManager(); audioManager.isMicrophoneMute().then((value) => { console.log('Promise returned to indicate that the mute status of the microphone is obtained.', + value); }); ``` +### on('volumeChange')8+ -## audioManager.on - -on(type: 'volumeChange', callback: Callback): void8+ +on(type: 'volumeChange', callback: Callback\): void -Listens for system volume change events. This method uses a callback to get volume change events. +Subscribes to system volume change events. This API uses a callback to get volume change events. -**System capabilities**: SystemCapability.Multimedia.Audio.Volume +This is a system API and cannot be called by third-party applications. -**Parameters** +**System capability:** SystemCapability.Multimedia.Audio.Volume -| Name | Type | Mandatory | Description | -| :------- | :--------------------- | :-------- | :--------------------------------------------------- | -| type | string | Yes | Type of the playback event to listen for. | -| callback | Callback | Yes | Callback used to get the system volume change event. | +**Parameters:** -**Return value** +| Name | Type | Mandatory | Description | +| :------- | :--------------------------------------| :-------------| :------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| type | string | Yes | Type of the event to subscribe to. The value 'volumeChange' means the system volume change event, which is triggered when a system volume change is detected. | +| callback | Callback<[VolumeEvent](#volumeevent8)> | Yes | Callback used to get the system volume change event. | -None - -**Example** +**Example:** ``` audioManager.on('volumeChange', (volumeEvent) => { @@ -2640,26 +1576,24 @@ audioManager.on('volumeChange', (volumeEvent) => { ``` -## audioManager.on - -on(type: 'ringerModeChange', callback: Callback): void8+ +### on('ringerModeChange')8+ -Listens for ringer mode change events. This method uses a callback to get ringer mode changes. +on(type: 'ringerModeChange', callback: Callback\): void -**System capabilities**: SystemCapability.Multimedia.Audio.Communication +Subscribes to ringer mode change events. This API uses a callback to get ringer mode changes. -**Parameters** +This is a system API and cannot be called by third-party applications. -| Name | Type | Mandatory | Description | -| :------- | :----------------------- | :-------- | :-------------------------------------------- | -| type | string | Yes | Type of the playback event to listen for. | -| callback | Callback | Yes | Callback used to get the updated ringer mode. | +**System capability:** SystemCapability.Multimedia.Audio.Communication -**Return value** +**Parameters:** -None +| Name | Type | Mandatory | Description | +| :------- | :----------------------------------------- | :-------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| type | string | Yes | Type of the event to subscribe to. The value 'ringerModeChange' means the ringer mode change event, which is triggered when a ringer mode change is detected. | +| callback | Callback<[AudioRingMode](#audioringmode)> | Yes | Callback used to get the updated ringer mode. | -**Example** +**Example:** ``` audioManager.on('ringerModeChange', (ringerMode) => { @@ -2667,26 +1601,22 @@ audioManager.on('ringerModeChange', (ringerMode) => { }); ``` -## audioManager.on +### on('deviceChange') -on(type: 'deviceChange', callback: Callback): void8+ +on(type: 'deviceChange', callback: Callback): void Subscribes to device change events. When a device is connected/disconnected, registered clients will receive the callback. -**System capabilities**: SystemCapability.Multimedia.Audio.Device - -**Parameters** - -| Name | Type | Mandatory | Description | -| :------- | :---------------------------- | :---------| :------------------------------------------------- | -| type | string | Yes | Type of the event to subscribe to. | -| callback | Callback | Yes | Callback used to obtain the device update details. | +**System capability:** SystemCapability.Multimedia.Audio.Device -**Return value** +**Parameters:** -None +| Name | Type | Mandatory | Description | +| :------- | :-------------------------------------------------- | :---------| :---------------------------------------------------------------------------------------------------------------------------------------------- | +| type | string | Yes | Type of the event to subscribe to. The value 'deviceChange' means the device change event, which is triggered when a device change is detected. | +| callback | Callback<[DeviceChangeAction](#DeviceChangeAction)> | Yes | Callback used to obtain the device update details. | -**Example** +**Example:** ``` audioManager.on('deviceChange', (deviceChanged) => { @@ -2697,27 +1627,123 @@ audioManager.on('deviceChange', (deviceChanged) => { }); ``` -## audioManager.setAudioScene +### off('deviceChange') + +off(type: 'deviceChange', callback?: Callback): void + +Unsubscribes from audio device connection 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 + +**Parameters:** + +| Name | Type | Mandatory | Description | +| :------- | :-------------------------------------------------- | :---------| :-------------------------------------------------- | +| type | string | Yes | Type of the event to unsubscribe from. | +| callback | Callback<[DeviceChangeAction](#DeviceChangeAction)> | Yes | Callback used to obtain the device update details. | + +**Example:** + +``` +audioManager.off('deviceChange', (deviceChanged) => { + console.log("Should be no callback."); +}); +``` + + +### on('interrupt') + +on(type: 'interrupt', interrupt: AudioInterrupt, callback: Callback\): void + +Subscribes to audio interrupt events. When the application's audio is interrupted by another playback event, the application will receive the callback. + +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 + +**Parameters:** + +| Name | Type | Mandatory | Description | +| --------- | --------------------------------------------- | ---- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| type | string | Yes | Type of event to subscribe to. The value 'interrupt' means the audio interrupt event, which is triggered when the audio playback of the current application is interrupted by another application.| +| interrupt | AudioInterrupt | Yes | Audio interrupt event type. | +| callback | Callback<[InterruptAction](#interruptaction)> | Yes | Audio interrupt event callback method. | + +**Example:** + +``` +var interAudioInterrupt = { + streamUsage:2, + contentType:0, + pauseWhenDucked:true +}; +this.audioManager.on('interrupt', interAudioInterrupt, (InterruptAction) => { + if (InterruptAction.actionType === 0) { + console.log("An event to gain the audio focus starts."); + console.log("Focus gain event:" + JSON.stringify(InterruptAction)); + } + if (InterruptAction.actionType === 1) { + console.log("An audio interruption event starts."); + console.log("Audio interruption event:" + JSON.stringify(InterruptAction)); + } +}); +``` + +### off('interrupt') + +off(type: 'interrupt', interrupt: AudioInterrupt, callback?: Callback\): void + +Unsubscribes from audio interrupt 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 + +**Parameters:** + +| Name | Type | Mandatory | Description | +| --------- | --------------------------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| type | string | Yes | Type of event to unsubscribe from. The value 'interrupt' means the audio interrupt event, which is triggered when the audio playback of the current application is interrupted by another application. | +| interrupt | AudioInterrupt | Yes | Audio interrupt event type. | +| callback | Callback<[InterruptAction](#interruptaction)> | No | Audio interrupt event callback method. | + +**Example:** + +``` +var interAudioInterrupt = { + streamUsage:2, + contentType:0, + pauseWhenDucked:true +}; +this.audioManager.off('interrupt', interAudioInterrupt, (InterruptAction) => { + if (InterruptAction.actionType === 0) { + console.log("An event to release the audio focus starts."); + console.log("Focus release event:" + JSON.stringify(InterruptAction)); + } +}); +``` + + +### setAudioScene8+ -setAudioScene\(scene: AudioScene, callback: AsyncCallback\): void8+ +setAudioScene\(scene: AudioScene, callback: AsyncCallback\): void -Sets the audio scene mode to change audio strategies. This method uses an asynchronous callback to return the result. +Sets the audio scene mode to change audio strategies. This API uses an asynchronous callback to return the result. -**System capabilities**: SystemCapability.Multimedia.Audio.Communication +This is a system API and cannot be called by third-party applications. -**Parameters** +**System capability:** SystemCapability.Multimedia.Audio.Communication + +**Parameters:** | Name | Type | Mandatory | Description | | :------- | :------------------------------------ | :-------- | :---------------------------------- | | scene | AudioScene | Yes | Audio scene mode. | | callback | AsyncCallback | Yes | Callback used to return the result. | - -**Return value** - -None - -**Example** +**Example:** ``` audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL, (err) => { @@ -2730,29 +1756,31 @@ audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL, (err) => { ``` -## audioManager.setAudioScene +### setAudioScene8+ -setAudioScene\(scene: AudioScene\): Promise8+ +setAudioScene\(scene: AudioScene\): Promise -Sets the audio scene mode to change audio strategies. This method uses a promise to return the result. +Sets the audio scene mode to change audio strategies. This API uses a promise to return the result. -**System capabilities**: SystemCapability.Multimedia.Audio.Communication +This is a system API and cannot be called by third-party applications. -**Parameters** +**System capability:** SystemCapability.Multimedia.Audio.Communication + +**Parameters:** | Name | Type | Mandatory | Description | | :------- | :-------------------------------------- | :-------- | :---------------- | | scene | AudioScene | Yes | Audio scene mode. | -**Return value** +**Return value:** | Type | Description | | :------------- | :---------------------------------- | | Promise | Promise used to return the result. | -**Example** +**Example:** ``` audioManager.setAudioScene(audio.AudioSceneMode.AUDIO_SCENE_PHONE_CALL).then(() => { @@ -2763,26 +1791,21 @@ audioManager.setAudioScene(audio.AudioSceneMode.AUDIO_SCENE_PHONE_CALL).then(() ``` -## audioManager.getAudioScene +### getAudioScene8+ -getAudioScene\(callback: AsyncCallback\): void8+ +getAudioScene\(callback: AsyncCallback\): void -Obtains the audio scene mode. This method uses an asynchronous callback to return the query result. +Obtains the audio scene mode. This API uses an asynchronous callback to return the query result. -**System capabilities**: SystemCapability.Multimedia.Audio.Communication +**System capability:** SystemCapability.Multimedia.Audio.Communication -**Parameters** +**Parameters:** | Name | Type | Mandatory | Description | | :------- | :-------------------------------------------------- | :-------- | :-------------------------------------------- | | callback | AsyncCallback<AudioScene> | Yes | Callback used to return the audio scene mode. | - -**Return value** - -None - -**Example** +**Example:** ``` audioManager.getAudioScene((err, value) => { @@ -2795,26 +1818,22 @@ audioManager.getAudioScene((err, value) => { ``` -## audioManager.getAudioScene +### getAudioScene8+ -getAudioScene\(\): Promise8+ +getAudioScene\(\): Promise -Obtains the audio scene mode. This method uses a promise to return the query result. +Obtains the audio scene mode. This API uses a promise to return the query result. -**System capabilities**: SystemCapability.Multimedia.Audio.Communication +**System capability:** SystemCapability.Multimedia.Audio.Communication -**Parameters** - -None - -**Return value** +**Return value:** | Type | Description | | :-------------------------------------------- | :------------------------------------------- | | Promise<AudioScene> | Promise used to return the audio scene mode. | -**Example** +**Example:** ``` audioManager.getAudioScene().then((value) => { @@ -2824,109 +1843,90 @@ audioManager.getAudioScene().then((value) => { }); ``` -# AudioDeviceDescriptor -Describes an audio device. - -**System capabilities**: SystemCapability.Multimedia.Audio.Device - -## AudioDeviceDescriptors - -type AudioDeviceDescriptors = Array\> : void\ -
-Array of AudioDeviceDescriptors, which is read-only. +## AudioDeviceDescriptor -**System capabilities**: SystemCapability.Multimedia.Audio.Device +Describes an audio device. -## audioDeviceDescriptor.deviceRole +**System capability:** SystemCapability.Multimedia.Audio.Device -readonly deviceRole: DeviceRole +| Name | Type | Readable | Writable | Description | +| ---------- | ------------------------- | -------- | -------- | ------------------ | +| deviceRole | [DeviceRole](#devicerole) | Yes | No | Audio device role. | +| deviceType | [DeviceType](#devicetype) | Yes | No | Audio device type. | -Defines the role of the device. +## AudioDeviceDescriptors -| Name | Type | Readable | Writable | Description | -| :--------- | :--------- | :------- | :------- | ------------------ | -| deviceRole | DeviceRole | Yes | No | Audio device role. | +Array of [AudioDeviceDescriptor](#audiodevicedescriptor), which is read-only. -## audioDeviceDescriptor.deviceType +**System capability:** SystemCapability.Multimedia.Audio.Device -readonly deviceType: DeviceType +**Example:** -Defines the type of the device. +``` +import audio from '@ohos.multimedia.audio'; -| Name | Type | Readable | Writable | Description | -| :--------- | :--------- | :------- | :------- | ------------------ | -| deviceType | DeviceType | Yes | No | Audio device type. | +function displayDeviceProp(value) { + deviceRoleValue = value.deviceRole; + deviceTypeValue = value.deviceType; -``` -function deviceProp(audioDeviceDescriptor, index, array) { - deviceRoleValue = audioDeviceDescriptor.deviceRole; - deviceTypeValue = audioDeviceDescriptor.deviceType; } -deviceRoleValue = null; -deviceTypeValue = null; -const promise = audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG); -promise.then(async function (audioDeviceDescriptors) { - console.info('getDevices OUTPUT_DEVICES_FLAG'); - audioDeviceDescriptors.forEach(deviceProp); +var deviceRoleValue = null; +var deviceTypeValue = null; +const promise = audio.getAudioManager().getDevices(1); +promise.then(function (value) { + console.info('AudioFrameworkTest: Promise: getDevices OUTPUT_DEVICES_FLAG'); + value.forEach(displayDeviceProp); if (deviceTypeValue != null && deviceRoleValue != null){ - console.info('OUTPUT_DEVICES_FLAG : Pass'); - expect(true).assertTrue(); + console.info('AudioFrameworkTest: Promise: getDevices : OUTPUT_DEVICES_FLAG : PASS'); } else{ - console.error('OUTPUT_DEVICES_FLAG : fail'); - expect(false).assertTrue(); - } - }); - await promise; - done(); + console.info('AudioFrameworkTest: Promise: getDevices : OUTPUT_DEVICES_FLAG : FAIL'); + } }); ``` -# AudioRenderer -Provides audio playback APIs. +## AudioRenderer8+ + +Provides related APIs for audio rendering. Before calling the AudioRenderer API, you need to create an instance through [createAudioRenderer](#audiocreateaudiorenderer8). -**System capabilities**: SystemCapability.Multimedia.Audio.Renderer +**System capability:** SystemCapability.Multimedia.Audio.Renderer -## audioRenderer.state +### state8+ -readonly state: AudioState 8+ +readonly state: AudioState Defines the current render state. -**System capabilities**: SystemCapability.Multimedia.Audio.Renderer +**System capability:** SystemCapability.Multimedia.Audio.Renderer -| Name | Type | Readable | Writable | Description | -| :---- | :--------- | :------- | :------- | :------------------ | -| state | AudioState | Yes | No | Audio render state. | +| Name | Type | Readable | Writable | Description | +| :---- | :-------------------------- | :------- | :------- | :------------------ | +| state | [AudioState](#audiostate8) | Yes | No | Audio render state. | -**Example** +**Example:** ``` var state = audioRenderer.state; ``` -## audioRenderer.getRendererInfo +### getRendererInfo8+ -getRendererInfo(callback: AsyncCallback): void8+ +getRendererInfo(callback: AsyncCallback): void -Obtains the renderer information provided while creating a renderer instance. This method uses an asynchronous callback to return the result. +Obtains the renderer information provided while creating a renderer instance. This API uses an asynchronous callback to return the result. -**System capabilities**: SystemCapability.Multimedia.Audio.Renderer +**System capability:** SystemCapability.Multimedia.Audio.Renderer -**Parameters** +**Parameters:** -| Name | Type | Mandatory | Description | -| :------- | :--------------------------------- | :-------- | :------------------------------------------------ | -| callback | AsyncCallback | Yes | Callback used to return the renderer information. | +| Name | Type | Mandatory | Description | +| :------- | :------------------------------------------------------- | :-------- | :------------------------------------------------ | +| callback | AsyncCallback<[AudioRendererInfo](#audiorendererinfo8)> | Yes | Callback used to return the renderer information. | -**Return value** - -None - -**Example** +**Example:** ``` -audioRenderer.getRendererInfo((err, rendererInfo)=>{ +audioRenderer.getRendererInfo((err, rendererInfo) => { console.log('Renderer GetRendererInfo:'); console.log('Renderer content:' + rendererInfo.content); console.log('Renderer usage:' + rendererInfo.usage); @@ -2935,56 +1935,53 @@ audioRenderer.getRendererInfo((err, rendererInfo)=>{ ``` -## audioRenderer.getRendererInfo - -getRendererInfo(): Promise8+ - -Obtains the renderer information provided while creating a renderer instance. This method uses a promise to return the result. +### getRendererInfo8+ -**System capabilities**: SystemCapability.Multimedia.Audio.Renderer +getRendererInfo(): Promise -**Parameters** +Obtains the renderer information provided while creating a renderer instance. This API uses a promise to return the result. -None +**System capability:** SystemCapability.Multimedia.Audio.Renderer -**Return value** +**Return value:** -| Type | Description | -| :---------------------------- | :----------------------------------------------- | -| Promise | Promise used to return the renderer information. | +| Type | Description | +| :-------------------------------------------------- | :----------------------------------------------- | +| Promise<[AudioRendererInfo](#audiorendererinfo8)> | Promise used to return the renderer information. | -**Example** +**Example:** ``` -let rendererInfo = await audioRenderer.getRendererInfo(); -console.log('Renderer GetRendererInfo:'); -console.log('Renderer content:' + rendererInfo.content); -console.log('Renderer usage:' + rendererInfo.usage); -console.log('Renderer flags:' + rendererInfo.rendererFlags); -``` - -## audioRenderer.getStreamInfo +audioRenderer.getRendererInfo().then((rendererInfo) => { + console.log('Renderer GetRendererInfo:'); + console.log('Renderer content:' + rendererInfo.content); + console.log('Renderer usage:' + rendererInfo.usage); + console.log('Renderer flags:' + rendererInfo.rendererFlags); +}).catch((err) => { + console.log('AudioFrameworkRenderLog: RendererInfo :ERROR: '+err.message); + resultFlag = false; +}); -getStreamInfo(callback: AsyncCallback): void8+ +``` -Obtains the renderer stream information. This method uses an asynchronous callback to return the result. +### getStreamInfo8+ -**System capabilities**: SystemCapability.Multimedia.Audio.Renderer +getStreamInfo(callback: AsyncCallback): void -**Parameters** +Obtains the renderer stream information. This API uses an asynchronous callback to return the result. -| Name | Type | Mandatory | Description | -| :------- | :--------------------------------- | :-------- | :---------------------------------------------- | -| callback | AsyncCallback | Yes | Callback used to return the stream information. | +**System capability:** SystemCapability.Multimedia.Audio.Renderer -**Return value** +**Parameters:** -None +| Name | Type | Mandatory | Description | +| :------- | :------------------------------------------------------ | :-------- | :---------------------------------------------- | +| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | Yes | Callback used to return the stream information. | -**Example** +**Example:** ``` -audioRenderer.getStreamInfo((err, streamInfo)=>{ +audioRenderer.getStreamInfo((err, streamInfo) => { console.log('Renderer GetStreamInfo:'); console.log('Renderer sampling rate:' + streamInfo.samplingRate); console.log('Renderer channel:' + streamInfo.channels); @@ -2993,58 +1990,54 @@ audioRenderer.getStreamInfo((err, streamInfo)=>{ }); ``` -## audioRenderer.getStreamInfo +### getStreamInfo8+ -getStreamInfo(): Promise8+ +getStreamInfo(): Promise -Obtains the renderer stream information. This method uses a promise to return the result. +Obtains the renderer stream information. This API uses a promise to return the result. -**System capabilities**: SystemCapability.Multimedia.Audio.Renderer +**System capability:** SystemCapability.Multimedia.Audio.Renderer -**Parameters** +**Return value:** -None +| Type | Description | +| :------------------------------------------------- | :--------------------------------------------- | +| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information. | -**Return value** - -| Type | Description | -| :---------------------------- | :--------------------------------------------- | -| Promise | Promise used to return the stream information. | - -**Example** +**Example:** ``` -let streamInfo = await audioRenderer.getStreamInfo(); -console.log('Renderer GetStreamInfo:'); -console.log('Renderer sampling rate:' + streamInfo.samplingRate); -console.log('Renderer channel:' + streamInfo.channels); -console.log('Renderer format:' + streamInfo.sampleFormat); -console.log('Renderer encoding type:' + streamInfo.encodingType); +audioRenderer.getStreamInfo().then((streamInfo) => { + console.log('Renderer GetStreamInfo:'); + console.log('Renderer sampling rate:' + streamInfo.samplingRate); + console.log('Renderer channel:' + streamInfo.channels); + console.log('Renderer format:' + streamInfo.sampleFormat); + console.log('Renderer encoding type:' + streamInfo.encodingType); +}).catch((err) => { + console.log('ERROR: '+err.message); +}); + ``` -## audioRenderer.start +### start8+ -start(callback: AsyncCallback): void8+ +start(callback: AsyncCallback): void -Starts the renderer. This method uses an asynchronous callback to return the result. +Starts the renderer. This API uses an asynchronous callback to return the result. -**System capabilities**: SystemCapability.Multimedia.Audio.Renderer +**System capability:** SystemCapability.Multimedia.Audio.Renderer -**Parameters** +**Parameters:** | Name | Type | Mandatory | Description | | :------- | :---------------------- | :-------- | :-------------------------------------- | | callback | AsyncCallback | Yes | Callback used to return the result. | | | | | | -**Return value** - -None - -**Example** +**Example:** ``` -audioRenderer.start((err)=>{ +audioRenderer.start((err) => { if (err) { console.error('Renderer start failed.'); } else { @@ -3053,55 +2046,50 @@ audioRenderer.start((err)=>{ }); ``` +### start8+ -## audioRenderer.start - -start(): Promise8+ +start(): Promise -Starts the renderer. This method uses a promise to return the result. +Starts the renderer. This API uses a promise to return the result. -**System capabilities**: SystemCapability.Multimedia.Audio.Renderer +**System capability:** SystemCapability.Multimedia.Audio.Renderer -**Parameters** - -None - -**Return value** +**Return value:** | Type | Description | | :------------- | :--------------------------------- | | Promise | Promise used to return the result. | -**Example** +**Example:** ``` -await audioRenderer.start(); +audioRenderer.start().then(() => { + console.log('Renderer started'); +}).catch((err) => { + console.log('ERROR: '+err.message); +}); ``` -## audioRenderer.pause +### pause8+ -pause(callback: AsyncCallback): void8+ +pause(callback: AsyncCallback\): void -Pauses rendering. This method uses an asynchronous callback to return the result. +Pauses rendering. This API uses an asynchronous callback to return the result. -**System capabilities**: SystemCapability.Multimedia.Audio.Renderer +**System capability:** SystemCapability.Multimedia.Audio.Renderer -**Parameters** +**Parameters:** | Name | Type | Mandatory | Description | | :------- | :---------------------- | :-------- | :------------------------------------ | | callback | AsyncCallback | Yes | Callback used to return the result. | | | | | | -**Return value** - -None - -**Example** +**Example:** ``` -audioRenderer.pause((err)=>{ +audioRenderer.pause((err) => { if (err) { console.error('Renderer pause failed'); } else { @@ -3110,57 +2098,49 @@ audioRenderer.pause((err)=>{ }); ``` +### pause8+ +pause(): Promise\ -## audioRenderer.pause - -pause(): Promise8+ - -Pauses rendering. This method uses a promise to return the result. - -**System capabilities**: SystemCapability.Multimedia.Audio.Renderer +Pauses rendering. This API uses a promise to return the result. -**Parameters** +**System capability:** SystemCapability.Multimedia.Audio.Renderer -None - -**Return value** +**Return value:** | Type | Description | | :------------- | :--------------------------------- | | Promise | Promise used to return the result. | -**Example** +**Example:** ``` -await audioRenderer.pause(); +audioRenderer.pause().then(() => { + console.log('Renderer paused'); +}).catch((err) => { + console.log('ERROR: '+err.message); +}); ``` +### drain8+ +drain(callback: AsyncCallback\): void -## audioRenderer.drain - -drain(callback: AsyncCallback): void8+ - -Drains the playback buffer. This method uses an asynchronous callback to return the result. +Drains the playback buffer. This API uses an asynchronous callback to return the result. -**System capabilities**: SystemCapability.Multimedia.Audio.Renderer +**System capability:** SystemCapability.Multimedia.Audio.Renderer -**Parameters** +**Parameters:** | Name | Type | Mandatory | Description | | :------- | :---------------------- | :-------- | :---------------------------------------| | callback | AsyncCallback | Yes | Callback used to return the result. | | | | | | -**Return value** - -None - -**Example** +**Example:** ``` -audioRenderer.drain((err)=>{ +audioRenderer.drain((err) => { if (err) { console.error('Renderer drain failed'); } else { @@ -3169,55 +2149,49 @@ audioRenderer.drain((err)=>{ }); ``` +### drain8+ -## audioRenderer.drain - -drain(): Promise8+ - -Drains the playback buffer. This method uses a promise to return the result. +drain(): Promise\ -**System capabilities**: SystemCapability.Multimedia.Audio.Renderer +Drains the playback buffer. This API uses a promise to return the result. -**Parameters** +**System capability:** SystemCapability.Multimedia.Audio.Renderer -None - -**Return value** +**Return value:** | Type | Description | | :------------- | :--------------------------------- | | Promise | Promise used to return the result. | -**Example** +**Example:** ``` -await audioRenderer.drain(); +audioRenderer.drain().then(() => { + console.log('Renderer drained successfully'); +}).catch((err) => { + console.log('ERROR: '+err.message); +}); ``` -## audioRenderer.stop +### stop8+ -stop(callback: AsyncCallback): void8+ +stop(callback: AsyncCallback\): void -Stops rendering. This method uses an asynchronous callback to return the result. +Stops rendering. This API uses an asynchronous callback to return the result. -**System capabilities**: SystemCapability.Multimedia.Audio.Renderer +**System capability:** SystemCapability.Multimedia.Audio.Renderer -**Parameters** +**Parameters:** | Name | Type | Mandatory | Description | | :------- | :---------------------- | :-------- | :------------------------------------- | | callback | AsyncCallback | Yes | Callback used to return the result. | -| | | | | - -**Return value** - -None -**Example** +**Example:** ``` -audioRenderer.stop((err)=>{ +audioRenderer.stop((err) => { if (err) { console.error('Renderer stop failed'); } else { @@ -3226,55 +2200,49 @@ audioRenderer.stop((err)=>{ }); ``` +### stop8+ -## audioRenderer.stop +stop(): Promise\ -stop(): Promise8+ +Stops rendering. This API uses a promise to return the result. -Stops rendering. This method uses a promise to return the result. +**System capability:** SystemCapability.Multimedia.Audio.Renderer -**System capabilities**: SystemCapability.Multimedia.Audio.Renderer - -**Parameters** - -None - -**Return value** +**Return value:** | Type | Description | | :------------- | :--------------------------------- | | Promise | Promise used to return the result. | -**Example** +**Example:** ``` -await audioRenderer.stop(); +audioRenderer.stop().then(() => { + console.log('Renderer stopped successfully'); +}).catch((err) => { + console.log('ERROR: '+err.message); +}); ``` -## audioRenderer.release +### release8+ -release(callback: AsyncCallback): void8+ +release(callback: AsyncCallback\): void -Releases the renderer. This method uses an asynchronous callback to return the result. +Releases the renderer. This API uses an asynchronous callback to return the result. -**System capabilities**: SystemCapability.Multimedia.Audio.Renderer +**System capability:** SystemCapability.Multimedia.Audio.Renderer -**Parameters** +**Parameters:** | Name | Type | Mandatory | Description | | :------- | :---------------------- | :-------- | :------------------------------------- | | callback | AsyncCallback | Yes | Callback used to return the result. | -| | | | | -**Return value** - -None - -**Example** +**Example:** ``` -audioRenderer.release((err)=>{ +audioRenderer.release((err) => { if (err) { console.error('Renderer release failed'); } else { @@ -3283,61 +2251,55 @@ audioRenderer.release((err)=>{ }); ``` +### release8+ +release(): Promise\ -## audioRenderer.release - -release(): Promise8+ - -Releases the renderer. This method uses a promise to return the result. +Releases the renderer. This API uses a promise to return the result. -**System capabilities**: SystemCapability.Multimedia.Audio.Renderer +**System capability:** SystemCapability.Multimedia.Audio.Renderer -**Parameters** - -None - -**Return value** +**Return value:** | Type | Description | | :------------- | :--------------------------------- | | Promise | Promise used to return the result. | -**Example** +**Example:** ``` -await audioRenderer.release(); +audioRenderer.release().then(() => { + console.log('Renderer released successfully'); +}).catch((err) => { + console.log('ERROR: '+err.message); +}); ``` +### write8+ +write(buffer: ArrayBuffer, callback: AsyncCallback\): void -## audioRenderer.write - -write(buffer: ArrayBuffer, callback: AsyncCallback): void8+ +Writes the buffer. This API uses an asynchronous callback to return the result. -Writes the buffer. This method uses an asynchronous callback to return the result. +**System capability:** SystemCapability.Multimedia.Audio.Renderer -**System capabilities**: SystemCapability.Multimedia.Audio.Renderer - -**Parameters** +**Parameters:** | Name | Type | Mandatory | Description | | :------- | :---------------------- | :-------- | :--------------------------------------------------------------------------------------------------- | | buffer | ArrayBuffer | Yes | Buffer to be written. | | callback | AsyncCallback | Yes | Returns the number of bytes written if the operation is successful; returns an error code otherwise. | -| | | | | - -**Return value** -None - -**Example** +**Example:** ``` +import audio from '@ohos.multimedia.audio'; +import fileio from '@ohos.fileio'; + let ss = fileio.createStreamSync(filePath, 'r'); let buf = new ArrayBuffer(bufferSize); ss.readSync(buf); -audioRenderer.write(buf, (err, writtenbytes)=>{ +audioRenderer.write(buf, (err, writtenbytes) => { if (writtenbytes < 0) { console.error('write failed.'); } else { @@ -3347,117 +2309,107 @@ audioRenderer.write(buf, (err, writtenbytes)=>{ ``` -## audioRenderer.write - -write(buffer: ArrayBuffer): Promise8+ +### write8+ -Writes the buffer. This method uses a promise to return the result. +write(buffer: ArrayBuffer): Promise\ -**System capabilities**: SystemCapability.Multimedia.Audio.Renderer +Writes the buffer. This API uses a promise to return the result. -**Parameters** +**System capability:** SystemCapability.Multimedia.Audio.Renderer -None - -**Return value** +**Return value:** | Type | Description | | :--------------- | :--------------------------------------------------------------------------------------------------- | | Promise | Returns the number of bytes written if the operation is successful; returns an error code otherwise. | -**Example** +**Example:** ``` +import audio from '@ohos.multimedia.audio'; +import fileio from '@ohos.fileio'; + +var filePath = 'data/StarWars10s-2C-48000-4SW.wav'; let ss = fileio.createStreamSync(filePath, 'r'); let buf = new ArrayBuffer(bufferSize); ss.readSync(buf); -let writtenbytes = await audioRenderer.write(buf); -if (writtenbytes < 0) { - console.error('write failed.'); -} else { - console.log('Actual written bytes: ' + writtenbytes); -} +audioRenderer.write(buf).then((writtenbytes) => { + if (writtenbytes < 0) { + console.error('write failed.'); + } else { + console.log('Actual written bytes: ' + writtenbytes); + } +}).catch((err) => { + console.log('ERROR: '+err.message); +}); ``` +### getAudioTime8+ +getAudioTime(callback: AsyncCallback\): void -## audioRenderer.getAudioTime - -getAudioTime(callback: AsyncCallback): void8+ +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 timestamp in Unix epoch time (starts from January 1, 1970), in nanoseconds. This method uses an asynchronous callback to return the result. +**System capability:** SystemCapability.Multimedia.Audio.Renderer -**System capabilities**: SystemCapability.Multimedia.Audio.Renderer - -**Parameters** +**Parameters:** | Name | Type | Mandatory | Description | | :------- | :--------------------- | :-------- | :------------------------------------- | | callback | AsyncCallback | Yes | Callback used to return the timestamp. | -| | | | | - -**Return value** - -None -**Example** +**Example:** ``` -audioRenderer.getAudioTime((err, timestamp)=>{ +audioRenderer.getAudioTime((err, timestamp) => { console.log('Current timestamp: ' + timestamp); }); ``` -## audioRenderer.getAudioTime +### getAudioTime8+ -getAudioTime(): Promise8+ +getAudioTime(): Promise\ -Obtains the timestamp in Unix epoch time (starts from January 1, 1970), in nanoseconds. This method uses a promise to return the result. +Obtains the timestamp in Unix epoch time (starts from January 1, 1970), in nanoseconds. This API uses a promise to return the result. -**System capabilities**: SystemCapability.Multimedia.Audio.Renderer +**System capability:** SystemCapability.Multimedia.Audio.Renderer -**Parameters** - -None - -**Return value** +**Return value:** | Type | Description | | :--------------- | :------------------------------------ | | Promise | Promise used to return the timestamp. | -**Example** +**Example:** ``` -let timestamp = await audioRenderer.getAudioTime(); -console.log('Current timestamp: ' + timestamp); +audioRenderer.getAudioTime().then((timestamp) => { + console.log('Current timestamp: ' + timestamp); +}).catch((err) => { + console.log('ERROR: '+err.message); +}); ``` -## audioRenderer.getBufferSize +### getBufferSize8+ -getBufferSize(callback: AsyncCallback): void8+ +getBufferSize(callback: AsyncCallback\): void -Obtains a reasonable minimum buffer size in bytes for rendering. This method 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 capabilities**: SystemCapability.Multimedia.Audio.Renderer +**System capability:** SystemCapability.Multimedia.Audio.Renderer -**Parameters** +**Parameters:** | Name | Type | Mandatory | Description | | :------- | :--------------------- | :-------- | :--------------------------------------- | | callback | AsyncCallback | Yes | Callback used to return the buffer size. | -| | | | | - -**Return value** -None - -**Example** +**Example:** ``` -audioRenderer.getBufferSize((err, bufferSize)=>{ +audioRenderer.getBufferSize((err, bufferSize) => { if (err) { console.error('getBufferSize error'); } @@ -3467,56 +2419,50 @@ ss.readSync(buf); ``` -## audioRenderer.getBufferSize - -getBufferSize(): Promise8+ +### getBufferSize8+ -Obtains a reasonable minimum buffer size in bytes for rendering. This method uses a promise to return the result. +getBufferSize(): Promise\ -**System capabilities**: SystemCapability.Multimedia.Audio.Renderer +Obtains a reasonable minimum buffer size in bytes for rendering. This API uses a promise to return the result. -**Parameters** +**System capability:** SystemCapability.Multimedia.Audio.Renderer -None - -**Return value** +**Return value:** | Type | Description | | :--------------- | :-------------------------------------- | | Promise | Promise used to return the buffer size. | -**Example** +**Example:** ``` -var bufferSize = await audioRenderer.getBufferSize(); -let buf = new ArrayBuffer(bufferSize); -ss.readSync(buf); +audioRenderer.getBufferSize().then((bufferSize) => { + let buf = new ArrayBuffer(bufferSize); + ss.readSync(buf); +}).catch((err) => { + console.log('ERROR: '+err.message); +}); ``` +### setRenderRate8+ -## audioRenderer.setRenderRate +setRenderRate(rate: AudioRendererRate, callback: AsyncCallback\): void -setRenderRate(rate: AudioRendererRate, callback: AsyncCallback): void8+ +Sets the render rate. This API uses an asynchronous callback to return the result. -Sets the render rate. This method uses an asynchronous callback to return the result. +**System capability:** SystemCapability.Multimedia.Audio.Renderer -**System capabilities**: SystemCapability.Multimedia.Audio.Renderer +**Parameters:** -**Parameters** +| Name | Type | Mandatory | Description | +| :------- | :------------------------------------------ | :-------- | :---------------------------------- | +| rate | [AudioRendererRate](#audiorendererrate8) | Yes | Audio render rate. | +| callback | AsyncCallback | Yes | Callback used to return the result. | -| Name | Type | Mandatory | Description | -| :------- | :------------------- | :-------- | :---------------------------------- | -| rate | AudioRendererRate | Yes | Audio render rate. | -| callback | AsyncCallback | Yes | Callback used to return the result. | - -**Return value** - -None - -**Example** +**Example:** ``` -audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL, (err)=> { +audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL, (err) => { if (err) { console.error('Failed to set params'); } else { @@ -3526,104 +2472,100 @@ audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL, (err)=> ``` -## audioRenderer.setRenderRate +### setRenderRate8+ -setRenderRate(rate: AudioRendererRate): Promise8+ +setRenderRate(rate: AudioRendererRate): Promise\ -Sets the render rate. This method uses a promise to return the result. +Sets the render rate. This API uses a promise to return the result. -**System capabilities**: SystemCapability.Multimedia.Audio.Renderer +**System capability:** SystemCapability.Multimedia.Audio.Renderer -**Parameters** +**Parameters:** -| Name | Type | Mandatory | Description | -| :--- | :---------------- | :-------- | :----------------- | -| rate | AudioRendererRate | Yes | Audio render rate. | +| Name | Type | Mandatory | Description | +| :--- | :--------------------------------------- | :-------- | :----------------- | +| rate | [AudioRendererRate](#audiorendererrate8) | Yes | Audio render rate. | -**Return value** +**Return value:** | Type | Description | | :------------- | :--------------------------------- | | Promise | Promise used to return the result. | -**Example** +**Example:** ``` -await audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL); +audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL).then(() => { + console.log('setRenderRate SUCCESS'); +}).catch((err) => { + console.log('ERROR: '+err.message); +}); ``` +### getRenderRate8+ -## audioRenderer.getRenderRate +getRenderRate(callback: AsyncCallback\): void -getRenderRate(callback: AsyncCallback): void8+ +Obtains the current render rate. This API uses an asynchronous callback to return the result. -Obtains the current render rate. This method uses an asynchronous callback to return the result. +**System capability:** SystemCapability.Multimedia.Audio.Renderer -**System capabilities**: SystemCapability.Multimedia.Audio.Renderer +**Parameters:** -**Parameters** -| Name | Type | Mandatory | Description | -| :------- | :-------------------------------- | :-------- | :--------------------------------------------- | -| callback | AsyncCallback | Yes | Callback used to return the audio render rate. | +| Name | Type | Mandatory | Description | +| :------- | :------------------------------------------------------- | :-------- | :--------------------------------------------- | +| callback | AsyncCallback<[AudioRendererRate](#audiorendererrate8)\> | Yes | Callback used to return the audio render rate. | -**Return value** - -None - -**Example** +**Example:** ``` -audioRenderer.getRenderRate((err, renderrate)=>{ +audioRenderer.getRenderRate((err, renderrate) => { console.log('getRenderRate: ' + renderrate); }); ``` -## audioRenderer.getRenderRate - -getRenderRate(): Promise8+ - -Obtains the current render rate. This method uses a promise to return the result. +### getRenderRate8+ -**System capabilities**: SystemCapability.Multimedia.Audio.Renderer +getRenderRate(): Promise\ -**Parameters** +Obtains the current render rate. This API uses a promise to return the result. -None +**System capability:** SystemCapability.Multimedia.Audio.Renderer -**Return value** +**Return value:** -| Type | Description | -| :-------------------------- | :-------------------------------------------- | -| Promise | Promise used to return the audio render rate. | +| Type | Description | +| :-------------------------------------------------- | :-------------------------------------------- | +| Promise<<[AudioRendererRate](#audiorendererrate8)\> | Promise used to return the audio render rate. | -**Example** +**Example:** ``` -let renderRate = await audioRenderer.getRenderRate(); -console.log('getRenderRate: ' + renderrate); +audioRenderer.getRenderRate().then((renderRate) => { + console.log('getRenderRate: ' + renderRate); +}).catch((err) => { + console.log('ERROR: '+err.message); +}); ``` -## audioRenderer.on - -on(type: 'interrupt', callback: Callback): void8+ +### on('interrupt')9+ -Listens for audio interrupt events. This method uses a callback to get interrupt events. The interrupt event is triggered when audio playback is interrupted. +on(type: 'interrupt', callback: Callback\): void -**System capabilities**: SystemCapability.Multimedia.Audio.Renderer +Subscribes to audio interrupt events. This API uses a callback to get interrupt events. The interrupt event is triggered when audio rendering is interrupted. -**Parameters** -| Name | Type | Mandatory | Description | -| :------- | :------------------------ | :-------- | :---------------------------------------------- | -| type | string | Yes | Type of the playback event to listen for. | -| callback | Callback | Yes | Callback used to listen for interrupt callback. | +**System capability:** SystemCapability.Multimedia.Audio.Renderer -**Return value** +**Parameters:** -None +| Name | Type | Mandatory | Description | +| :------- | :-------------------------------------------- | :-------- | :---------------------------------------------- | +| type | string | Yes | Type of the playback event to subscribe to. | +| callback | Callback<[InterruptEvent](#interruptevent9)\> | Yes | Callback used to listen for interrupt callback. | -**Example** +**Example:** ``` audioRenderer.on('interrupt', (interruptEvent) => { @@ -3653,27 +2595,23 @@ audioRenderer.on('interrupt', (interruptEvent) => { }); ``` -## audioRenderer.on +### on('markReach')8+ -on(type: 'markReach', frame: number, callback: (position: number)): void8+ +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. -**System capabilities**: SystemCapability.Multimedia.Audio.Renderer +**System capability:** SystemCapability.Multimedia.Audio.Renderer -**Parameters** +**Parameters:** | Name | Type | Mandatory | Description | | :------- | :------------------------ | :-------- | :----------------------------------------------------------------------- | | type | string | Yes | Type of the renderer event to subscribe to. | | frame | number | Yes | Number of frames to trigger the event. The value must be greater than 0. | -| callback | Callback | Yes | Callback invoked when the event is triggered. | +| callback | (position: number) => {} | Yes | Callback invoked when the event is triggered. | -**Return value** - -None - -**Example** +**Example:** ``` audioRenderer.on('markReach', 1000, (position) => { @@ -3684,51 +2622,43 @@ audioRenderer.on('markReach', 1000, (position) => { ``` -## audioRenderer.off +### off('markReach') 8+ -off(type: 'markReach'): void8+ +off(type: 'markReach'): void Unsubscribes from mark reached events. -**System capabilities**: SystemCapability.Multimedia.Audio.Renderer +**System capability:** SystemCapability.Multimedia.Audio.Renderer -**Parameters** +**Parameters:** | Name | Type | Mandatory | Description | | :------- | :------------------------ | :-------- | :----------------------------------------------- | | type | string | Yes | Type of the renderer event to unsubscribe from. | -**Return value** - -None - -**Example** +**Example:** ``` audioRenderer.off('markReach'); ``` -## audioRenderer.on +### on('periodReach') 8+ -on(type: 'periodReach', frame: number, callback: (position: number)): void8+ +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. -**System capabilities**: SystemCapability.Multimedia.Audio.Renderer +**System capability:** SystemCapability.Multimedia.Audio.Renderer -**Parameters** +**Parameters:** | Name | Type | Mandatory | Description | | :------- | :------------------------ | :-------- | :--------------------------------------------------------------------------------- | | type | string | Yes | Type of the renderer event to subscribe to. | | frame | number | Yes | Period during which frame rendering is listened. The value must be greater than 0. | -| callback | Callback | Yes | Callback invoked when the event is triggered. | +| callback | (position: number) => {} | Yes | Callback invoked when the event is triggered. | -**Return value** - -None - -**Example** +**Example:** ``` audioRenderer.on('periodReach', 1000, (position) => { @@ -3738,91 +2668,95 @@ audioRenderer.on('periodReach', 1000, (position) => { }); ``` -## audioRenderer.off +### off('periodReach') 8+ -off(type: 'periodReach'): void8+ +off(type: 'periodReach'): void Unsubscribes from period reached events. -**System capabilities**: SystemCapability.Multimedia.Audio.Renderer +**System capability:** SystemCapability.Multimedia.Audio.Renderer -**Parameters** +**Parameters:** | Name | Type | Mandatory | Description | | :------- | :------------------------ | :-------- | :----------------------------------------------- | | type | string | Yes | Type of the renderer event to unsubscribe from. | -**Return value** - -None - -**Example** +**Example:** ``` audioRenderer.off('periodReach') ``` -## AudioDeviceDescriptor +### on('stateChange') 8+ -Describes an audio device. +on(type: 'stateChange', callback: Callback): void -| Name | Type | Readable | Writable | Description | -| -------- | -------- | -------- | -------- | -------- | -| deviceRole | [DeviceRole](#devicerole) | Yes | No | Device role.
**System capabilities:** SystemCapability.Multimedia.Audio.Device | -| deviceType | [DeviceType](#devicetype) | Yes | No | Device type.
**System capabilities:** SystemCapability.Multimedia.Audio.Device | +Subscribes to state change events. +**System capability:** SystemCapability.Multimedia.Audio.Renderer -## AudioDeviceDescriptors +**Parameters:** + +| Name | Type | Mandatory | Description | +| :------- | :------------------------- | :-------- | :--------------------------------------------------------------------------------------- | +| type | string | Yes | Type of the event to subscribe to. The value 'stateChange' means the state change event. | +| callback | [AudioState](#AudioState8) | Yes | Callback used to return the state change. | + +**Example:** + +``` +audioRenderer.on('stateChange', (state) => { + if (state == 1) { + console.log("audio renderer state is: STATE_PREPARED"); + } + if (state == 2) { + console.log("audio renderer state is: STATE_RUNNING"); + } +}); +``` -| Name | Description | -| -------- | -------- | -| AudioDeviceDescriptors | Array of **AudioDeviceDescriptor** objects. It is read-only.
**System capabilities:** SystemCapability.Multimedia.Audio.Device | -# AudioCapturer -Provides APIs for audio recording. +## AudioCapturer8+ +Provides related APIs for audio capture. Before calling the API of AudioCapturer, you need to create an instance through [createAudioCapturer](#audiocreateaudiocapturer8). -## audioCapturer.state +### state8+ -readonly state: AudioState 8+ +readonly state: AudioState Defines the current capture state. -**System capabilities**: SystemCapability.Multimedia.Audio.Capturer +**System capability:** SystemCapability.Multimedia.Audio.Capturer -| Name | Type | Readable | Writable | Description | -| :---- | :--------- | :------- | :------- | :------------------- | -| state | AudioState | Yes | No | Audio capture state. | +| Name | Type | Readable | Writable | Description | +| :---- | :------------------------- | :------- | :------- | :------------------- | +| state | [AudioState](#audiostate8) | Yes | No | Audio capture state. | -**Example** +**Example:** ``` var state = audioCapturer.state; ``` -## audioCapturer.getCapturerInfo - -getCapturerInfo(callback: AsyncCallback): void8+ +### getCapturerInfo8+ -Obtains the capturer information provided while creating a capturer instance. This method uses an asynchronous callback to return the result. +getCapturerInfo(callback: AsyncCallback): void -**System capabilities**: SystemCapability.Multimedia.Audio.Capturer +Obtains the capturer information provided while creating a capturer instance. This API uses an asynchronous callback to return the result. -**Parameters** +**System capability:** SystemCapability.Multimedia.Audio.Capturer -| Name | Type | Mandatory | Description | -| :------- | :--------------------------------- | :-------- | :------------------------------------------------ | -| callback | AsyncCallback | Yes | Callback used to return the capturer information. | -| | | | | +**Parameters:** -**Return value** +| Name | Type | Mandatory | Description | +| :------- | :------------------------------------------------------- | :-------- | :------------------------------------------------ | +| callback | AsyncCallback<[AudioCapturerInfo](#audioCapturerInfo)\> | Yes | Callback used to return the capturer information. | -None - -**Example** +**Example:** ``` -audioCapturer.getCapturerInfo((err, capturerInfo)=>{ +audioCapturer.getCapturerInfo((err, capturerInfo) => { if (err) { console.error('Failed to get capture info'); } else { @@ -3834,59 +2768,56 @@ audioCapturer.getCapturerInfo((err, capturerInfo)=>{ ``` -## audioCapturer.getCapturerInfo - -getCapturerInfo(): Promise8+ +### getCapturerInfo8+ -Obtains the capturer information provided while creating a capturer instance. This method uses a promise to return the result. +getCapturerInfo(): Promise -**System capabilities**: SystemCapability.Multimedia.Audio.Capturer +Obtains the capturer information provided while creating a capturer instance. This API uses a promise to return the result. -**Parameters** +**System capability:** SystemCapability.Multimedia.Audio.Capturer -None +**Return value:** -**Return value** +| Type | Description | +| :-------------------------------------------------- | :----------------------------------------------- | +| Promise<[AudioCapturerInfo](#audiocapturerinfo)\> | Promise used to return the capturer information. | -| Type | Description | -| :---------------------------- | :----------------------------------------------- | -| Promise | Promise used to return the capturer information. | - -**Example** +**Example:** ``` -audioCapturer.getCapturerInfo().then((capturerInfo) => { - console.log('Capturer getCapturerInfo:'); - console.log('Capturer source:' + capturerInfo.source); - console.log('Capturer flags:' + capturerInfo.capturerFlags); -}).catch ((err) => { - console.log("Failed to get capturer info"); +audioCapturer.getCapturerInfo().then((audioParamsGet) => { + if (audioParamsGet != undefined) { + console.info('AudioFrameworkRecLog: Capturer CapturerInfo:'); + console.info('AudioFrameworkRecLog: Capturer SourceType:' + audioParamsGet.source); + console.info('AudioFrameworkRecLog: Capturer capturerFlags:' + audioParamsGet.capturerFlags); + }else { + console.info('AudioFrameworkRecLog: audioParamsGet is : '+audioParamsGet); + console.info('AudioFrameworkRecLog: audioParams getCapturerInfo are incorrect: '); + } +}).catch((err) => { + console.log('AudioFrameworkRecLog: CapturerInfo :ERROR: '+err.message); }); -``` -## audioCapturer.getStreamInfo - -getStreamInfo(callback: AsyncCallback): void8+ +``` -Obtains the capturer stream information. This method uses an asynchronous callback to return the result. +### getStreamInfo8+ -**System capabilities**: SystemCapability.Multimedia.Audio.Capturer +getStreamInfo(callback: AsyncCallback): void -**Parameters** +Obtains the capturer stream information. This API uses an asynchronous callback to return the result. -| Name | Type | Mandatory | Description | -| :------- | :--------------------------------- | :-------- | :---------------------------------------------- | -| callback | AsyncCallback | Yes | Callback used to return the stream information. | -| | | | | +**System capability:** SystemCapability.Multimedia.Audio.Capturer -**Return value** +**Parameters:** -None +| Name | Type | Mandatory | Description | +| :------- | :----------------------------------------------------------- | :-------- | :---------------------------------------------- | +| callback | AsyncCallback<[AudioStreamInfo](#AudioRendererOptions8)\> | Yes | Callback used to return the stream information. | -**Example** +**Example:** ``` -audioCapturer.start((err)=>{ +audioCapturer.getStreamInfo((err, streamInfo) => { if (err) { console.error('Failed to get stream info'); } else { @@ -3899,61 +2830,53 @@ audioCapturer.start((err)=>{ }); ``` -## audioCapturer.getStreamInfo +### getStreamInfo8+ -getStreamInfo(): Promise8+ +getStreamInfo(): Promise -Obtains the capturer stream information. This method uses a promise to return the result. +Obtains the capturer stream information. This API uses a promise to return the result. -**System capabilities**: SystemCapability.Multimedia.Audio.Capturer +**System capability:** SystemCapability.Multimedia.Audio.Capturer -**Parameters** +**Return value:** -None +| Type | Description | +| :---------------------------------------------------- | :----------------------------------------------- | +| Promise<[AudioStreamInfo](#AudioRendererOptions8)\> | Promise used to return the stream information. | -**Return value** - -| Type | Description | -| :---------------------------- | :----------------------------------------------- | -| Promise | Promise used to return the stream information. | - -**Example** +**Example:** ``` -audioCapturer.getStreamInfo().then((streamInfo) => { - console.log('Capturer GetStreamInfo:'); - console.log('Capturer sampling rate:' + streamInfo.samplingRate); - console.log('Capturer channel:' + streamInfo.channels); - console.log('Capturer format:' + streamInfo.sampleFormat); - console.log('Capturer encoding type:' + streamInfo.encodingType); -}).catch ((err) => { - console.log("Failed to get stream info"); +audioCapturer.getStreamInfo().then((audioParamsGet) => { + console.info('getStreamInfo:'); + console.info('sampleFormat:' + audioParamsGet.sampleFormat); + console.info('samplingRate:' + audioParamsGet.samplingRate); + console.info('channels:' + audioParamsGet.channels); + console.info('encodingType:' + audioParamsGet.encodingType); +}).catch((err) => { + console.log('getStreamInfo :ERROR: ' + err.message); }); + ``` -## audioCapturer.start +### start8+ -start(callback: AsyncCallback): void8+ +start(callback: AsyncCallback): void -Starts capturing. This method uses an asynchronous callback to return the result. +Starts capturing. This API uses an asynchronous callback to return the result. -**System capabilities**: SystemCapability.Multimedia.Audio.Capturer +**System capability:** SystemCapability.Multimedia.Audio.Capturer -**Parameters** +**Parameters:** | Name | Type | Mandatory | Description | | :------- | :---------------------- | :-------- | :-------------------------------------- | | callback | AsyncCallback | Yes | Callback used to return the result. | -| | | | | - -**Return value** -None - -**Example** +**Example:** ``` -audioCapturer.start((err)=>{ +audioCapturer.start((err) => { if (err) { console.error('Capturer start failed.'); } else { @@ -3963,57 +2886,55 @@ audioCapturer.start((err)=>{ ``` -## audioCapturer.start - -start(): Promise8+ +### start8+ -Starts capturing. This method uses a promise to return the result. +start(): Promise -**System capabilities**: SystemCapability.Multimedia.Audio.Capturer +Starts capturing. This API uses a promise to return the result. -**Parameters** +**System capability:** SystemCapability.Multimedia.Audio.Capturer -None - -**Return value** +**Return value:** | Type | Description | | :------------- | :--------------------------------- | | Promise | Promise used to return the result. | -**Example** +**Example:** ``` audioCapturer.start().then(() => { - console.log("capturer start success"); -}).catch ((err) => { - console.log("Failed to start capturer"); + console.info('AudioFrameworkRecLog: ---------START---------'); + console.info('AudioFrameworkRecLog: Capturer started :SUCCESS '); + console.info('AudioFrameworkRecLog: AudioCapturer : STATE : '+audioCapturer.state); + console.info('AudioFrameworkRecLog: Capturer started :SUCCESS '); + if ((audioCapturer.state == audio.AudioState.STATE_RUNNING)) { + stateFlag = true; + } +}).catch((err) => { + console.info('AudioFrameworkRecLog: Capturer start :ERROR : '+err.message); + stateFlag=false; }); ``` -## audioCapturer.stop +### stop8+ -stop(callback: AsyncCallback): void8+ +stop(callback: AsyncCallback): void -Stops capturing. This method uses an asynchronous callback to return the result. +Stops capturing. This API uses an asynchronous callback to return the result. -**System capabilities**: SystemCapability.Multimedia.Audio.Capturer +**System capability:** SystemCapability.Multimedia.Audio.Capturer -**Parameters** +**Parameters:** | Name | Type | Mandatory | Description | | :------- | :---------------------- | :-------- | :------------------------------------- | | callback | AsyncCallback | Yes | Callback used to return the result. | -| | | | | - -**Return value** -None - -**Example** +**Example:** ``` -audioCapturer.stop((err)=>{ +audioCapturer.stop((err) => { if (err) { console.error('Capturer stop failed'); } else { @@ -4023,58 +2944,55 @@ audioCapturer.stop((err)=>{ ``` -## audioCapturer.stop - -stop(): Promise8+ +### stop8+ -Stops capturing. This method uses a promise to return the result. +stop(): Promise -**System capabilities**: SystemCapability.Multimedia.Audio.Capturer +Stops capturing. This API uses a promise to return the result. -**Parameters** +**System capability:** SystemCapability.Multimedia.Audio.Capturer -None - -**Return value** +**Return value:** | Type | Description | | :------------- | :--------------------------------- | | Promise | Promise used to return the result. | -**Example** +**Example:** ``` audioCapturer.stop().then(() => { - console.log("capturer stop success"); -}).catch ((err) => { - console.log("Failed to stop capturer"); + console.info('AudioFrameworkRecLog: ---------RELEASE RECORD---------'); + console.info('AudioFrameworkRecLog: Capturer stopped : SUCCESS'); + if ((audioCapturer.state == audioCapturer.AudioState.STATE_STOPPED)){ + stateFlag=true; + console.info('AudioFrameworkRecLog: resultFlag : '+stateFlag); + } +}).catch((err) => { + console.info('AudioFrameworkRecLog: Capturer stop:ERROR : '+err.message); + stateFlag=false; }); ``` -## audioCapturer.release +### release8+ -release(callback: AsyncCallback): void8+ +release(callback: AsyncCallback): void -Releases the capturer. This method uses an asynchronous callback to return the result. +Releases the capturer. This API uses an asynchronous callback to return the result. -**System capabilities**: SystemCapability.Multimedia.Audio.Capturer +**System capability:** SystemCapability.Multimedia.Audio.Capturer -**Parameters** +**Parameters:** | Name | Type | Mandatory | Description | | :------- | :---------------------- | :-------- | :------------------------------------- | | callback | AsyncCallback | Yes | Callback used to return the result. | -| | | | | - -**Return value** -None - -**Example** +**Example:** ``` -audioCapturer.release((err)=>{ +audioCapturer.release((err) => { if (err) { console.error('capturer release failed'); } else { @@ -4084,44 +3002,49 @@ audioCapturer.release((err)=>{ ``` -## audioCapturer.release - -release(): Promise8+ +### release8+ -Releases the capturer. This method uses a promise to return the result. +release(): Promise -**System capabilities**: SystemCapability.Multimedia.Audio.Capturer +Releases the capturer. This API uses a promise to return the result. -**Parameters** +**System capability:** SystemCapability.Multimedia.Audio.Capturer -None - -**Return value** +**Return value:** | Type | Description | | :------------- | :--------------------------------- | | Promise | Promise used to return the result. | -**Example** +**Example:** ``` + audioCapturer.release().then(() => { - console.log("capturer release success"); -}).catch ((err) => { - console.log("Failed to release capturer"); + console.info('AudioFrameworkRecLog: ---------RELEASE RECORD---------'); + console.info('AudioFrameworkRecLog: Capturer release : SUCCESS'); + console.info('AudioFrameworkRecLog: AudioCapturer : STATE : '+audioCapturer.state); + stateFlag=true; + console.info('AudioFrameworkRecLog: stateFlag : '+stateFlag); + expect(stateFlag).assertTrue(); + done(); +}).catch((err) => { + console.info('AudioFrameworkRecLog: Capturer stop:ERROR : '+err.message); + stateFlag=false }); + ``` -## audioCapturer.read +### read8+ -read(size: number, isBlockingRead: boolean, callback: AsyncCallback): void8+ +read(size: number, isBlockingRead: boolean, callback: AsyncCallback): void -Reads the buffer from the audio capturer. This method uses an asynchronous callback to return the result. +Reads the buffer from the audio capturer. This API uses an asynchronous callback to return the result. -**System capabilities**: SystemCapability.Multimedia.Audio.Capturer +**System capability:** SystemCapability.Multimedia.Audio.Capturer -**Parameters** +**Parameters:** | Name | Type | Mandatory | Description | | :------------- | :-------------------------- | :-------- | :-------------------------------------------- | @@ -4129,11 +3052,7 @@ Reads the buffer from the audio capturer. This method uses an asynchronous callb | isBlockingRead | boolean | Yes | Whether the read operation should be blocked. | | callback | AsyncCallback | Yes | Callback used to return the buffer. | -**Return value** - -None - -**Example** +**Example:** ``` audioCapturer.read(bufferSize, true, async(err, buffer) => { @@ -4145,178 +3064,164 @@ audioCapturer.read(bufferSize, true, async(err, buffer) => { ``` -## audioCapturer.read +### read8+ -read(size: number, isBlockingRead: boolean): Promise8+ +read(size: number, isBlockingRead: boolean): Promise -Reads the buffer from the audio capturer. This method uses a promise to return the result. +Reads the buffer from the audio capturer. This API uses a promise to return the result. -**System capabilities**: SystemCapability.Multimedia.Audio.Capturer +**System capability:** SystemCapability.Multimedia.Audio.Capturer -**Parameters** +**Parameters:** -| Name | Type | Mandatory | Description | -| :------------- | :-------------------------- | :-------- | :-------------------------------------------- | -| size | number | Yes | Number of bytes to read. | -| isBlockingRead | boolean | Yes | Whether the read operation should be blocked. | +| Name | Type | Mandatory | Description | +| :------------- | :--------- | :-------- | :-------------------------------------------- | +| size | number | Yes | Number of bytes to read. | +| isBlockingRead | boolean | Yes | Whether the read operation should be blocked. | -**Return value** +**Return value:** | Type | Description | | :-------------------- | :----------------------------------------------------------------------------------------------- | | Promise | Returns the buffer data read if the operation is successful; returns an error code otherwise. | -**Example** +**Example:** ``` -audioCapturer.read(size, true).then((buffer) => { - console.log("Success in reading the buffer data"); - var number = fileio.writeSync(fd, buffer); -}).catch ((err) => { - console.log("Failed to read data!"); +audioCapturer.read(bufferSize, true).then((buffer) => { + console.info('buffer read successfully'); +}).catch((err) => { + console.info('ERROR : '+err.message); }); ``` -## audioCapturer.getAudioTime +### getAudioTime8+ -getAudioTime(callback: AsyncCallback): void8+ +getAudioTime(callback: AsyncCallback): void -Obtains the timestamp in Unix epoch time (starts from January 1, 1970), in nanoseconds. This method uses an asynchronous callback to return the result. +Obtains the timestamp in Unix epoch time (starts from January 1, 1970), in nanoseconds. This API uses an asynchronous callback to return the result. -**System capabilities**: SystemCapability.Multimedia.Audio.Capturer +**System capability:** SystemCapability.Multimedia.Audio.Capturer -**Parameters** +**Parameters:** | Name | Type | Mandatory | Description | | :------- | :--------------------- | :-------- | :------------------------------------- | | callback | AsyncCallback | Yes | Callback used to return the timestamp. | | | | | | -**Return value** - -None - -**Example** +**Example:** ``` -audioCapturer.getAudioTime((err, timestamp)=>{ +audioCapturer.getAudioTime((err, timestamp) => { console.log('Current timestamp: ' + timestamp); }); ``` -## audioCapturer.getAudioTime - -getAudioTime(): Promise8+ - -Obtains the timestamp in Unix epoch time (starts from January 1, 1970), in nanoseconds. This method uses a promise to return the result. +### getAudioTime8+ -**System capabilities**: SystemCapability.Multimedia.Audio.Capturer +getAudioTime(): Promise -**Parameters** +Obtains the timestamp in Unix epoch time (starts from January 1, 1970), in nanoseconds. This API uses a promise to return the result. -None +**System capability:** SystemCapability.Multimedia.Audio.Capturer -**Return value** +**Return value:** | Type | Description | | :--------------- | :------------------------------------ | | Promise | Promise used to return the timestamp. | -**Example** +**Example:** ``` audioCapturer.getAudioTime().then((audioTime) => { - console.log("Success in getting the audio time"); -}).catch ((err) => { - console.log("Failed to get the audio time"); + console.info('AudioFrameworkRecLog: AudioCapturer getAudioTime : Success' + audioTime ); +}).catch((err) => { + console.info('AudioFrameworkRecLog: AudioCapturer Created : ERROR : '+err.message); }); + ``` -## audioCapturer.getBufferSize +### getBufferSize8+ -getBufferSize(callback: AsyncCallback): void8+ +getBufferSize(callback: AsyncCallback): void -Obtains a reasonable minimum buffer size in bytes for capturing. This method 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 capabilities**: SystemCapability.Multimedia.Audio.Capturer +**System capability:** SystemCapability.Multimedia.Audio.Capturer -**Parameters** +**Parameters:** | Name | Type | Mandatory | Description | | :------- | :--------------------- | :-------- | :--------------------------------------- | | callback | AsyncCallback | Yes | Callback used to return the buffer size. | | | | | | -**Return value** - -None - -**Example** +**Example:** ``` -audioCapturer.getBufferSize((err, bufferSize)=>{ +audioCapturer.getBufferSize((err, bufferSize) => { if (!err) { console.log('BufferSize : ' + bufferSize); - var buffer = await audioCapturer.read(bufferSize, true); + audioCapturer.read(bufferSize, true).then((buffer) => { + console.info('Buffer read is ' + buffer ); + }).catch((err) => { + console.info('AudioFrameworkRecLog: AudioCapturer Created : ERROR : '+err.message); + }); } }); ``` +### getBufferSize8+ -## audioCapturer.getBufferSize +getBufferSize(): Promise -getBufferSize(): Promise8+ +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 method uses a promise to return the result. +**System capability:** SystemCapability.Multimedia.Audio.Capturer -**System capabilities**: SystemCapability.Multimedia.Audio.Capturer - -**Parameters** - -None - -**Return value** +**Return value:** | Type | Description | | :--------------- | :-------------------------------------- | | Promise | Promise used to return the buffer size. | -**Example** +**Example:** ``` audioCapturer.getBufferSize().then((bufferSize) => { - console.log("Success in getting the buffer size"); - var buffer = await audioCapturer.read(bufferSize, true); -}).catch ((err) => { - console.log("Failed to get the buffer size"); + if (!err) { + console.log('BufferSize : ' + bufferSize); + audioCapturer.read(bufferSize, true).then((buffer) => { + console.info('Buffer read is ' + buffer ); + }).catch((err) => { + console.info('ERROR : '+err.message); + }); + } }); ``` +### on('markReach')8+ -## audioCapturer.on - -on(type: 'markReach', frame: number, callback: (position: number)): void8+ +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. -**System capabilities**: SystemCapability.Multimedia.Audio.Capturer +**System capability:** SystemCapability.Multimedia.Audio.Capturer -**Parameters** +**Parameters:** | Name | Type | Mandatory | Description | | :------- | :------------------------ | :-------- | :----------------------------------------------------------------------- | | type | string | Yes | Type of the capturer event to subscribe to. | | frame | number | Yes | Number of frames to trigger the event. The value must be greater than 0. | -| callback | Callback | Yes | Callback invoked when the event is triggered. | +| callback | position: number) => {} | Yes | Callback invoked when the event is triggered. | -**Return value** - -None - -**Example** +**Example:** ``` audioCapturer.on('markReach', 1000, (position) => { @@ -4327,51 +3232,43 @@ audioCapturer.on('markReach', 1000, (position) => { ``` -## audioCapturer.off +### off('markReach')8+ -off(type: 'markReach'): void8+ +off(type: 'markReach'): void Unsubscribes from the mark reached events. -**System capabilities**: SystemCapability.Multimedia.Audio.Capturer +**System capability:** SystemCapability.Multimedia.Audio.Capturer -**Parameters** +**Parameters:** | Name | Type | Mandatory | Description | | :------- | :------------------------ | :-------- | :---------------------------------------------- | | type | string | Yes | Type of the capturer event to unsubscribe from. | -**Return value** - -None - -**Example** +**Example:** ``` audioCapturer.off('markReach'); ``` -## audioCapturer.on +### on('periodReach')8+ -on(type: 'periodReach', frame: number, callback: (position: number)): void8+ +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. -**System capabilities**: SystemCapability.Multimedia.Audio.Capturer +**System capability:** SystemCapability.Multimedia.Audio.Capturer -**Parameters** +**Parameters:** | Name | Type | Mandatory | Description | | :------- | :------------------------ | :-------- | :--------------------------------------------------------------------------------- | | type | string | Yes | Type of the capturer event to subscribe to. | | frame | number | Yes | Period during which frame capturing is listened. The value must be greater than 0. | -| callback | Callback | Yes | Callback invoked when the event is triggered. | +| callback | (position: number) => {} | Yes | Callback invoked when the event is triggered. | -**Return value** - -None - -**Example** +**Example:** ``` audioCapturer.on('periodReach', 1000, (position) => { @@ -4381,26 +3278,50 @@ audioCapturer.on('periodReach', 1000, (position) => { }); ``` -## audioCapturer.off +### off('periodReach')8+ -off(type: 'periodReach'): void8+ +off(type: 'periodReach'): void Unsubscribes from period reached events. -**System capabilities**: SystemCapability.Multimedia.Audio.Capturer +**System capability:** SystemCapability.Multimedia.Audio.Capturer -**Parameters** +**Parameters:** | Name | Type | Mandatory | Description | | :------- | :------------------------ | :-------- | :---------------------------------------------- | | type | string | Yes | Type of the capturer event to unsubscribe from. | -**Return value** +**Example:** + +``` +audioCapturer.off('periodReach') +``` + +### on('stateChange') 8+ + +on(type: 'stateChange', callback: Callback): void -None +Subscribes to state change events. -**Example** +**System capability:** SystemCapability.Multimedia.Audio.Capturer + +**Parameters:** + +| Name | Type | Mandatory | Description | +| :------- | :------------------------- | :-------- | :--------------------------------------------------------------------------------------- | +| type | string | Yes | Type of the event to subscribe to. The value 'stateChange' means the state change event. | +| callback | [AudioState](#AudioState8) | Yes | Callback used to return the state change. | + +**Example:** ``` -audioCapturer.off('periodReach') +audioCapturer.on('stateChange', (state) => { + if (state == 1) { + console.log("audio capturer state is: STATE_PREPARED"); + } + if (state == 2) { + console.log("audio capturer state is: STATE_RUNNING"); + } +}); ```