diff --git a/en/application-dev/media/audio-management.md b/en/application-dev/media/audio-management.md index 0f4dc93fa334eced5b30cf1d005f5e210223e271..8c5de441e95a11ecc928c1dc0bd94f698b38fc2a 100644 --- a/en/application-dev/media/audio-management.md +++ b/en/application-dev/media/audio-management.md @@ -112,6 +112,31 @@ You use audio management APIs to set and obtain volume, and get information abou

Obtains the device list asynchronously and uses a Promise to return the execution result.

+

setDeviceActive(deviceType: ActiveDeviceType, active: boolean, callback: AsyncCallback): void;

+ +

Activates the device asynchronously and uses a callback to return the execution result.

+ + +

setDeviceActive(deviceType: ActiveDeviceType, active: boolean): Promise;

+ +

Activates the device asynchronously and uses a Promise to return the execution result.

+ + +

isDeviceActive(deviceType: ActiveDeviceType, callback: AsyncCallback): void;

+ +

Checks whether a device is active asynchronously and uses a callback to return the execution result.

+ + +

isDeviceActive(deviceType: ActiveDeviceType): Promise;

+ +

Checks whether a device is active asynchronously and uses a Promise to return the execution result.

+ + +

on(type: 'deviceChange', callback: Callback): void;

+ +

Subscribes to device change events. Registered clients will receieve the callback when a device is connected/disconnected.

+ + diff --git a/en/application-dev/reference/apis/js-apis-audio.md b/en/application-dev/reference/apis/js-apis-audio.md index eb6fbc82775e1631bd852319de66b4318a1c28de..c9ba6efb37fe32ebeb0acc277707e900d8b76d8d 100644 --- a/en/application-dev/reference/apis/js-apis-audio.md +++ b/en/application-dev/reference/apis/js-apis-audio.md @@ -16,7 +16,9 @@ None getAudioManager\(\): AudioManager -Obtains an **AudioManager** instance. +Obtains an **AudioManager** instance. + +**System capabilities**: SystemCapability.Multimedia.Audio.Core **Return value** @@ -44,14 +46,16 @@ var audioManager = audio.getAudioManager(); ## audioRenderer -createAudioRenderer(volumeType: AudioVolumeType): AudioRenderer +createAudioRenderer(options: AudioRendererOptions): AudioRenderer Obtains an **AudioRenderer** instance. +**System capabilities**: SystemCapability.Multimedia.Audio.Renderer + **Parameters** -| Name | Type | Mandatory | Description | -| :--------- | :-------------- | :-------- | :----------------- | -| volumeType | AudioVolumeType | Yes | Audio stream type. | +| Name | Type | Mandatory | Description | +| :--------- | :------------------- | :-------- | :---------------------- | +| options | AudioRendererOptions | Yes | Renderer configurations | **Return value** @@ -125,28 +129,28 @@ Enumerates audio stream types.

0

-

Audio stream for voice calls.

+

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

RINGTONE

2

-

Audio stream for ringtones.

+

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

MEDIA

3

-

Audio stream for media purpose.

+

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

VOICE_ASSISTANT

9

-

Audio stream for voice assistant.

+

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

@@ -170,21 +174,21 @@ Enumerates audio device flags.

1

-

Output device.

+

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

INPUT_DEVICES_FLAG

2

-

Input device.

+

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

ALL_DEVICES_FLAG

3

-

All devices.

+

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

@@ -208,14 +212,14 @@ Enumerates audio device roles.

1

-

Input role.

+

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

OUTPUT_DEVICE

2

-

Output role.

+

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

@@ -239,42 +243,42 @@ Enumerates audio device types.

0

-

Invalid device.

+

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

SPEAKER

2

-

Speaker.

+

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

WIRED_HEADSET

3

-

Wired headset.

+

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

BLUETOOTH_SCO

7

-

Bluetooth device using the synchronous connection oriented (SCO) link.

+

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).

+

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

MIC

15

-

Microphone.

+

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

@@ -298,21 +302,21 @@ Enumerates ringer modes.

0

-

Silence mode.

+

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

RINGER_MODE_VIBRATE

1

-

Vibration mode.

+

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

RINGER_MODE_NORMAL

2

-

Normal mode.

+

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

