diff --git a/en/application-dev/reference/apis/js-apis-audio.md b/en/application-dev/reference/apis/js-apis-audio.md index 6c7076e006a05fa06e709633f0e5e345265f9dca..98d16f8591eed0dd77e1c68a39bdd1c937c4c6d2 100644 --- a/en/application-dev/reference/apis/js-apis-audio.md +++ b/en/application-dev/reference/apis/js-apis-audio.md @@ -1,4 +1,15 @@ -# Audio Management +# Audio + +This module provides the following functions: audio management, audio rendering and system sound management. + + +--- +## ***Note:*** + + Changes to the AudioRenderer interface have been proposed. + When the updated APIs have been integrated, the document will be revised, and apps must adapt to it. + +--- ## Modules to Import @@ -10,11 +21,13 @@ import audio from '@ohos.multimedia.audio'; None -## getAudioManager\(\): AudioManager +## audioManager + +getAudioManager\(\): AudioManager Obtains an **AudioManager** instance. -**Return values** +**Return value** - @@ -37,6 +50,55 @@ Obtains an **AudioManager** instance. var audioManager = audio.getAudioManager(); ``` + +## audioRenderer + +createAudioRenderer(volumeType: AudioVolumeType): AudioRenderer + +Obtains an **AudioRenderer** instance. + +**Parameters** +| Name | Type | Mandatory | Description | +| :--------- | :-------------- | :-------- | :----------------- | +| volumeType | AudioVolumeType | Yes | Audio stream type. | + +**Return value** + +| Type | Description | +| ------------- | --------------------- | +| AudioRenderer | AudioRenderer object. | + +**Example** + +``` +const volType = audio.AudioVolumeType.MEDIA; +const audioRenderer = audio.createAudioRenderer(volType); +``` + + +## systemSoundManager + +getSystemSoundManager(): SystemSoundManager + +Obtains a **SystemSoundManager** instance. + +**Parameters** + +None + +**Return value** + +| Type | Description | +| ------------------ | -------------------------- | +| SystemSoundManager | SystemSoundManager object. | + +**Example** + +``` +const systemSoundManager = audio.getSystemSoundManager(); +``` + + ## AudioVolumeType Enumerates audio stream types. @@ -54,19 +116,20 @@ Enumerates audio stream types. - -

Type

@@ -25,7 +38,7 @@ Obtains an **AudioManager** instance.

AudioManager

Audio manager

+

AudioManager object.

2

Audio stream for ringtones

+

Audio stream for ringtones.

MEDIA

3

Audio stream for media purpose

+

Audio stream for media purpose.

+ ## DeviceFlag Enumerates audio device flags. @@ -84,26 +147,27 @@ Enumerates audio device flags.

1

-

Output device

+

Output device.

INPUT_DEVICES_FLAG

2

-

Input device

+

Input device.

ALL_DEVICES_FLAG

3

-

All devices

+

All devices.

+ ## DeviceRole Enumerates audio device roles. @@ -121,19 +185,20 @@ Enumerates audio device roles.

1

-

Input role

+

Input role.

OUTPUT_DEVICE

2

-

Output role

+

Output role.

+ ## DeviceType Enumerates audio device types. @@ -151,47 +216,48 @@ Enumerates audio device types.

0

-

Invalid device

+

Invalid device.

SPEAKER

1

-

Speaker

+

Speaker.

WIRED_HEADSET

2

-

Wired headset

+

Wired headset.

BLUETOOTH_SCO

3

-

Bluetooth device using the synchronous connection oriented (SCO) link

+

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

BLUETOOTH_A2DP

4

-

Bluetooth device using the advanced audio distribution profile (A2DP)

+

Bluetooth device using the advanced audio distribution profile (A2DP).

MIC

5

-

Microphone

+

Microphone.

+ ## AudioRingMode7+ Enumerates ringer modes. @@ -209,33 +275,236 @@ Enumerates ringer modes.

0

-

Silence mode

+

Silence mode.

RINGER_MODE_VIBRATE

1

-

Vibration mode

+

Vibration mode.

RINGER_MODE_NORMAL

2

-

Normal mode

+

Normal mode.

-## AudioManager + +## AudioSampleFormat8+ +Enumerates the audio sample formats. + +| Name | Default Value | Description | +| :------------ | :------------ | :------------------------------------ | +| INVALID_WIDTH | -1 | Invalid format. | +| SAMPLE_U8 | 1 | Unsigned 8 bit integer. | +| SAMPLE_S16LE | 0 | Signed 16 bit integer, little endian. | +| SAMPLE_S24LE | 1 | Signed 24 bit integer, little endian. | +| SAMPLE_S32LE | 2 | Signed 32 bit integer, little endian. | + + +## AudioChannel8+ +Enumerates the audio channels. + +| Name | Default Value | Description | +| :----- | :------------ | :--------------- | +| MONO | 1 | Channel count 1. | +| STEREO | 2 | Channel count 2. | + + +## 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. | + + +## AudioEncodingType8+ +Enumerates the audio encoding types. + +| Name | Default Value | Description | +| :--------------- | :------------ | :---------- | +| ENCODING_PCM | 0 | PCM. | +| ENCODING_INVALID | 1 | Invalid. | + + +## 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. | + + +## 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. | + + +## AudioState8+ +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. | + + +## 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. | + + +## 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. | + + +## 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. | + + +## 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. | + + +## RingtoneType8+ +Enumerates the ringtone types. + +| Name | Default Value | Description | +| :--------------------- | :------------ | :-------------- | +| RINGTONE_TYPE_DEFAULT | 0 | Default type. | +| RINGTONE_TYPE_MULTISIM | 1 | Multi-SIM type. | + + +## AudioParameters8+ +Describes audio parameters of playback files. + +**Parameters** + +| Name | Type | Mandatory | Description | +| :----------- | :---------------- | :-------- | :-------------------------------------------- | +| format | AudioSampleFormat | Yes | Sample format of the audio file to be played. | +| channels | AudioChannel | Yes | Channel count of the audio file to be played. | +| samplingRate | AudioSamplingRate | Yes | Sample rate of the audio file to be played. | +| encoding | AudioEncodingType | Yes | Encoding type of the audio file to be played. | +| contentType | ContentType | Yes | Content type. | +| usage | StreamUsage | Yes | Stream usage. | +| deviceRole | DeviceRole | Yes | Device role. | +| deviceType | DeviceType | Yes | Device type. | + + +## AudioRendererInfo8+ +Describes audio renderer information. + +**Parameters** + +| Name | Type | Mandatory | Description | +| :------------ | :---------- | :-------- | :-------------------- | +| contentType | ContentType | Yes | Content type. | +| usage | StreamUsage | Yes | Stream usage. | +| rendererFlags | number | Yes | Audio renderer flags. | + + +## InterruptEvent8+ +Describes the interrupt event received by the app when playback is interrupted. + +**Parameters** + +| 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. | + + +## VolumeEvent8+ +Describes the volume event received by the app when the volume is changed. + +**Parameters** + +| 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. | + + +## RingtoneOptions8+ +Describes ringtone options. + +**Parameters** + +| Name | Type | Mandatory | Description | +| :----- | :------ | :-------- | :--------------- | +| volume | number | Yes | Ringtone volume. | +| loop | boolean | Yes | Loop value. | + + +# AudioManager Implements audio volume and audio device management. -### setVolume\(volumeType: AudioVolumeType, volume: number, callback: AsyncCallback\): void +## 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 execution result. +Sets the volume for a stream. This method uses an asynchronous callback to return the result. **Parameters** @@ -256,7 +525,7 @@ Sets the volume for a stream. This method uses an asynchronous callback to retur

Yes

-

Audio stream type

+

Audio stream type.

volume

@@ -274,13 +543,13 @@ Sets the volume for a stream. This method uses an asynchronous callback to retur

Yes

-

Callback used to return the execution result

+

Callback used to return the result.

-**Return values** +**Return value** None @@ -295,10 +564,11 @@ audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10, (err)=>{ console.log('Callback invoked to indicate a successful volume setting.'); }) ``` +## audioManager.setVolume -### setVolume\(volumeType: AudioVolumeType, volume: number\): Promise +setVolume\(volumeType: AudioVolumeType, volume: number\): Promise -Sets the volume for a stream. This method uses a promise to return the execution result. +Sets the volume for a stream. This method uses a promise to return the result. **Parameters** @@ -319,7 +589,7 @@ Sets the volume for a stream. This method uses a promise to return the execution

Yes

-

Audio stream type

+

Audio stream type.

volume

@@ -334,7 +604,7 @@ Sets the volume for a stream. This method uses a promise to return the execution -**Return values** +**Return value** - @@ -359,7 +629,9 @@ audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(()=> ) ``` -### getVolume\(volumeType: AudioVolumeType, callback: AsyncCallback\): void +## 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. @@ -382,7 +654,7 @@ Obtains the volume of a stream. This method uses an asynchronous callback to ret - -

Type

@@ -345,7 +615,7 @@ Sets the volume for a stream. This method uses a promise to return the execution

Promise<void>

Promise used to return the execution result

+

Promise used to return the result.

Yes

Audio stream type

+

Audio stream type.

callback

@@ -391,13 +663,13 @@ Obtains the volume of a stream. This method uses an asynchronous callback to ret

Yes

Callback used to return the volume

+

Callback used to return the volume.

-**Return values** +**Return value** None @@ -413,7 +685,10 @@ audioManager.getVolume(audio.AudioVolumeType.MEDIA, (err, value) => { }) ``` -### getVolume\(volumeType: AudioVolumeType\): Promise + +## audioManager.getVolume + +getVolume\(volumeType: AudioVolumeType\): Promise Obtains the volume of a stream. This method uses a promise to return the query result. @@ -436,13 +711,13 @@ Obtains the volume of a stream. This method uses a promise to return the query r

Yes

-

Audio stream type

+

Audio stream type.

-**Return values** +**Return value** - @@ -467,7 +742,10 @@ audioManager.getVolume(audio.AudioVolumeType.MEDIA).then((value) => ) ``` -### getMinVolume\(volumeType: AudioVolumeType, callback: AsyncCallback\): void + +## 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. @@ -490,7 +768,7 @@ Obtains the minimum volume allowed for a stream. This method uses an asynchronou - -

Type

@@ -453,7 +728,7 @@ Obtains the volume of a stream. This method uses a promise to return the query r

Promise<number>

Promise used to return the volume

+

Promise used to return the volume.

Yes

Audio stream type

+

Audio stream type.

callback

@@ -499,13 +777,13 @@ Obtains the minimum volume allowed for a stream. This method uses an asynchronou

Yes

Callback used to return the minimum volume

+

Callback used to return the minimum volume.

-**Return values** +**Return value** None @@ -521,7 +799,10 @@ audioManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err, value) => { }) ``` -### getMinVolume\(volumeType: AudioVolumeType\): Promise + +## audioManager.getMinVolume + +getMinVolume\(volumeType: AudioVolumeType\): Promise Obtains the minimum volume allowed for a stream. This method uses a promise to return the query result. @@ -544,13 +825,13 @@ Obtains the minimum volume allowed for a stream. This method uses a promise to r

Yes

-

Audio stream type

+

Audio stream type.

-**Return values** +**Return value** - @@ -575,7 +856,10 @@ audioManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value) => ) ``` -### getMaxVolume\(volumeType: AudioVolumeType, callback: AsyncCallback\): void + +## 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. @@ -598,7 +882,7 @@ Obtains the maximum volume allowed for a stream. This method uses an asynchronou - -

Type

@@ -561,7 +842,7 @@ Obtains the minimum volume allowed for a stream. This method uses a promise to r

Promise<number>

Promise used to return the minimum volume

+

Promise used to return the minimum volume.

Yes

Audio stream type

+

Audio stream type.

callback

@@ -607,13 +891,13 @@ Obtains the maximum volume allowed for a stream. This method uses an asynchronou

Yes

Callback used to return the maximum volume

+

Callback used to return the maximum volume.

-**Return values** +**Return value** None @@ -629,7 +913,10 @@ audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA, (err, value) => { }) ``` -### getMaxVolume\(volumeType: AudioVolumeType\): Promise + +## audioManager.getMaxVolume + +getMaxVolume\(volumeType: AudioVolumeType\): Promise Obtains the maximum volume allowed for a stream. This method uses a promise to return the query result. @@ -652,13 +939,13 @@ Obtains the maximum volume allowed for a stream. This method uses a promise to r

Yes

-

Audio stream type

+

Audio stream type.

-**Return values** +**Return value** - @@ -683,9 +970,11 @@ audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data)=> ) ``` -### mute\(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback\): void7+ +## audioManager.mute + +mute\(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback\): void7+ -Mutes a stream. This method uses an asynchronous callback to return the execution result. +Mutes a stream. This method uses an asynchronous callback to return the result. **Parameters** @@ -706,7 +995,7 @@ Mutes a stream. This method uses an asynchronous callback to return the executio - -

Type

@@ -669,7 +956,7 @@ Obtains the maximum volume allowed for a stream. This method uses a promise to r

Promise<number>

Promise used to return the maximum volume

+

Promise used to return the maximum volume.

Yes

Audio stream type

+

Audio stream type.

mute

@@ -724,13 +1013,13 @@ Mutes a stream. This method uses an asynchronous callback to return the executio

Yes

Callback used to return the execution result

+

Callback used to return the result.

-**Return values** +**Return value** None @@ -746,9 +1035,12 @@ audioManager.mute(audio.AudioVolumeType.MEDIA, true, (err) => { }) ``` -### mute\(volumeType: AudioVolumeType, mute: boolean\): Promise7+ -Mutes a stream. This method uses a promise to return the execution result. +## audioManager.mute + +mute\(volumeType: AudioVolumeType, mute: boolean\): Promise7+ + +Mutes a stream. This method uses a promise to return the result. **Parameters** @@ -769,7 +1061,7 @@ Mutes a stream. This method uses a promise to return the execution result.

Yes

-

Audio stream type

+

Audio stream type.

mute

@@ -784,7 +1076,7 @@ Mutes a stream. This method uses a promise to return the execution result. -**Return values** +**Return value** - @@ -809,7 +1101,10 @@ audioManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => ) ``` -### isMute\(volumeType: AudioVolumeType, callback: AsyncCallback\): void7+ + +## audioManager.isMute + +isMute\(volumeType: AudioVolumeType, callback: AsyncCallback\): void7+ Checks whether a stream is muted. This method uses an asynchronous callback to return the query result. @@ -832,7 +1127,7 @@ Checks whether a stream is muted. This method uses an asynchronous callback to r -

Type

@@ -795,7 +1087,7 @@ Mutes a stream. This method uses a promise to return the execution result.

Promise<void>

Promise used to return the execution result

+

Promise used to return the result.

Yes

Audio stream type

+

Audio stream type.

callback

@@ -847,7 +1142,7 @@ Checks whether a stream is muted. This method uses an asynchronous callback to r
-**Return values** +**Return value** None @@ -863,9 +1158,12 @@ audioManager.isMute(audio.AudioVolumeType.MEDIA, (err, value) => { }) ``` -### isMute\(volumeType: AudioVolumeType\): Promise7+ -Checks whether a stream is muted. This method uses a promise to return the execution result. +## audioManager.isMute + +isMute\(volumeType: AudioVolumeType\): Promise7+ + +Checks whether a stream is muted. This method uses a promise to return the result. **Parameters** @@ -886,13 +1184,13 @@ Checks whether a stream is muted. This method uses a promise to return the execu

Yes

-

Audio stream type

+

Audio stream type.

-**Return values** +**Return value** -

Type

@@ -917,7 +1215,10 @@ audioManager.isMute(audio.AudioVolumeType.MEDIA).then((value) => ) ``` -### isActive\(volumeType: AudioVolumeType, callback: AsyncCallback\): void7+ + +## audioManager.isActive + +isActive\(volumeType: AudioVolumeType, callback: AsyncCallback\): void7+ Checks whether a stream is active. This method uses an asynchronous callback to return the query result. @@ -940,7 +1241,7 @@ Checks whether a stream is active. This method uses an asynchronous callback to

Yes

Audio stream type

+

Audio stream type.

callback

@@ -955,7 +1256,7 @@ Checks whether a stream is active. This method uses an asynchronous callback to
-**Return values** +**Return value** None @@ -971,7 +1272,10 @@ audioManager.isActive(audio.AudioVolumeType.MEDIA, (err, value) => { }) ``` -### isActive\(volumeType: AudioVolumeType\): Promise7+ + +## audioManager.isActive + +isActive\(volumeType: AudioVolumeType\): Promise7+ Checks whether a stream is active. This method uses a promise to return the query result. @@ -994,13 +1298,13 @@ Checks whether a stream is active. This method uses a promise to return the quer

Yes

-

Audio stream type

+

Audio stream type.

-**Return values** +**Return value** - -

Type

@@ -1025,9 +1329,12 @@ audioManager.isActive(audio.AudioVolumeType.MEDIA).then((value) => ) ``` -### setRingerMode\(mode: AudioRingMode, callback: AsyncCallback\): void7+ -Sets the ringer mode. This method uses an asynchronous callback to return the execution result. +## audioManager.setRingerMode + +setRingerMode\(mode: AudioRingMode, callback: AsyncCallback\): void7+ + +Sets the ringer mode. This method uses an asynchronous callback to return the result. **Parameters** @@ -1048,7 +1355,7 @@ Sets the ringer mode. This method uses an asynchronous callback to return the ex