@@ -322,71 +326,71 @@ Enumerates ringer modes. ## AudioSampleFormat8+ Enumerates the audio sample formats. -| Name | Default Value | Description | -| :------------ | :------------ | :------------------------------------ | -| INVALID_WIDTH | -1 | Invalid format. | -| SAMPLE_U8 | 0 | Unsigned 8 bit integer. | -| SAMPLE_S16LE | 1 | Signed 16 bit integer, little endian. | -| SAMPLE_S24LE | 2 | Signed 24 bit integer, little endian. | -| SAMPLE_S32LE | 3 | Signed 32 bit integer, little endian. | +| 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 | ## AudioChannel8+ Enumerates the audio channels. -| Name | Default Value | Description | -| :----- | :------------ | :--------------- | -| CHANNEL_1 | 0x1 << 0 | Channel count 1. | -| CHANNEL_2 | 0x1 << 1 | Channel count 2. | +| Name | Default Value | Description | +| :----- | :------------ | :-------------------------------------------------------------------------------- | +| CHANNEL_1 | 0x1 << 0 | Channel count 1.
System capabilities: SystemCapability.Multimedia.Audio.Core | +| CHANNEL_2 | 0x1 << 1 | Channel count 2.
System capabilities: SystemCapability.Multimedia.Audio.Core | ## AudioSamplingRate8+ Enumerates the audio sampling rates. -| 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. | +| 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+ Enumerates the audio encoding types. -| Name | Default Value | Description | -| :-------------------- | :------------ | :---------------- | -| ENCODING_TYPE_INVALID | -1 | Invalid. | -| ENCODING_TYPE_RAW | 0 | PCM encoding. | +| 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 | ## ContentType8+ Enumerates the content types. -| Name | Default Value | Description | -| :------------------------ | :------------ | :-------------------- | -| CONTENT_TYPE_UNKNOWN | 0 | Unknown content. | -| CONTENT_TYPE_SPEECH | 1 | Speech content. | -| CONTENT_TYPE_MUSIC | 2 | Music content. | -| CONTENT_TYPE_MOVIE | 3 | Movie content. | -| CONTENT_TYPE_SONIFICATION | 4 | Notification content. | -| CONTENT_TYPE_RINGTONE | 5 | Ringtone content. | +| 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 | ## StreamUsage8+ Enumerates the stream usage. -| Name | Default Value | Description | -| :--------------------------------- | :------------ | :------------------------------ | -| STREAM_USAGE_UNKNOWN | 0 | Unknown usage. | -| STREAM_USAGE_MEDIA | 1 | Media usage. | -| STREAM_USAGE_VOICE_COMMUNICATION | 2 | Voice communication usage. | -| STREAM_USAGE_NOTIFICATION_RINGTONE | 3 | Notification or ringtone 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 | ## AudioState8+ @@ -394,54 +398,54 @@ Enumerates the audio states. | Name | Default Value | Description | | :------------- | :------------ | :------------------------- | -| STATE_INVALID | -1 | Invalid state. | -| STATE_NEW | 0 | Create 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. | +| 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 | ## AudioRendererRate8+ Enumerates the audio renderer rates. -| Name | Default Value | Description | -| :----------------- | :------------ | :----------- | -| RENDER_RATE_NORMAL | 0 | Normal rate. | -| RENDER_RATE_DOUBLE | 1 | Double rate. | -| RENDER_RATE_HALF | 2 | Half rate. | +| Name | Default Value | Description | +| :----------------- | :------------ | :-------------------------------------------------------------------------------- | +| RENDER_RATE_NORMAL | 0 | Normal rate.
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 | ## InterruptType8+ Enumerates the interrupt types. -| Name | Default Value | Description | -| :------------------- | :------------ | :----------------------------------- | -| INTERRUPT_TYPE_BEGIN | 1 | Audio playback interruption started. | -| INTERRUPT_TYPE_END | 2 | Audio playback interruption ended. | +| Name | Default Value | Description | +| :------------------- | :------------ | :-------------------------------------------------------------------------------------------------------- | +| INTERRUPT_TYPE_BEGIN | 1 | Audio playback interruption started.
System capabilities: SystemCapability.Multimedia.Audio.Renderer | +| INTERRUPT_TYPE_END | 2 | Audio playback interruption ended.
System capabilities: SystemCapability.Multimedia.Audio.Renderer | ## InterruptForceType8+ Enumerates the interrupt force types. -| Name | Default Value | Description | -| :-------------- | :------------ | :--------------------------------------- | -| INTERRUPT_FORCE | 0 | Forced action taken by system. | -| INTERRUPT_SHARE | 1 | App can choose to take action or ignore. | +| 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 | ## InterruptHint8+ Enumerates the interrupt hints. -| Name | Default Value | Description | -| :-------------------- | :------------ | :------------------------- | -| INTERRUPT_HINT_NONE | 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_UNDUCK | 5 | Unducked the playback. | +| 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 | ## RingtoneType8+ @@ -455,6 +459,8 @@ Enumerates the ringtone types. ## AudioStreamInfo8+ Describes audio stream information. +**System capabilities**: SystemCapability.Multimedia.Audio.Core + **Parameters** | Name | Type | Mandatory | Description | @@ -467,6 +473,8 @@ Describes audio stream information. ## AudioRendererInfo8+ Describes audio renderer information. +**System capabilities**: SystemCapability.Multimedia.Audio.Core + **Parameters** | Name | Type | Mandatory | Description | @@ -475,10 +483,23 @@ Describes audio renderer information. | usage | StreamUsage | Yes | Stream usage. | | rendererFlags | number | Yes | Audio renderer flags. | +## AudioRendererOptions8+ +Describes audio renderer configuration options. + +**System capabilities**: SystemCapability.Multimedia.Audio.Renderer + +**Parameters** + +| Name | Type | Mandatory | Description | +| :------------ | :---------------- | :-------- | :-------------------- | +| streamInfo | AudioStreamInfo | Yes | Stream information. | +| rendererInfo | AudioRendererInfo | Yes | Renderer information. | ## InterruptEvent8+ Describes the interrupt event received by the app when playback is interrupted. +**System capabilities**: SystemCapability.Multimedia.Audio.Renderer + **Parameters** | Name | Type | Mandatory | Description | @@ -491,6 +512,8 @@ Describes the interrupt event received by the app when playback is interrupted. ## VolumeEvent8+ Describes the volume event received by the app when the volume is changed. +**System capabilities**: SystemCapability.Multimedia.Audio.Volume + **Parameters** | Name | Type | Mandatory | Description | @@ -511,16 +534,64 @@ Describes ringtone options. | loop | boolean | Yes | Loop value. | +## DeviceChangeAction +Describes the device change type and device information. + +**System capabilities**: SystemCapability.Multimedia.Audio.Device + +**Parameters** + +| Name | Type | Mandatory | Description | +| :------------------ | :--------------------- | :-------- | :------------------ | +| type | DeviceChangeType | Yes | Device change type. | +| deviceDescriptors | 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 | + + +## AudioCapturerInfo8+ +Describes audio capturer information. + +**System capabilities**: SystemCapability.Multimedia.Audio.Core + +**Parameters** + +| Name | Type | Mandatory | Description | +| :---------------| :----------------| :-------- | :-------------------- | +| source | 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 | + + # 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** @@ -585,6 +656,8 @@ setVolume\(volumeType: AudioVolumeType, volume: number\): Promise @@ -650,6 +723,8 @@ 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** @@ -707,6 +782,8 @@ getVolume\(volumeType: AudioVolumeType\): Promise @@ -764,6 +841,8 @@ getMinVolume\(volumeType: AudioVolumeType, callback: AsyncCallback\): v 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** @@ -821,6 +900,8 @@ getMinVolume\(volumeType: AudioVolumeType\): Promise @@ -878,6 +959,8 @@ getMaxVolume\(volumeType: AudioVolumeType, callback: AsyncCallback\): v 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** @@ -935,6 +1018,8 @@ getMaxVolume\(volumeType: AudioVolumeType\): Promise @@ -991,6 +1076,8 @@ mute\(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback Mutes a stream. This method uses an asynchronous callback to return the result. +**System capabilities**: SystemCapability.Multimedia.Audio.Volume + **Parameters** @@ -1057,6 +1144,8 @@ mute\(volumeType: AudioVolumeType, mute: boolean\): Promise7+< Mutes a stream. This method uses a promise to return the result. +**System capabilities**: SystemCapability.Multimedia.Audio.Volume + **Parameters** @@ -1123,6 +1212,8 @@ isMute\(volumeType: AudioVolumeType, callback: AsyncCallback\): void @@ -1180,6 +1271,8 @@ isMute\(volumeType: AudioVolumeType\): Promise7+ @@ -1237,6 +1330,8 @@ isActive\(volumeType: AudioVolumeType, callback: AsyncCallback\): void Checks whether a stream is active. This method uses an asynchronous callback to return the query result. +**System capabilities**: SystemCapability.Multimedia.Audio.Volume + **Parameters** @@ -1294,6 +1389,8 @@ isActive\(volumeType: AudioVolumeType\): Promise7+ @@ -1351,6 +1448,8 @@ setRingerMode\(mode: AudioRingMode, callback: AsyncCallback\): void7 Sets the ringer mode. This method uses an asynchronous callback to return the result. +**System capabilities**: SystemCapability.Multimedia.Audio.Communication + **Parameters** @@ -1408,6 +1507,8 @@ setRingerMode\(mode: AudioRingMode\): Promise7+ @@ -1465,6 +1566,8 @@ getRingerMode\(callback: AsyncCallback\): void7+ @@ -1513,6 +1616,8 @@ getRingerMode\(\): Promise7+ @@ -1615,6 +1722,8 @@ setAudioParameter\(key: string, value: string\): Promise7+ @@ -1681,6 +1790,8 @@ getAudioParameter\(key: string, callback: AsyncCallback\): void7+< 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** @@ -1738,6 +1849,8 @@ getAudioParameter\(key: string\): Promise7+ @@ -1795,6 +1908,8 @@ getDevices\(deviceFlag: DeviceFlag, callback: AsyncCallback @@ -1853,6 +1968,8 @@ getDevices\(deviceFlag: DeviceFlag\): Promise @@ -1910,6 +2027,8 @@ setDeviceActive\(deviceType: DeviceType, active: boolean, callback: AsyncCallbac Sets a device to the active state. This method uses an asynchronous callback to return the result. +**System capabilities**: SystemCapability.Multimedia.Audio.Device + **Parameters** @@ -1977,6 +2096,8 @@ setDeviceActive\(deviceType: DeviceType, active: boolean\): Promise7 Sets a device to the active state. This method uses a promise to return the result. +**System capabilities**: SystemCapability.Multimedia.Audio.Device + **Parameters** @@ -2043,6 +2164,8 @@ isDeviceActive\(deviceType: DeviceType, callback: AsyncCallback\): voi Checks whether a device is active. This method uses an asynchronous callback to return the query result. +**System capabilities**: SystemCapability.Multimedia.Audio.Device + **Parameters** @@ -2100,6 +2223,8 @@ isDeviceActive\(deviceType: DeviceType\): Promise7+ @@ -2157,6 +2282,8 @@ setMicrophoneMute\(mute: boolean, callback: AsyncCallback\): void7+< Mutes or unmutes the microphone. This method uses an asynchronous callback to return the result. +**System capabilities**: SystemCapability.Multimedia.Audio.Device + **Parameters** @@ -2214,6 +2341,8 @@ setMicrophoneMute\(mute: boolean\): Promise7+ @@ -2271,6 +2400,8 @@ isMicrophoneMute\(callback: AsyncCallback\): void7+ @@ -2319,6 +2450,8 @@ isMicrophoneMute\(\): Promise7+ + +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. | + +**Return value** + +None + +**Example** + +``` +audioManager.on('deviceChange', (deviceChanged) => { + console.info("device change type : " + deviceChanged.type); + console.info("device descriptor size : " + deviceChanged.deviceDescriptors.length); + console.info("device change descriptor : " + deviceChanged.deviceDescriptors[0].deviceRole); + console.info("device change descriptor : " + deviceChanged.deviceDescriptors[0].deviceType); +}) +``` + # AudioDeviceDescriptor Describes an audio device. +**System capabilities**: SystemCapability.Multimedia.Audio.Device + ## AudioDeviceDescriptors type AudioDeviceDescriptors = Array\> : void\
Array of AudioDeviceDescriptors, which is read-only. +**System capabilities**: SystemCapability.Multimedia.Audio.Device + ## audioDeviceDescriptor.deviceRole readonly deviceRole: DeviceRole @@ -2459,6 +2630,7 @@ promise.then(async function (audioDeviceDescriptors) { # AudioRenderer Provides audio playback APIs. +**System capabilities**: SystemCapability.Multimedia.Audio.Renderer ## audioRenderer.state @@ -2466,6 +2638,8 @@ readonly state: AudioState 8+ Defines the current render state. +**System capabilities**: SystemCapability.Multimedia.Audio.Renderer + | Name | Type | Readable | Writable | Description | | :---- | :--------- | :------- | :------- | :------------------ | | state | AudioState | Yes | No | Audio render state. | @@ -2480,14 +2654,15 @@ Defines the current render state. getRendererInfo(callback: AsyncCallback): void8+ -Gets 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 method uses an asynchronous callback to return the result. + +**System capabilities**: SystemCapability.Multimedia.Audio.Renderer **Parameters** | Name | Type | Mandatory | Description | | :------- | :--------------------------------- | :-------- | :------------------------------------------------ | | callback | AsyncCallback | Yes | Callback used to return the renderer information. | -| | | | | **Return value** @@ -2507,9 +2682,11 @@ audioRenderer.getRendererInfo((err, rendererInfo)=>{ ## audioRenderer.getRendererInfo -getParams(): Promise8+ +getRendererInfo(): Promise8+ -Gets the renderer information provided while creating a renderer instance. This method uses a promise to return the result. +Obtains the renderer information provided while creating a renderer instance. This method uses a promise to return the result. + +**System capabilities**: SystemCapability.Multimedia.Audio.Renderer **Parameters** @@ -2535,14 +2712,15 @@ console.log('Renderer flags:' + rendererInfo.rendererFlags); getStreamInfo(callback: AsyncCallback): void8+ -Gets the renderer stream information. This method uses an asynchronous callback to return the result. +Obtains the renderer stream information. This method uses an asynchronous callback to return the result. + +**System capabilities**: SystemCapability.Multimedia.Audio.Renderer **Parameters** | Name | Type | Mandatory | Description | | :------- | :--------------------------------- | :-------- | :---------------------------------------------- | | callback | AsyncCallback | Yes | Callback used to return the stream information. | -| | | | | **Return value** @@ -2554,9 +2732,9 @@ None audioRenderer.getStreamInfo((err, streamInfo)=>{ console.log('Renderer GetStreamInfo:'); console.log('Renderer sampling rate:' + streamInfo.samplingRate); - console.log('Renderer channel:' + streamInfo.AudioChannel); - console.log('Renderer format:' + streamInfo.AudioSampleFormat); - console.log('Renderer encoding type:' + streamInfo.AudioEncodingType); + console.log('Renderer channel:' + streamInfo.channels); + console.log('Renderer format:' + streamInfo.sampleFormat); + console.log('Renderer encoding type:' + streamInfo.encodingType); }) ``` @@ -2564,7 +2742,9 @@ audioRenderer.getStreamInfo((err, streamInfo)=>{ getStreamInfo(): Promise8+ -Gets the renderer stream information. This method uses a promise to return the result. +Obtains the renderer stream information. This method uses a promise to return the result. + +**System capabilities**: SystemCapability.Multimedia.Audio.Renderer **Parameters** @@ -2582,9 +2762,9 @@ None let streamInfo = await audioRenderer.getStreamInfo(); console.log('Renderer GetStreamInfo:'); console.log('Renderer sampling rate:' + streamInfo.samplingRate); -console.log('Renderer channel:' + streamInfo.AudioChannel); -console.log('Renderer format:' + streamInfo.AudioSampleFormat); -console.log('Renderer encoding type:' + streamInfo.AudioEncodingType); +console.log('Renderer channel:' + streamInfo.channels); +console.log('Renderer format:' + streamInfo.sampleFormat); +console.log('Renderer encoding type:' + streamInfo.encodingType); ``` ## audioRenderer.start @@ -2593,6 +2773,8 @@ start(callback: AsyncCallback): void8+8+ Starts the renderer. This method uses a promise to return the result. +**System capabilities**: SystemCapability.Multimedia.Audio.Renderer + **Parameters** None @@ -2646,6 +2830,8 @@ pause(callback: AsyncCallback): void8+ Pauses rendering. This method uses a promise to return the result. +**System capabilities**: SystemCapability.Multimedia.Audio.Renderer + **Parameters** None @@ -2701,6 +2889,8 @@ drain(callback: AsyncCallback): void8+ Drains the playback buffer. This method uses a promise to return the result. +**System capabilities**: SystemCapability.Multimedia.Audio.Renderer + **Parameters** None @@ -2754,6 +2946,8 @@ stop(callback: AsyncCallback): void8+ Stops rendering. This method uses a promise to return the result. +**System capabilities**: SystemCapability.Multimedia.Audio.Renderer + **Parameters** None @@ -2807,6 +3003,8 @@ release(callback: AsyncCallback): void8+ Releases the renderer. This method uses a promise to return the result. +**System capabilities**: SystemCapability.Multimedia.Audio.Renderer + **Parameters** None @@ -2862,6 +3062,8 @@ write(buffer: ArrayBuffer, callback: AsyncCallback): void8+< Writes the buffer. This method uses an asynchronous callback to return the result. +**System capabilities**: SystemCapability.Multimedia.Audio.Renderer + **Parameters** | Name | Type | Mandatory | Description | @@ -2896,6 +3098,8 @@ write(buffer: ArrayBuffer): Promise8+): void8+ -Obtains the timestamp. 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 method uses an asynchronous callback to return the result. + +**System capabilities**: SystemCapability.Multimedia.Audio.Renderer **Parameters** @@ -2952,7 +3158,9 @@ audioRenderer.getAudioTime((err, timestamp)=>{ getAudioTime(): Promise8+ -Obtains the timestamp. This method uses a promise to return the result. +Obtains the timestamp in Unix epoch time (starts from January 1, 1970), in nanoseconds. This method uses a promise to return the result. + +**System capabilities**: SystemCapability.Multimedia.Audio.Renderer **Parameters** @@ -2976,7 +3184,9 @@ console.log('Current timestamp: ' + timestamp); getBufferSize(callback: AsyncCallback): void8+ -Obtains a reasonable minimum buffer size for rendering. This method uses an asynchronous callback to return the result. +Obtains a reasonable minimum buffer size in bytes for rendering. This method uses an asynchronous callback to return the result. + +**System capabilities**: SystemCapability.Multimedia.Audio.Renderer **Parameters** @@ -3006,7 +3216,9 @@ ss.readSync(buf); getBufferSize(): Promise8+ -Obtains a reasonable minimum buffer size for rendering. This method uses a promise to return the result. +Obtains a reasonable minimum buffer size in bytes for rendering. This method uses a promise to return the result. + +**System capabilities**: SystemCapability.Multimedia.Audio.Renderer **Parameters** @@ -3033,13 +3245,14 @@ setRenderRate(rate: AudioRendererRate, callback: AsyncCallback): void | Yes | Callback used to return the result. | -| | | | | **Return value** @@ -3064,6 +3277,8 @@ setRenderRate(rate: AudioRendererRate): Promise8+): void8+ { ``` +## audioRenderer.on + +on(type: 'markReach', frame: number, callback: (position: number)): void8+ + +Subscribes to mark reached events. When the number of frames rendered reaches the value of the frame parameter, the callback is invoked. The frame value should be greater than zero. + +**System capabilities**: SystemCapability.Multimedia.Audio.Renderer + +**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. | + +**Return value** + +None + +**Example** + +``` +audioRenderer.on('markReach', 1000, (position) => { + if (position == "1000") { + console.log('ON Triggered successfully'); + } +}); +``` + + +## audioRenderer.off + +off(type: 'markReach'): void8+ + +Unsubscribes from mark reached events. + +**System capabilities**: SystemCapability.Multimedia.Audio.Renderer + +**Parameters** + +| Name | Type | Mandatory | Description | +| :------- | :------------------------ | :-------- | :----------------------------------------------- | +| type | string | Yes | Type of the renderer event to unsubscribe from. | + +**Return value** + +None + +**Example** + +``` +audioRenderer.off('markReach'); +``` + +## audioRenderer.on + +on(type: 'periodReach', frame: number, callback: (position: number)): void8+ + +Subscribes to period reached events. When the period of frame rendering reaches the value of frame, the callback is invoked. The frame value should be greater than zero. + +**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. | +| callback | Callback | Yes | Callback invoked when the event is triggered. | + +**Return value** + +None + +**Example** + +``` +audioRenderer.on('periodReach', 1000, (position) => { + if (position == "1000") { + console.log('ON Triggered successfully'); + } +}); +``` + +## audioRenderer.off + +off(type: 'periodReach'): void8+ + +Unsubscribes from period reached events. + +**Parameters** + +| Name | Type | Mandatory | Description | +| :------- | :------------------------ | :-------- | :----------------------------------------------- | +| type | string | Yes | Type of the renderer event to unsubscribe from. | + +**Return value** + +None + +**Example** + +``` +audioRenderer.off('periodReach') +``` ## SystemSoundManager @@ -3975,3 +4299,631 @@ None ``` await ringtonePlayer.release(); ``` + +# AudioCapturer +Provides APIs for audio recording. + + +## audioCapturer.state + +readonly state: AudioState 8+ + +Defines the current capture state. + +**System capabilities**: SystemCapability.Multimedia.Audio.Capturer + +| Name | Type | Readable | Writable | Description | +| :---- | :--------- | :------- | :------- | :------------------- | +| state | AudioState | Yes | No | Audio capture state. | + +**Example** + +``` +var state = audioCapturer.state; +``` + + +## audioCapturer.getCapturerInfo + +getCapturerInfo(callback: AsyncCallback): void8+ + +Obtains the capturer information provided while creating a capturer instance. This method uses an asynchronous callback to return the result. + +**System capabilities**: SystemCapability.Multimedia.Audio.Capturer + +**Parameters** + +| Name | Type | Mandatory | Description | +| :------- | :--------------------------------- | :-------- | :------------------------------------------------ | +| callback | AsyncCallback | Yes | Callback used to return the capturer information. | +| | | | | + +**Return value** + +None + +**Example** + +``` +audioCapturer.getCapturerInfo((err, capturerInfo)=>{ + if (err) { + console.error('Failed to get capture info'); + } else { + console.log('Capturer getCapturerInfo:'); + console.log('Capturer source:' + capturerInfo.source); + console.log('Capturer flags:' + capturerInfo.capturerFlags); + } +}) +``` + + +## audioCapturer.getCapturerInfo + +getCapturerInfo(): Promise8+ + +Obtains the capturer information provided while creating a capturer instance. This method uses a promise to return the result. + +**System capabilities**: SystemCapability.Multimedia.Audio.Capturer + +**Parameters** + +None + +**Return value** + +| Type | Description | +| :---------------------------- | :----------------------------------------------- | +| Promise | Promise used to return the capturer information. | + +**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.getStreamInfo + +getStreamInfo(callback: AsyncCallback): void8+ + +Obtains the capturer stream information. This method uses an asynchronous callback to return the result. + +**System capabilities**: SystemCapability.Multimedia.Audio.Capturer + +**Parameters** + +| Name | Type | Mandatory | Description | +| :------- | :--------------------------------- | :-------- | :---------------------------------------------- | +| callback | AsyncCallback | Yes | Callback used to return the stream information. | +| | | | | + +**Return value** + +None + +**Example** + +``` +audioCapturer.start((err)=>{ + if (err) { + console.error('Failed to get stream info'); + } else { + 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); + } +}) +``` + +## audioCapturer.getStreamInfo + +getStreamInfo(): Promise8+ + +Obtains the capturer stream information. This method uses a promise to return the result. + +**System capabilities**: SystemCapability.Multimedia.Audio.Capturer + +**Parameters** + +None + +**Return value** + +| Type | Description | +| :---------------------------- | :----------------------------------------------- | +| Promise | Promise used to return the stream information. | + +**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.start + +start(callback: AsyncCallback): void8+ + +Starts capturing. This method uses an asynchronous callback to return the result. + +**System capabilities**: SystemCapability.Multimedia.Audio.Capturer + +**Parameters** + +| Name | Type | Mandatory | Description | +| :------- | :---------------------- | :-------- | :-------------------------------------- | +| callback | AsyncCallback | Yes | Callback used to return the result. | +| | | | | + +**Return value** + +None + +**Example** + +``` +audioCapturer.start((err)=>{ + if (err) { + console.error('Capturer start failed.'); + } else { + console.info('Capturer start success.'); + } +}) +``` + + +## audioCapturer.start + +start(): Promise8+ + +Starts capturing. This method uses a promise to return the result. + +**System capabilities**: SystemCapability.Multimedia.Audio.Capturer + +**Parameters** + +None + +**Return value** + +| Type | Description | +| :------------- | :--------------------------------- | +| Promise | Promise used to return the result. | + +**Example** + +``` +audioCapturer.start().then(() => { + console.log("capturer start success"); +}).catch ((err) => { + console.log("Failed to start capturer"); +}); +``` + +## audioCapturer.stop + +stop(callback: AsyncCallback): void8+ + +Stops capturing. This method uses an asynchronous callback to return the result. + +**System capabilities**: SystemCapability.Multimedia.Audio.Capturer + +**Parameters** + +| Name | Type | Mandatory | Description | +| :------- | :---------------------- | :-------- | :------------------------------------- | +| callback | AsyncCallback | Yes | Callback used to return the result. | +| | | | | + +**Return value** + +None + +**Example** + +``` +audioCapturer.stop((err)=>{ + if (err) { + console.error('Capturer stop failed'); + } else { + console.log('Capturer stopped.'); + } +}) +``` + + +## audioCapturer.stop + +stop(): Promise8+ + +Stops capturing. This method uses a promise to return the result. + +**System capabilities**: SystemCapability.Multimedia.Audio.Capturer + +**Parameters** + +None + +**Return value** + +| Type | Description | +| :------------- | :--------------------------------- | +| Promise | Promise used to return the result. | + +**Example** + +``` +audioCapturer.stop().then(() => { + console.log("capturer stop success"); +}).catch ((err) => { + console.log("Failed to stop capturer"); +}); +``` + + +## audioCapturer.release + +release(callback: AsyncCallback): void8+ + +Releases the capturer. This method uses an asynchronous callback to return the result. + +**System capabilities**: SystemCapability.Multimedia.Audio.Capturer + +**Parameters** + +| Name | Type | Mandatory | Description | +| :------- | :---------------------- | :-------- | :------------------------------------- | +| callback | AsyncCallback | Yes | Callback used to return the result. | +| | | | | + +**Return value** + +None + +**Example** + +``` +audioCapturer.release((err)=>{ + if (err) { + console.error('capturer release failed'); + } else { + console.log('capturer released.'); + } +}) +``` + + +## audioCapturer.release + +release(): Promise8+ + +Releases the capturer. This method uses a promise to return the result. + +**System capabilities**: SystemCapability.Multimedia.Audio.Capturer + +**Parameters** + +None + +**Return value** + +| Type | Description | +| :------------- | :--------------------------------- | +| Promise | Promise used to return the result. | + +**Example** + +``` +audioCapturer.release().then(() => { + console.log("capturer release success"); +}).catch ((err) => { + console.log("Failed to release capturer"); +}); +``` + + +## audioCapturer.read + +read(size: number, isBlockingRead: boolean, callback: AsyncCallback): void8+ + +Reads the buffer from the audio capturer. This method uses an asynchronous callback to return the result. + +**System capabilities**: SystemCapability.Multimedia.Audio.Capturer + +**Parameters** + +| Name | Type | Mandatory | Description | +| :------------- | :-------------------------- | :-------- | :-------------------------------------------- | +| size | number | Yes | Number of bytes to read. | | +| isBlockingRead | boolean | Yes | Whether the read operation should be blocked. | +| callback | AsyncCallback | Yes | Callback used to return the buffer. | + +**Return value** + +None + +**Example** + +``` +audioCapturer.read(bufferSize, true, async(err, buffer) => { + if (!err) { + console.log("Success in reading the buffer data"); + var number = fileio.writeSync(fd, buffer); + } +}; +``` + + +## audioCapturer.read + +read(size: number, isBlockingRead: boolean): Promise8+ + +Reads the buffer from the audio capturer. This method uses a promise to return the result. + +**System capabilities**: SystemCapability.Multimedia.Audio.Capturer + +**Parameters** + +| Name | Type | Mandatory | Description | +| :------------- | :-------------------------- | :-------- | :-------------------------------------------- | +| size | number | Yes | Number of bytes to read. | | +| isBlockingRead | boolean | Yes | Whether the read operation should be blocked. | + +**Return value** + +| Type | Description | +| :-------------------- | :----------------------------------------------------------------------------------------------- | +| Promise | Returns the buffer data read if the operation is successful; returns an error code otherwise. | + +**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.getAudioTime + +getAudioTime(callback: AsyncCallback): void8+ + +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 capabilities**: SystemCapability.Multimedia.Audio.Capturer + +**Parameters** + +| Name | Type | Mandatory | Description | +| :------- | :--------------------- | :-------- | :------------------------------------- | +| callback | AsyncCallback | Yes | Callback used to return the timestamp. | +| | | | | + +**Return value** + +None + +**Example** + +``` +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. + +**System capabilities**: SystemCapability.Multimedia.Audio.Capturer + +**Parameters** + +None + +**Return value** + +| Type | Description | +| :--------------- | :------------------------------------ | +| Promise | Promise used to return the timestamp. | + +**Example** + +``` +audioCapturer.getAudioTime().then((audioTime) => { + console.log("Success in getting the audio time"); +}).catch ((err) => { + console.log("Failed to get the audio time"); +}); +``` + + +## audioCapturer.getBufferSize + +getBufferSize(callback: AsyncCallback): void8+ + +Obtains a reasonable minimum buffer size in bytes for capturing. This method uses an asynchronous callback to return the result. + +**System capabilities**: SystemCapability.Multimedia.Audio.Capturer + +**Parameters** + +| Name | Type | Mandatory | Description | +| :------- | :--------------------- | :-------- | :--------------------------------------- | +| callback | AsyncCallback | Yes | Callback used to return the buffer size. | +| | | | | + +**Return value** + +None + +**Example** + +``` +audioCapturer.getBufferSize((err, bufferSize)=>{ + if (!err) { + console.log('BufferSize : ' + bufferSize); + var buffer = await audioCapturer.read(bufferSize, true); + } +}); +``` + + +## audioCapturer.getBufferSize + +getBufferSize(): Promise8+ + +Obtains a reasonable minimum buffer size in bytes for capturing. This method uses a promise to return the result. + +**System capabilities**: SystemCapability.Multimedia.Audio.Capturer + +**Parameters** + +None + +**Return value** + +| Type | Description | +| :--------------- | :-------------------------------------- | +| Promise | Promise used to return the buffer size. | + +**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"); +}); +``` + + +## audioCapturer.on + +on(type: 'markReach', frame: number, callback: (position: number)): void8+ + +Listens for mark reach event. When the frames captured reaches given value in frame parameter, the callback is called. + +**System capabilities**: SystemCapability.Multimedia.Audio.Capturer + +**Parameters** + +| Name | Type | Mandatory | Description | +| :------- | :------------------------ | :-------- | :---------------------------------------------------------| +| type | string | Yes | Type of the capture event to listen for. | +| frame | number | Yes | Indicates the frame number to be reached to trigger event | +| callback | Callback | Yes | Callback used to listen for mark reach event | + +**Return value** + +None + +**Example** + +``` +audioCapturer.on('markReach', 1000, (position) => { + if (position == "1000") { + console.log('ON Triggered successfully'); + } +}); +``` + + +## audioCapturer.off + +off(type: 'markReach'): void8+ + +Unsubscribes the mark reach event. + +**System capabilities**: SystemCapability.Multimedia.Audio.Capturer + +**Parameters** + +| Name | Type | Mandatory | Description | +| :------- | :------------------------ | :-------- | :---------------------------------------------- | +| type | string | Yes | Type of the capture event to listen for. | + +**Return value** + +None + +**Example** + +``` +audioCapturer.off('markReach'); +``` + +## audioCapturer.on + +on(type: 'periodReach', frame: number, callback: (position: number)): void8+ + +Listens for period reach event. When the frames captured reaches end value of period in frame parameter, the callback is called. + +**System capabilities**: SystemCapability.Multimedia.Audio.Capturer + +**Parameters** + +| Name | Type | Mandatory | Description | +| :------- | :------------------------ | :-------- | :--------------------------------------------------------------------------- | +| type | string | Yes | Type of the capture event to listen for. | +| frame | number | Yes | Period for listening to capture event | +| callback | Callback | Yes | Callback called when the captured frames reach the end of period mentioned | + +**Return value** + +None + +**Example** + +``` +audioCapturer.on('periodReach', 1000, (position) => { + if (position == "1000") { + console.log('ON Triggered successfully'); + } +}); +``` + +## audioCapturer.off + +off(type: 'periodReach'): void8+ + +Unsubscribes the period reach event. + +**System capabilities**: SystemCapability.Multimedia.Audio.Capturer + +**Parameters** + +| Name | Type | Mandatory | Description | +| :------- | :------------------------ | :-------- | :---------------------------------------------- | +| type | string | Yes | Type of the capture event to listen for. | + +**Return value** + +None + +**Example** + +``` +audioCapturer.off('periodReach') +``` \ No newline at end of file