Yes

Ringer mode

+

Ringer mode.

callback

@@ -1057,13 +1364,13 @@ Sets the ringer mode. This method uses an asynchronous callback to return the ex

Yes

Callback used to return the execution result

+

Callback used to return the result.

-**Return values** +**Return value** None @@ -1079,9 +1386,12 @@ audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL, (err) => { }) ``` -### setRingerMode\(mode: AudioRingMode\): Promise7+ -Sets the ringer mode. This method uses a promise to return the execution result. +## audioManager.setRingerMode + +setRingerMode\(mode: AudioRingMode\): Promise7+ + +Sets the ringer mode. This method uses a promise to return the result. **Parameters** @@ -1102,13 +1412,13 @@ Sets the ringer mode. This method uses a promise to return the execution result.

Yes

-

Ringer mode

+

Ringer mode.

-**Return values** +**Return value** - @@ -1133,7 +1443,10 @@ audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() => ) ``` -### getRingerMode\(callback: AsyncCallback\): void7+ + +## audioManager.getRingerMode + +getRingerMode\(callback: AsyncCallback\): void7+ Obtains the ringer mode. This method uses an asynchronous callback to return the query result. @@ -1156,13 +1469,13 @@ Obtains the ringer mode. This method uses an asynchronous callback to return the -

Type

@@ -1119,7 +1429,7 @@ Sets the ringer mode. This method uses a promise to return the execution result.

Promise<void>

Promise used to return the execution result

+

Promise used to return the result.

Yes

Callback used to return the ringer mode

+

Callback used to return the ringer mode.

-**Return values** +**Return value** None @@ -1178,7 +1491,10 @@ audioManager.getRingerMode((err, value) => { }) ``` -### getRingerMode\(\): Promise7+ + +## audioManager.getRingerMode + +getRingerMode\(\): Promise7+ Obtains the ringer mode. This method uses a promise to return the query result. @@ -1186,7 +1502,7 @@ Obtains the ringer mode. This method uses a promise to return the query result. None -**Return values** +**Return value** - @@ -1211,9 +1527,12 @@ audioManager.getRingerMode().then((value) => ) ``` -### setAudioParameter\(key: string, value: string, callback: AsyncCallback\): void7+ -Sets an audio parameter. This method uses an asynchronous callback to return the execution result. +## audioManager.setAudioParameter + +setAudioParameter\(key: string, value: string, callback: AsyncCallback\): void7+ + +Sets an audio parameter. This method uses an asynchronous callback to return the result. **Parameters** @@ -1234,7 +1553,7 @@ Sets an audio parameter. This method uses an asynchronous callback to return the - - -

Type

@@ -1197,7 +1513,7 @@ None

Promise<AudioRingMode>

Promise used to return the ringer mode

+

Promise used to return the ringer mode.

Yes

Key of the audio parameter to set

+

Key of the audio parameter to set.

value

@@ -1243,7 +1562,7 @@ Sets an audio parameter. This method uses an asynchronous callback to return the

Yes

Value of the audio parameter to set

+

Value of the audio parameter to set.

callback

@@ -1252,13 +1571,13 @@ Sets an audio parameter. This method uses an asynchronous callback to return the

Yes

Callback used to return the execution result

+

Callback used to return the result.

-**Return values** +**Return value** None @@ -1274,9 +1593,12 @@ audioManager.setAudioParameter('PBits per sample', '8 bit', (err) => { }) ``` -### setAudioParameter\(key: string, value: string\): Promise7+ -Sets an audio parameter. This method uses a promise to return the execution result. +## audioManager.setAudioParameter + +setAudioParameter\(key: string, value: string\): Promise7+ + +Sets an audio parameter. This method uses a promise to return the result. **Parameters** @@ -1297,7 +1619,7 @@ Sets an audio parameter. This method uses a promise to return the execution resu

Yes

-

Key of the audio parameter to set

+

Key of the audio parameter to set.

value

@@ -1306,13 +1628,13 @@ Sets an audio parameter. This method uses a promise to return the execution resu

Yes

-

Value of the audio parameter to set

+

Value of the audio parameter to set.

-**Return values** +**Return value** - @@ -1337,7 +1659,10 @@ audioManager.setAudioParameter('PBits per sample', '8 bit').then(() => ) ``` -### getAudioParameter\(key: string, callback: AsyncCallback\): void7+ + +## audioManager.getAudioParameter + +getAudioParameter\(key: string, callback: AsyncCallback\): void7+ Obtains the value of an audio parameter. This method uses an asynchronous callback to return the query result. @@ -1360,7 +1685,7 @@ Obtains the value of an audio parameter. This method uses an asynchronous callba - -

Type

@@ -1323,7 +1645,7 @@ Sets an audio parameter. This method uses a promise to return the execution resu

Promise<void>

Promise used to return the execution result

+

Promise used to return the result.

Yes

Key of the audio parameter whose value is to be obtained

+

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

callback

@@ -1369,13 +1694,13 @@ Obtains the value of an audio parameter. This method uses an asynchronous callba

Yes

Callback used to return the value of the audio parameter

+

Callback used to return the value of the audio parameter.

-**Return values** +**Return value** None @@ -1391,7 +1716,10 @@ audioManager.getAudioParameter('PBits per sample', (err, value) => { }) ``` -### getAudioParameter\(key: string\): Promise7+ + +## audioManager.getAudioParameter + +getAudioParameter\(key: string\): Promise7+ Obtains the value of an audio parameter. This method uses a promise to return the query result. @@ -1414,13 +1742,13 @@ Obtains the value of an audio parameter. This method uses a promise to return th

Yes

-

Key of the audio parameter whose value is to be obtained

+

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

-**Return values** +**Return value** - @@ -1445,7 +1773,10 @@ audioManager.getAudioParameter('PBits per sample').then((value) => ) ``` -### getDevices\(deviceFlag: DeviceFlag, callback: AsyncCallback\): void + +## 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. @@ -1468,7 +1799,7 @@ Obtains the audio devices with a specific flag. This method uses an asynchronous - -

Type

@@ -1431,7 +1759,7 @@ Obtains the value of an audio parameter. This method uses a promise to return th

Promise<string>

Promise used to return the value of the audio parameter

+

Promise used to return the value of the audio parameter.

Yes

Audio device flag

+

Audio device flag.

callback

@@ -1477,13 +1808,13 @@ Obtains the audio devices with a specific flag. This method uses an asynchronous

Yes

Callback used to return the device list

+

Callback used to return the device list.

-**Return values** +**Return value** None @@ -1499,7 +1830,11 @@ audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err, value)=>{ }) ``` -### getDevices\(deviceFlag: DeviceFlag\): Promise + + +## audioManager.getDevices + +getDevices\(deviceFlag: DeviceFlag\): Promise Obtains the audio devices with a specific flag. This method uses a promise to return the query result. @@ -1522,13 +1857,13 @@ Obtains the audio devices with a specific flag. This method uses a promise to re

Yes

-

Audio device flag

+

Audio device flag.

-**Return values** +**Return value** - @@ -1553,9 +1888,12 @@ audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data)=> ) ``` -### setDeviceActive\(deviceType: DeviceType, active: boolean, callback: AsyncCallback\): void7+ -Sets a device to the active state. This method uses an asynchronous callback to return the execution result. +## audioManager.setDeviceActive + +setDeviceActive\(deviceType: DeviceType, active: boolean, callback: AsyncCallback\): void7+ + +Sets a device to the active state. This method uses an asynchronous callback to return the result. **Parameters** @@ -1576,7 +1914,7 @@ Sets a device to the active state. This method uses an asynchronous callback to - -

Type

@@ -1539,7 +1874,7 @@ Obtains the audio devices with a specific flag. This method uses a promise to re

Promise<AudioDeviceDescriptors>

Promise used to return the device list

+

Promise used to return the device list.

Yes

Audio device type

+

Audio device type.

active

@@ -1594,13 +1932,13 @@ Sets a device to the active state. This method uses an asynchronous callback to

Yes

Callback used to return the execution result

+

Callback used to return the result.

-**Return values** +**Return value** None @@ -1616,9 +1954,13 @@ audioManager.setDeviceActive(audio.DeviceType.SPEAKER, true, (err)=> { }) ``` -### setDeviceActive\(deviceType: DeviceType, active: boolean\): Promise7+ -Sets a device to the active state. This method uses a promise to return the execution result. + +## audioManager.setDeviceActive + +setDeviceActive\(deviceType: DeviceType, active: boolean\): Promise7+ + +Sets a device to the active state. This method uses a promise to return the result. **Parameters** @@ -1639,7 +1981,7 @@ Sets a device to the active state. This method uses a promise to return the exec

Yes

-

Audio device type

+

Audio device type.

active

@@ -1654,7 +1996,7 @@ Sets a device to the active state. This method uses a promise to return the exec -**Return values** +**Return value** - @@ -1679,7 +2021,10 @@ audioManager.setDeviceActive(audio.DeviceType.SPEAKER, true).then(()=> ) ``` -### isDeviceActive\(deviceType: DeviceType, callback: AsyncCallback\): void7+ + +## audioManager.isDeviceActive + +isDeviceActive\(deviceType: DeviceType, callback: AsyncCallback\): void7+ Checks whether a device is active. This method uses an asynchronous callback to return the query result. @@ -1702,7 +2047,7 @@ Checks whether a device is active. This method uses an asynchronous callback to - -

Type

@@ -1665,7 +2007,7 @@ Sets a device to the active state. This method uses a promise to return the exec

Promise<void>

Promise used to return the execution result

+

Promise used to return the result.

Yes

Audio device type

+

Audio device type.

callback

@@ -1711,13 +2056,13 @@ Checks whether a device is active. This method uses an asynchronous callback to

Yes

Callback used to return the active status of the device

+

Callback used to return the active status of the device.

-**Return values** +**Return value** None @@ -1733,7 +2078,10 @@ audioManager.isDeviceActive(audio.DeviceType.SPEAKER, (err, value) => { }) ``` -### isDeviceActive\(deviceType: DeviceType\): Promise7+ + +## audioManager.isDeviceActive + +isDeviceActive\(deviceType: DeviceType\): Promise7+ Checks whether a device is active. This method uses a promise to return the query result. @@ -1756,13 +2104,13 @@ Checks whether a device is active. This method uses a promise to return the quer

Yes

-

Audio device type

+

Audio device type.

-**Return values** +**Return value** - @@ -1787,9 +2135,12 @@ audioManager.isDeviceActive(audio.DeviceType.SPEAKER).then((value) => ) ``` -### setMicrophoneMute\(mute: boolean, callback: AsyncCallback\): void7+ -Mutes or unmutes the microphone. This method uses an asynchronous callback to return the execution result. +## audioManager.setMicrophoneMute + +setMicrophoneMute\(mute: boolean, callback: AsyncCallback\): void7+ + +Mutes or unmutes the microphone. This method uses an asynchronous callback to return the result. **Parameters** @@ -1819,13 +2170,13 @@ Mutes or unmutes the microphone. This method uses an asynchronous callback to re -

Type

@@ -1773,7 +2121,7 @@ Checks whether a device is active. This method uses a promise to return the quer

Promise<boolean>

Promise used to return the active status of the device

+

Promise used to return the active status of the device.

Yes

Callback used to return the execution result

+

Callback used to return the result.

-**Return values** +**Return value** None @@ -1841,9 +2192,12 @@ audioManager.setMicrophoneMute(true, (err) => { }) ``` -### setMicrophoneMute\(mute: boolean\): Promise7+ -Mutes or unmutes the microphone. This method uses a promise to return the execution result. +## audioManager.setMicrophoneMute + +setMicrophoneMute\(mute: boolean\): Promise7+ + +Mutes or unmutes the microphone. This method uses a promise to return the result. **Parameters** @@ -1870,7 +2224,7 @@ Mutes or unmutes the microphone. This method uses a promise to return the execut -**Return values** +**Return value** - @@ -1895,7 +2249,10 @@ audioManager.setMicrophoneMute(true).then(() => ) ``` -### isMicrophoneMute\(callback: AsyncCallback\): void7+ + +## audioManager.isMicrophoneMute + +isMicrophoneMute\(callback: AsyncCallback\): void7+ Checks whether the microphone is muted. This method uses an asynchronous callback to return the query result. @@ -1924,7 +2281,7 @@ Checks whether the microphone is muted. This method uses an asynchronous callbac

Type

@@ -1881,7 +2235,7 @@ Mutes or unmutes the microphone. This method uses a promise to return the execut

Promise<void>

Promise used to return the execution result

+

Promise used to return the result.

-**Return values** +**Return value** None @@ -1940,7 +2297,10 @@ audioManager.isMicrophoneMute((err, value) => { }) ``` -### isMicrophoneMute\(\): Promise7+ + +## audioManager.isMicrophoneMute + +isMicrophoneMute\(\): Promise7+ Checks whether the microphone is muted. This method uses a promise to return the query result. @@ -1948,7 +2308,7 @@ Checks whether the microphone is muted. This method uses a promise to return the None -**Return values** +**Return value**

Type

@@ -1973,64 +2333,1673 @@ audioManager.isMicrophoneMute().then((value) => ) ``` -## AudioDeviceDescriptor -Describes an audio device. +## audioManager.on -### Attributes +on(type: 'volumeChange', callback: Callback): void8+ - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Readable

-

Writable

-

Description

-

deviceRole

-

DeviceRole

-

Yes

-

No

-

Audio device role

-

deviceType

-

DeviceType

-

Yes

-

No

-

Audio device type

-
+Listens for system volume change events. This method uses a callback to get volume change events. + +**Parameters** + +| 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. | + +**Return value** + +None + +**Example** + +``` +audioManager.on('volumeChange', (volumeEvent) => { + console.log('VolumeType of stream: ' + volumeEvent.volumeType); + console.log('Volume level: ' + volumeEvent.volume); + console.log('Whether to updateUI: ' + volumeEvent.updateUi); +}) +``` + + +## audioManager.on + +on(type: 'ringerModeChange', callback: Callback): void8+ + +Listens for ringer mode change events. This method uses a callback to get ringer mode changes. + +**Parameters** + +| 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. | + +**Return value** + +None + +**Example** + +``` +audioManager.on('ringerModeChange', (ringerMode) => { + console.log('Updated ringermode: ' + ringerMode); +}) +``` + +# AudioDeviceDescriptor +Describes an audio device. ## AudioDeviceDescriptors - - - - - - - - - -

Name

-

Description

-

Device attribute array

-

Array of AudioDeviceDescriptors, which is read-only

-
+type AudioDeviceDescriptors = Array\> : void\ +
+Array of AudioDeviceDescriptors, which is read-only. + +## audioDeviceDescriptor.deviceRole +readonly deviceRole: DeviceRole + +Defines the role of the device. + +| Name | Type | Readable | Writable | Description | +| :--------- | :--------- | :------- | :------- | ------------------ | +| deviceRole | DeviceRole | Yes | No | Audio device role. | + +## audioDeviceDescriptor.deviceType + +readonly deviceType: DeviceType + +Defines the type of the device. + +| Name | Type | Readable | Writable | Description | +| :--------- | :--------- | :------- | :------- | ------------------ | +| deviceType | DeviceType | Yes | No | Audio device type. | + +``` +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); + if (deviceTypeValue != null && deviceRoleValue != null){ + console.info('OUTPUT_DEVICES_FLAG : Pass'); + expect(true).assertTrue(); + } + else{ + console.error('OUTPUT_DEVICES_FLAG : fail'); + expect(false).assertTrue(); + } + }); + await promise; + done(); +}) +``` +# AudioRenderer +Provides audio playback APIs. + + +## audioRenderer.state + +readonly state: AudioState 8+ + +Defines the current render state. + +| Name | Type | Readable | Writable | Description | +| :---- | :--------- | :------- | :------- | :------------------ | +| state | AudioState | Yes | No | Audio render state. | + +**Example** + +``` + var state = audioRenderer.state; +``` + + +## audioRenderer.setParams + +setParams(params: AudioParameters, callback: AsyncCallback): void8+ + +Sets audio parameters for rendering. This method uses an asynchronous callback to return the result. + +**Parameters** + +| Name | Type | Mandatory | Description | +| :------- | :------------------- | :-------- | :-------------------------------------- | +| params | AudioParameters | Yes | Audio parameters of the file to be set. | +| callback | AsyncCallback | Yes | Callback used to return the result. | +| | | | | + +**Return value** + +None + +**Example** + +``` +var audioParams = { + format: audio.AudioSampleFormat.SAMPLE_S16LE, + channels: audio.AudioChannel.STEREO, + samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_16000, + encoding: audio.AudioEncodingType.ENCODING_PCM, + }; + +audioRenderer.setParams(audioParams, (err)=>{ + if (err) { + console.error('Failed to set params. ${err.message}'); + return; + } + console.log('Callback invoked to indicate a successful params setting.'); +}) +``` + + +## audioRenderer.setParams + +setParams(params: AudioParameters): Promise8+ + +Sets audio parameters for rendering. This method uses a promise to return the result. + +**Parameters** + +| Name | Type | Mandatory | Description | +| :----- | :-------------- | :-------- | :-------------------------------------- | +| params | AudioParameters | Yes | Audio parameters of the file to be set. | + +**Return value** + +| Type | Description | +| :------------- | :--------------------------------- | +| Promise | Promise used to return the result. | + +**Example** + +``` +var audioParams = { + format: audio.AudioSampleFormat.SAMPLE_S16LE, + channels: audio.AudioChannel.STEREO, + samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_16000, + encoding: audio.AudioEncodingType.ENCODING_PCM, + }; + +await audioRenderer.setParams(audioParams); +``` + + +## audioRenderer.getParams + +getParams(callback: AsyncCallback): void8+ + +Gets audio parameters of the renderer. This method uses an asynchronous callback to return the result. + +**Parameters** + +| Name | Type | Mandatory | Description | +| :------- | :------------------------------ | :-------- | :-------------------------------------------- | +| callback | AsyncCallback | Yes | Callback used to return the audio parameters. | +| | | | | + +**Return value** + +None + +**Example** + +``` +audioRenderer.getParams((err, audioParams)=>{ + console.log('Renderer GetParams:'); + console.log('Renderer format:' + audioParams.format); + console.log('Renderer samplingRate:' + audioParams.samplingRate); + console.log('Renderer channels:' + audioParams.channels); + console.log('Renderer encoding:' + audioParams.encoding); +}) +``` + + +## audioRenderer.getParams + +getParams(): Promise8+ + +Gets audio parameters of the renderer. This method uses a promise to return the result. + +**Parameters** + +None + +**Return value** + +| Type | Description | +| :------------------------ | :------------------------------------------- | +| Promise | Promise used to return the audio parameters. | + +**Example** + +``` +let audioParams = await audioRenderer.getParams(); +console.log('Renderer GetParams:'); +console.log('Renderer format:' + audioParams.format); +console.log('Renderer samplingRate:' + audioParams.samplingRate); +console.log('Renderer channels:' + audioParams.channels); +console.log('Renderer encoding:' + audioParams.encoding); +``` + + +## audioRenderer.start + +start(callback: AsyncCallback): void8+ + +Starts the renderer. This method uses an asynchronous callback to return the result. + +**Parameters** + +| Name | Type | Mandatory | Description | +| :------- | :---------------------- | :-------- | :----------------------------------------------------------------------------- | +| callback | AsyncCallback | Yes | Returns true if the renderer is started successfully; returns false otherwise. | +| | | | | + +**Return value** + +None + +**Example** + +``` +audioRenderer.start((err, started)=>{ + if (started) { + console.log('Renderer started.'); + } else { + console.error('Renderer start rejected.'); + } +}) +``` + + +## audioRenderer.start + +start(): Promise8+ + +Starts the renderer. This method uses a promise to return the result. + +**Parameters** + +None + +**Return value** + +| Type | Description | +| :---------------- | :----------------------------------------------------------------------------- | +| Promise | Returns true if the renderer is started successfully; returns false otherwise. | + +**Example** + +``` +var started = await audioRenderer.start(); +if (started) { + console.log('Renderer started'); +} else { + console.error('Renderer start rejected'); +} +``` + + +## audioRenderer.pause + +pause(callback: AsyncCallback): void8+ + +Pauses rendering. This method uses an asynchronous callback to return the result. + +**Parameters** + +| Name | Type | Mandatory | Description | +| :------- | :---------------------- | :-------- | :---------------------------------------------------------------------------- | +| callback | AsyncCallback | Yes | Returns true if the renderer is paused successfully; returns false otherwise. | +| | | | | + +**Return value** + +None + +**Example** + +``` +audioRenderer.pause((err, paused)=>{ + if (paused) { + console.log('Renderer paused.'); + } else { + console.error('Renderer pause failed'); + } +}) +``` + + + +## audioRenderer.pause + +pause(): Promise8+ + +Pauses rendering. This method uses a promise to return the result. + +**Parameters** + +None + +**Return value** + +| Type | Description | +| :---------------- | :---------------------------------------------------------------------------- | +| Promise | Returns true if the renderer is paused successfully; returns false otherwise. | + +**Example** + +``` +var paused = await audioRenderer.pause(); +if (paused) { + console.log('Renderer paused'); +} else { + console.error('Renderer pause failed'); +} +``` + + + +## audioRenderer.drain + +drain(callback: AsyncCallback): void8+ + +Drains the playback buffer. This method uses an asynchronous callback to return the result. + +**Parameters** + +| Name | Type | Mandatory | Description | +| :------- | :---------------------- | :-------- | :--------------------------------------------------------------------------- | +| callback | AsyncCallback | Yes | Returns true if the buffer is drained successfully; returns false otherwise. | +| | | | | + +**Return value** + +None + +**Example** + +``` +audioRenderer.drain((err, drained)=>{ + if (drained) { + console.log('Renderer drained.'); + } else { + console.error('Renderer drain failed'); + } +}) +``` + + +## audioRenderer.drain + +drain(): Promise8+ + +Drains the playback buffer. This method uses a promise to return the result. + +**Parameters** + +None + +**Return value** + +| Type | Description | +| :---------------- | :--------------------------------------------------------------------------- | +| Promise | Returns true if the buffer is drained successfully; returns false otherwise. | + +**Example** + +``` +var drained = await audioRenderer.drain(); +if (drained) { + console.log('Renderer drained'); +} else { + console.error('Renderer drain failed'); +} +``` + + +## audioRenderer.stop + +stop(callback: AsyncCallback): void8+ + +Stops rendering. This method uses an asynchronous callback to return the result. + +**Parameters** + +| Name | Type | Mandatory | Description | +| :------- | :---------------------- | :-------- | :------------------------------------------------------------------------------ | +| callback | AsyncCallback | Yes | Returns true if the rendering is stopped successfully; returns false otherwise. | +| | | | | + +**Return value** + +None + +**Example** + +``` +audioRenderer.stop((err, stopped)=>{ + if (stopped) { + console.log('Renderer stopped.'); + } else { + console.error('Renderer stop failed'); + } +}) +``` + + +## audioRenderer.stop + +stop(): Promise8+ + +Stops rendering. This method uses a promise to return the result. + +**Parameters** + +None + +**Return value** + +| Type | Description | +| :---------------- | :------------------------------------------------------------------------------ | +| Promise | Returns true if the rendering is stopped successfully; returns false otherwise. | + +**Example** + +``` +var stopped = await audioRenderer.stop(); +if (stopped) { + console.log('Renderer stopped'); +} else { + console.error('Renderer stop failed'); +} +``` + + +## audioRenderer.release + +release(callback: AsyncCallback): void8+ + +Releases the renderer. This method uses an asynchronous callback to return the result. + +**Parameters** + +| Name | Type | Mandatory | Description | +| :------- | :---------------------- | :-------- | :------------------------------------------------------------------------------ | +| callback | AsyncCallback | Yes | Returns true if the renderer is released successfully; returns false otherwise. | +| | | | | + +**Return value** + +None + +**Example** + +``` +audioRenderer.release((err, released)=>{ + if (released) { + console.log('Renderer released.'); + } else { + console.error('Renderer release failed'); + } +}) +``` + + + +## audioRenderer.release + +release(): Promise8+ + +Releases the renderer. This method uses a promise to return the result. + +**Parameters** + +None + +**Return value** + +| Type | Description | +| :---------------- | :------------------------------------------------------------------------------ | +| Promise | Returns true if the renderer is released successfully; returns false otherwise. | + +**Example** + +``` +var released = await audioRenderer.release(); +if (released) { + console.log('Renderer released'); +} else { + console.error('Renderer release failed'); +} +``` + + + +## audioRenderer.write + +write(buffer: ArrayBuffer, callback: AsyncCallback): void8+ + +Writes the buffer. This method uses an asynchronous callback to return the result. + +**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** + +``` +let ss = fileio.createStreamSync(filePath, 'r'); +let buf = new ArrayBuffer(bufferSize); +ss.readSync(buf); +audioRenderer.write(buf, (err, writtenbytes)=>{ + if (writtenbytes < 0) { + console.error('write failed.'); + } else { + console.log('Actual written bytes: ' + writtenbytes); + } +}) +``` + + +## audioRenderer.write + +write(buffer: ArrayBuffer): Promise8+ + +Writes the buffer. This method uses a promise to return the result. + +**Parameters** + +None + +**Return value** + +| Type | Description | +| :--------------- | :--------------------------------------------------------------------------------------------------- | +| Promise | Returns the number of bytes written if the operation is successful; returns an error code otherwise. | + +**Example** + +``` +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.getAudioTime + +getAudioTime(callback: AsyncCallback): void8+ + +Obtains the timestamp. This method uses an asynchronous callback to return the result. + +**Parameters** + +| Name | Type | Mandatory | Description | +| :------- | :--------------------- | :-------- | :------------------------------------- | +| callback | AsyncCallback | Yes | Callback used to return the timestamp. | +| | | | | + +**Return value** + +None + +**Example** + +``` +audioRenderer.getAudioTime((err, timestamp)=>{ + console.log('Current timestamp: ' + timestamp); +}) +``` + + +## audioRenderer.getAudioTime + +getAudioTime(): Promise8+ + +Obtains the timestamp. This method uses a promise to return the result. + +**Parameters** + +None + +**Return value** + +| Type | Description | +| :--------------- | :------------------------------------ | +| Promise | Promise used to return the timestamp. | + +**Example** + +``` +let timestamp = await audioRenderer.getAudioTime(); +console.log('Current timestamp: ' + timestamp); +``` + + +## audioRenderer.getBufferSize + +getBufferSize(callback: AsyncCallback): void8+ + +Obtains a reasonable minimum buffer size for rendering. This method uses an asynchronous callback to return the result. + +**Parameters** + +| Name | Type | Mandatory | Description | +| :------- | :--------------------- | :-------- | :--------------------------------------- | +| callback | AsyncCallback | Yes | Callback used to return the buffer size. | +| | | | | + +**Return value** + +None + +**Example** + +``` +audioRenderer.getBufferSize((err, bufferSize)=>{ + if (err) { + console.error('getBufferSize error'); + } +}) +let buf = new ArrayBuffer(bufferSize); +ss.readSync(buf); +``` + + +## audioRenderer.getBufferSize + +getBufferSize(): Promise8+ + +Obtains a reasonable minimum buffer size for rendering. This method uses a promise to return the result. + +**Parameters** + +None + +**Return value** + +| Type | Description | +| :--------------- | :-------------------------------------- | +| Promise | Promise used to return the buffer size. | + +**Example** + +``` +var bufferSize = await audioRenderer.getBufferSize(); +let buf = new ArrayBuffer(bufferSize); +ss.readSync(buf); +``` + + +## audioRenderer.setRenderRate + +setRenderRate(rate: AudioRendererRate, callback: AsyncCallback): void8+ + +Sets the render rate. This method uses an asynchronous callback to return the result. + +**Parameters** + +| Name | Type | Mandatory | Description | +| :------- | :------------------- | :-------- | :---------------------------------- | +| rate | AudioRendererRate | Yes | Audio render rate. | +| callback | AsyncCallback | Yes | Callback used to return the result. | +| | | | | + +**Return value** + +None + +**Example** + +``` +audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL, (err)=> { + if (err) { + console.error('Failed to set params'); + } else { + console.log('Callback invoked to indicate a successful render rate setting.'); + } +}) +``` + + +## audioRenderer.setRenderRate + +setRenderRate(rate: AudioRendererRate): Promise8+ + +Sets the render rate. This method uses a promise to return the result. + +**Parameters** + +| Name | Type | Mandatory | Description | +| :--- | :---------------- | :-------- | :----------------- | +| rate | AudioRendererRate | Yes | Audio render rate. | + +**Return value** + +| Type | Description | +| :------------- | :--------------------------------- | +| Promise | Promise used to return the result. | + +**Example** + +``` +await audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL); +``` + + +## audioRenderer.getRenderRate + +getRenderRate(callback: AsyncCallback): void8+ + +Obtains the current render rate. This method uses an asynchronous callback to return the result. + +**Parameters** +| Name | Type | Mandatory | Description | +| :------- | :-------------------------------- | :-------- | :--------------------------------------------- | +| callback | AsyncCallback | Yes | Callback used to return the audio render rate. | +| | | | | + +**Return value** + +None + +**Example** + +``` +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. + +**Parameters** + +None + +**Return value** + +| Type | Description | +| :-------------------------- | :-------------------------------------------- | +| Promise | Promise used to return the audio render rate. | + +**Example** + +``` +let renderRate = await audioRenderer.getRenderRate(); +console.log('getRenderRate: ' + renderrate); +``` + + +## audioRenderer.on + +on(type: 'interrupt', callback: Callback): void8+ + +Listens for audio interrupt events. This method uses a callback to get interrupt events. The interrupt event is triggered when audio playback 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. | + +**Return value** + +None + +**Example** + +``` +audioRenderer.on('interrupt', (interruptEvent) => { + if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_FORCE) { + switch (interruptEvent.hintType) { + case audio.InterruptHint.INTERRUPT_HINT_PAUSE: + console.log('Force paused. Stop writing'); + isPlay = false; + break; + case audio.InterruptHint.INTERRUPT_HINT_STOP: + console.log('Force stopped. Stop writing'); + isPlay = false; + break; + } + } else if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_SHARE) { + switch (interruptEvent.hintType) { + case audio.InterruptHint.INTERRUPT_HINT_RESUME: + console.log('Resume force paused renderer or ignore'); + startRenderer(); + break; + case audio.InterruptHint.INTERRUPT_HINT_PAUSE: + console.log('Choose to pause or ignore'); + pauseRenderer(); + break; + } + } +}) +``` + + + +## SystemSoundManager + + +## systemSoundManager.setSystemRingtoneUri + +setSystemRingtoneUri(context: Context, uri: string, type: RingtoneType, callback: AsyncCallback): void8+ + +Sets the system ringtone URI. This method uses an asynchronous callback to return the result. + +**Parameters** + +| Name | Type | Mandatory | Description | +| :------- | :------------------- | :-------- | :---------------------------------- | +| context | Context | Yes | Current application context. | +| uri | string | Yes | Ringtone URI to be set. | +| type | RingtoneType | Yes | Ringtone type to be set. | +| callback | AsyncCallback | Yes | Callback used to return the result. | +| | | | | + +**Return value** + +None + +**Example** + +``` +systemSoundManager.setSystemRingtoneUri(null, '/data/media/Ringtonetone.wav', + audio.RingtoneType.RINGTONE_TYPE_DEFAULT, (err)=> { + if (err) { + console.error('Failed to setSystemRingtoneUri'); + } else { + console.log('Callback invoked to indicate a successful system ringtone URI setting.'); + } +}) +``` + + +## systemSoundManager.setSystemRingtoneUri + +setSystemRingtoneUri(context: Context, uri: string, type: RingtoneType): Promise8+ + +Sets the system ringtone URI. This method uses a promise to return the result. + +**Parameters** + +| Name | Type | Mandatory | Description | +| :------ | :----------- | :-------- | :--------------------------- | +| context | Context | Yes | Current application context. | +| uri | string | Yes | Ringtone URI to be set. | +| type | RingtoneType | Yes | Ringtone type to be set. | +| | | | | + +**Return value** + +| Type | Description | +| :------------- | :--------------------------------- | +| Promise | Promise used to return the result. | + +**Example** + +``` +await systemSoundManager.setSystemRingtoneUri(null, '/data/media/Ringtone.wav', audio.RingtoneType.RINGTONE_TYPE_DEFAULT); +``` + + +## systemSoundManager.getSystemRingtoneUri + +getSystemRingtoneUri(context: Context, type: RingtoneType, callback: AsyncCallback): void8+ + +Obtains the system ringtone URI. This method uses an asynchronous callback to return the result. + +**Parameters** + +| Name | Type | Mandatory | Description | +| :------- | :--------------------- | :-------- | :---------------------------------- | +| context | Context | Yes | Current application context. | +| type | RingtoneType | Yes | Ringtone type to be obtained. | +| callback | AsyncCallback | Yes | Callback used to return the result. | +| | | | | + +**Return value** + +None + +**Example** + +``` +systemSoundManager.getSystemRingtoneUri(null, audio.RingtoneType.RINGTONE_TYPE_DEFAULT, (err, ringtoneUri)=>{ + if (err) { + console.err('getSystemRingtoneUri failed'); + } else { + console.log('getSystemRingtoneUri success: ' + ringtoneUri); + } +}) +``` + + +## systemSoundManager.getSystemRingtoneUri + +getSystemRingtoneUri(context: Context, type: RingtoneType): Promise8+ + +Obtains the system ringtone URI. This method uses a promise to return the result. + +**Parameters** + +None + +**Return value** + +| Type | Description | +| :--------------- | :-------------------------------- | +| Promise | Promise used to the ringtone URI. | + +**Example** + +``` +let ringtoneUri = await systemSoundManager.getSystemRingtoneUri(null, audio.RingtoneType.RINGTONE_TYPE_DEFAULT); +if (ringtoneUri == '/data/media/Believer60s.wav') { + console.log('getSystemRingtoneUri success: ' + uri); +} else { + console.log('getSystemRingtoneUri fail: ' + uri); +} +``` + + +## systemSoundManager.getSystemRingtonePlayer + +getSystemRingtonePlayer(context: Context, type: RingtoneType, callback: AsyncCallback): void8+ + +Obtains the ringtone player. This method uses an asynchronous callback to return the result. + +**Parameters** + +| Name | Type | Mandatory | Description | +| :------- | :------------------------------ | :-------- | :---------------------------------------- | +| context | Context | Yes | Current application context. | +| type | RingtoneType | Yes | Ringtone type to be obtained. | +| callback | AsyncCallback) | Yes | Ringtone player maintained in the system. | +| | | | | + +**Return value** + +None + +**Example** + +``` +systemSoundManager.getSystemRingtonePlayer(null, audio.RingtoneType.RINGTONE_TYPE_DEFAULT, (err, ringtonePlayer)=>{ + if (err) { + console.err('getSystemRingtonePlayer failed'); + } else { + console.log('getSystemRingtonePlayer success: '); + } +}) +``` + + +## systemSoundManager.getSystemRingtonePlayer + +getSystemRingtonePlayer(context: Context, type: RingtoneType): Promise8+ + +Obtains the ringtone player. This method uses a promise to return the result. + +**Parameters** + +None + +**Return value** + +| Type | Description | +| :----------------------- | :--------------------------------------- | +| Promise | Promise used return the ringtone player. | + +**Example** + +``` +let ringtonePlayer = await systemSoundManager.getSystemRingtoneUri(null, audio.RingtoneType.RINGTONE_TYPE_DEFAULT); +``` + + +## systemSoundManager.setSystemNotificationUri + +setSystemNotificationUri(context: Context, uri: string, callback: AsyncCallback): void8+ + +Sets the system notification URI. This method uses an asynchronous callback to return the result. + +**Parameters** + +| Name | Type | Mandatory | Description | +| :------- | :------------------- | :-------- | :---------------------------------- | +| context | Context | Yes | Current application context. | +| uri | string | Yes | System notification URI to be set. | +| callback | AsyncCallback | Yes | Callback used to return the result. | +| | | | | + +**Return value** + +None + +**Example** + +``` +systemSoundManager.setSystemNotificationUri(null, '/data/media/Notification.wav'), (err)=> { + if (err) { + console.error('Failed to setSystemNotificationUri'); + } else { + console.log('Callback invoked to indicate a successful system notification URI setting.'); + } +}) +``` + + +## systemSoundManager.setSystemNotificationUri + +setSystemNotificationUri(context: Context, uri: string): Promise8+ + +Sets the system notification URI. This method uses a promise to return the result. + +**Parameters** + +| Name | Type | Mandatory | Description | +| :------ | :------ | :-------- | :--------------------------------- | +| context | Context | Yes | Current application context. | +| uri | string | Yes | System notification URI to be set. | +| | | | | + +**Return value** + +| Type | Description | +| :------------- | :--------------------------------- | +| Promise | Promise used to return the result. | + +**Example** + +``` +await systemSoundManager.setSystemNotificationUri(null, '/data/media/Notification.wav'); +``` + + +## systemSoundManager.getSystemNotificationUri + +getSystemNotificationUri(context: Context, callback: AsyncCallback): void8+ + +Obtains the system notification URI. This method uses an asynchronous callback to return the result. + +**Parameters** + +| Name | Type | Mandatory | Description | +| :------- | :--------------------- | :-------- | :--------------------------------------------------- | +| context | Context | Yes | Current application context. | +| callback | AsyncCallback | Yes | Callback used to return the system notification URI. | +| | | | | + +**Return value** + +None + +**Example** + +``` +systemSoundManager.getSystemNotificationUri(null, (err, notificationUri)=>{ + if (err) { + console.err('getSystemNotificationUri failed'); + } else { + console.log('getSystemNotificationUri success: ' + notificationUri); + } +}) +``` + + +## systemSoundManager.getSystemNotificationUri + +getSystemNotificationUri(context: Context): Promise8+ + +Obtains the system notification URI. This method uses a promise to return the result. + +**Parameters** + +None + +**Return value** + +| Type | Description | +| :--------------- | :-------------------------------------------------- | +| Promise | Promise used to return the system notification URI. | + +**Example** + +``` +let notificationUri = await systemSoundManager.getSystemNotificationUri(null); +console.log('getSystemNotificationUri : ' + uri); +``` + + +## systemSoundManager.setSystemAlarmUri + +setSystemAlarmUri(context: Context, uri: string, callback: AsyncCallback): void8+ + +Sets the system alarm URI. This method uses an asynchronous callback to return the result. + +**Parameters** + +| Name | Type | Mandatory | Description | +| :------- | :------------------- | :-------- | :---------------------------------- | +| context | Context | Yes | Current application context. | +| uri | string | Yes | System alarm URI to be set. | +| callback | AsyncCallback | Yes | Callback used to return the result. | +| | | | | + +**Return value** + +None + +**Example** + +``` +systemSoundManager.setSystemAlarmUri(null, '/data/media/Alarm.wav'), (err)=> { + if (err) { + console.error('Failed to setSystemAlarmUri'); + } else { + console.log('Callback invoked to indicate a successful system alarm URI setting.'); + } +}) +``` + + +## systemSoundManager.setSystemAlarmUri + +setSystemAlarmUri(context: Context, uri: string): Promise8+ + +Sets the system alarm URI. This method uses a promise to return the result. + +**Parameters** + +| Name | Type | Mandatory | Description | +| :------ | :------ | :-------- | :--------------------------- | +| context | Context | Yes | Current application context. | +| uri | string | Yes | System alarm URI to be set. | +| | | | | + +**Return value** + +| Type | Description | +| :------------- | :--------------------------------- | +| Promise | Promise used to return the result. | + +**Example** + +``` +await systemSoundManager.setSystemAlarmUri(null, '/data/media/Alarm.wav'); +``` + + +## systemSoundManager.getSystemAlarmUri + +getSystemAlarmUri(context: Context, callback: AsyncCallback): void8+ + +Obtains the system alarm URI. This method uses an asynchronous callback to return the result. + +**Parameters** + +| Name | Type | Mandatory | Description | +| :------- | :--------------------- | :-------- | :-------------------------------------------- | +| context | Context | Yes | Current application context. | +| callback | AsyncCallback | Yes | Callback used to return the system alarm URI. | +| | | | | + +**Return value** + +None + +**Example** + +``` +systemSoundManager.getSystemAlarmUri(null, (err, alarmUri)=>{ + if (err) { + console.err('getSystemAlarmUri failed'); + } else { + console.log('getSystemAlarmUri success: ' + alarmUri); + } +}) +``` + + +## systemSoundManager.getSystemAlarmUri + +getSystemAlarmUri(context: Context): Promise8+ + +Obtains the system alarm URI. This method uses a promise to return the result. + +**Parameters** + +None + +**Return value** + +| Type | Description | +| :--------------- | :------------------------------------------- | +| Promise | Promise used to return the system alarm URI. | + +**Example** + +``` +let alarmUri = await systemSoundManager.getSystemAlarmUri(null); +console.log('getSystemAlarmUri success: ' + alarmUri); +``` + + +# RingtonePlayer + +## ringtonePlayer.state + +readonly state: AudioState 8+ + +Defines the current ringtone player state. + +| Name | Type | Readable | Writable | Description | +| :---- | :--------- | :------- | :------- | :--------------------- | +| state | AudioState | Yes | No | Ringtone player state. | + +**Example** + +``` +systemSoundManager.getSystemRingtonePlayer(null, audio.RingtoneType.RINGTONE_TYPE_DEFAULT, (err, ringtonePlayer)=>{ + if (err) { + console.err('getSystemRingtonePlayer failed'); + return; + } else { + console.log('getSystemRingtonePlayer success'); + } +}); + +var state = ringtonePlayer.state; +``` + + +## ringtonePlayer.getTitle + +getTitle(callback: AsyncCallback): void8+ + +Obtains the title of the ringtone. This method uses an asynchronous callback to return the result. + +**Parameters** +| Name | Type | Mandatory | Description | +| :------- | :--------------------- | :-------- | :------------------------------------------------- | +| callback | AsyncCallback | Yes | Callback used to return the title of the ringtone. | +| | | | | + +**Return value** + +None + +**Example** + +``` +systemSoundManager.getSystemRingtonePlayer(null, audio.RingtoneType.RINGTONE_TYPE_DEFAULT, (err, ringtonePlayer)=>{ + if (err) { + console.err('getSystemRingtonePlayer failed'); + return; + } else { + console.log('getSystemRingtonePlayer success'); + } +}); + +ringtonePlayer.getTitle((err, title)=>{ + if (err) { + console.err('getTitle failed'); + } else { + console.log('getTitle success: ' + title); + } +}) +``` + + +## ringtonePlayer.getTitle + +getTitle(): Promise8+ + +Obtains the title of the ringtone. This method uses a promise to return the result. + +**Parameters** + +None + +**Return value** + +| Type | Description | +| :--------------- | :------------------------------------------------ | +| Promise | Promise used to return the title of the ringtone. | + +**Example** + +``` +let ringtonePlayer = await systemSoundManager.getSystemRingtoneUri(null, audio.RingtoneType.RINGTONE_TYPE_DEFAULT); +let title = await ringtonePlayer.getTitle(); +``` + + +## ringtonePlayer.getAudioRendererInfo + +getAudioRendererInfo(callback: AsyncCallback): void8+ + +Obtains the audio renderer information. This method uses an asynchronous callback to return the result. + +**Parameters** + +| Name | Type | Mandatory | Description | +| :------- | :-------------------------------- | :-------- | :------------------------------------------------------ | +| callback | AsyncCallback | Yes | Callback used to return the audio renderer information. | +| | | | | + +**Return value** + +None + +**Example** + +``` +systemSoundManager.getSystemRingtonePlayer(null, audio.RingtoneType.RINGTONE_TYPE_DEFAULT, (err, ringtonePlayer)=>{ + if (err) { + console.err('getSystemRingtonePlayer failed'); + return; + } else { + console.log('getSystemRingtonePlayer success: '); + } +}); + +ringtonePlayer.getAudioRendererInfo((err, rendererInfo)=>{ + if (err) { + console.err('getAudioRendererInfo failed'); + } else { + console.log('getAudioRendererInfo success'); + } +}); +``` + + +## ringtonePlayer.getAudioRendererInfo + +getAudioRendererInfo(): Promise8+ + +Obtains the audio renderer information. This method uses a promise to return the result. + +**Parameters** + +None + +**Return value** + +| Type | Description | +| :-------------------------- | :----------------------------------------------------- | +| Promise | Promise used to return the audio renderer information. | + +**Example** + +``` +let ringtonePlayer = await systemSoundManager.getSystemRingtoneUri(null, audio.RingtoneType.RINGTONE_TYPE_DEFAULT); +let rendererInfo = await ringtonePlayer.getAudioRendererInfo(); +``` + + +## ringtonePlayer.configure + +configure(options: RingtoneOptions, callback: AsyncCallback): void8+ + +Configures ringtone options. This method uses an asynchronous callback to return the result. + +**Parameters** + +| Name | Type | Mandatory | Description | +| :------- | :------------------- | :-------- | :---------------------------------- | +| options | RingtoneOptions | Yes | Ringtone options. | +| callback | AsyncCallback | Yes | Callback used to return the result. | +| | | | | + +**Return value** + +None + +**Example** + +``` +systemSoundManager.getSystemRingtonePlayer(null, audio.RingtoneType.RINGTONE_TYPE_DEFAULT, (err, ringtonePlayer)=>{ + if (err) { + console.err('getSystemRingtonePlayer failed'); + return; + } else { + console.log('getSystemRingtonePlayer success: '); + } +}); + +let ringtoneOptions = { + volume: 1, + loop: false +}; + +ringtonePlayer.configure(ringtoneOptions, (err)=> { + if (err) { + console.error('Failed to configure ringtone options'); + } else { + console.log('Callback invoked to indicate a successful ringtone options configuration.'); + } +}) +``` + + +## ringtonePlayer.configure + +configure(options: RingtoneOptions): Promise8+ + +Configures ringtone options. This method uses a promise to return the result. + +**Parameters** + +| Name | Type | Mandatory | Description | +| :------ | :-------------- | :-------- | :---------------- | +| options | RingtoneOptions | Yes | Ringtone options. | +| | | | | + +**Return value** + +| Type | Description | +| :------------- | :--------------------------------- | +| Promise | Promise used to return the result. | + +**Example** + +``` +let ringtonePlayer = await systemSoundManager.getSystemRingtoneUri(null, audio.RingtoneType.RINGTONE_TYPE_DEFAULT); +let ringtoneOptions = { + volume: 1, + loop: false +}; + +await ringtonePlayer.configure(ringtoneOptions); +``` + + +## ringtonePlayer.start + +start(callback: AsyncCallback): void8+ + +Starts playing ringtone. This method uses a callback to return the result. + +**Parameters** + +| Name | Type | Mandatory | Description | +| :------- | :------------------- | :-------- | :---------------------------------- | +| callback | AsyncCallback | Yes | Callback used to return the result. | +| | | | | + +**Return value** + +None + +**Example** + +``` +ringtonePlayer.start((err)=> { + if (err) { + console.error('Failed to start playing ringtone'); + } else { + console.log('Ringtone start playing successfully.'); + } +}) +``` + + +## ringtonePlayer.start + +start(): Promise8+ + +Starts playing ringtone. This method uses a promise to return the result. + +**Parameters** + +None + +**Return value** + +| Type | Description | +| :------------- | :--------------------------------- | +| Promise | Promise used to return the result. | + +**Example** + +``` +await ringtonePlayer.start(); +``` + + +## ringtonePlayer.stop + +stop(callback: AsyncCallback): void8+ + +Stops playing ringtone. This method uses a callback to return the result. + +**Parameters** + +| Name | Type | Mandatory | Description | +| :------- | :------------------- | :-------- | :---------------------------------- | +| callback | AsyncCallback | Yes | Callback used to return the result. | +| | | | | + +**Return value** + +None + +**Example** + +``` +ringtonePlayer.stop((err)=> { + if (err) { + console.error('Failed to stop playing ringtone'); + } else { + console.log('Ringtone stop playing successfully.'); + } +}) +``` + + +## ringtonePlayer.stop + +stop(): Promise8+ + +Stops playing ringtone. This method uses a promise to return the result. + +**Parameters** + +None + +**Return value** + +| Type | Description | +| :------------- | :--------------------------------- | +| Promise | Promise used to return the result. | + +**Example** + +``` +await ringtonePlayer.stop(); +``` + + +## ringtonePlayer.release + +release(callback: AsyncCallback): void8+ + +Releases ringtone player resources. This method uses a callback to return the result. + +**Parameters** + +| Name | Type | Mandatory | Description | +| :------- | :------------------- | :-------- | :---------------------------------- | +| callback | AsyncCallback | Yes | Callback used to return the result. | +| | | | | + +**Return value** + +None + +**Example** + +``` +ringtonePlayer.release((err)=> { + if (err) { + console.error('Failed to release ringtone player resource'); + } else { + console.log('Release ringtone player resource successfully.'); + } +}) +``` + + +## ringtonePlayer.release + +release(): Promise8+ + +Releases ringtone player resource. This method uses a promise to return the result. + +**Parameters** + +None + +**Return value** + +| Type | Description | +| :------------- | :--------------------------------- | +| Promise | Promise used to return the result. | + +**Example** + +``` +await ringtonePlayer.release(); +```