# Audio
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```
import audio from '@ohos.multimedia.audio';
```
## Required Permissions
None
## audioManager
getAudioManager\(\): AudioManager
Obtains an **AudioManager** instance.
**System capabilities**: SystemCapability.Multimedia.Audio.Core
**Return value**
**Example**
```
var audioManager = audio.getAudioManager();
```
## audioRenderer
createAudioRenderer(options: AudioRendererOptions): AudioRenderer
Obtains an **AudioRenderer** instance.
**System capabilities**: SystemCapability.Multimedia.Audio.Renderer
**Parameters**
| Name | Type | Mandatory | Description |
| :--------- | :------------------- | :-------- | :---------------------- |
| options | AudioRendererOptions | Yes | Renderer configurations |
**Return value**
| Type | Description |
| ------------- | --------------------- |
| AudioRenderer | AudioRenderer object. |
**Example**
```
var audioStreamInfo = {
samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100,
channels: audio.AudioChannel.CHANNEL_1,
sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
}
var audioRendererInfo = {
content: audio.ContentType.CONTENT_TYPE_SPEECH,
usage: audio.StreamUsage.STREAM_USAGE_VOICE_COMMUNICATION,
rendererFlags: 1
}
var audioRendererOptions = {
streamInfo: audioStreamInfo,
rendererInfo: audioRendererInfo
}
let audioRenderer = await audio.createAudioRenderer(audioRendererOptions);
```
## 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.
Name
|
Default Value
|
Description
|
VOICE_CALL
|
0
|
Audio stream for voice calls. System capabilities: SystemCapability.Multimedia.Audio.Volume
|
RINGTONE
|
2
|
Audio stream for ringtones. System capabilities: SystemCapability.Multimedia.Audio.Volume
|
MEDIA
|
3
|
Audio stream for media purpose. System capabilities: SystemCapability.Multimedia.Audio.Volume
|
VOICE_ASSISTANT
|
9
|
Audio stream for voice assistant. System capabilities: SystemCapability.Multimedia.Audio.Volume
|
## DeviceFlag
Enumerates audio device flags.
Name
|
Default Value
|
Description
|
OUTPUT_DEVICES_FLAG
|
1
|
Output device. System capabilities: SystemCapability.Multimedia.Audio.Device
|
INPUT_DEVICES_FLAG
|
2
|
Input device. System capabilities: SystemCapability.Multimedia.Audio.Device
|
ALL_DEVICES_FLAG
|
3
|
All devices. System capabilities: SystemCapability.Multimedia.Audio.Device
|
## DeviceRole
Enumerates audio device roles.
Name
|
Default Value
|
Description
|
INPUT_DEVICE
|
1
|
Input role. System capabilities: SystemCapability.Multimedia.Audio.Device
|
OUTPUT_DEVICE
|
2
|
Output role. System capabilities: SystemCapability.Multimedia.Audio.Device
|
## DeviceType
Enumerates audio device types.
Name
|
Default Value
|
Description
|
INVALID
|
0
|
Invalid device. System capabilities: SystemCapability.Multimedia.Audio.Device
|
SPEAKER
|
2
|
Speaker. System capabilities: SystemCapability.Multimedia.Audio.Device
|
WIRED_HEADSET
|
3
|
Wired headset. System capabilities: SystemCapability.Multimedia.Audio.Device
|
BLUETOOTH_SCO
|
7
|
Bluetooth device using the synchronous connection oriented (SCO) link. System capabilities: SystemCapability.Multimedia.Audio.Device
|
BLUETOOTH_A2DP
|
8
|
Bluetooth device using the advanced audio distribution profile (A2DP). System capabilities: SystemCapability.Multimedia.Audio.Device
|
MIC
|
15
|
Microphone. System capabilities: SystemCapability.Multimedia.Audio.Device
|
## ActiveDeviceType
Enumerates the active device types.
| Name | Default Value | Default Value |
| ------------- | ------ | ------------------------------------------------------------ |
| SPEAKER | 2 | Speaker.
**System capabilities:** SystemCapability.Multimedia.Audio.Device |
| BLUETOOTH_SCO | 7 | Bluetooth device using the SCO link.
**System capabilities:** SystemCapability.Multimedia.Audio.Device |
## AudioRingMode
Enumerates ringer modes.
Name
|
Default Value
|
Description
|
RINGER_MODE_SILENT
|
0
|
Silence mode. System capabilities: SystemCapability.Multimedia.Audio.Communication
|
RINGER_MODE_VIBRATE
|
1
|
Vibration mode. System capabilities: SystemCapability.Multimedia.Audio.Communication
|
RINGER_MODE_NORMAL
|
2
|
Normal mode. System capabilities: SystemCapability.Multimedia.Audio.Communication
|
## AudioSampleFormat8+
Enumerates the audio sample formats.
| Name | Default Value | Description |
| :-------------------- | :------------ | :----------------------------------------------------------------------------------------------------- |
| SAMPLE_FORMAT_INVALID | -1 | Invalid format.
System capabilities: SystemCapability.Multimedia.Audio.Core |
| SAMPLE_FORMAT_U8 | 0 | Unsigned 8 bit integer.
System capabilities: SystemCapability.Multimedia.Audio.Core |
| SAMPLE_FORMAT_S16LE | 1 | Signed 16 bit integer, little endian.
System capabilities: SystemCapability.Multimedia.Audio.Core |
| SAMPLE_FORMAT_S24LE | 2 | Signed 24 bit integer, little endian.
System capabilities: SystemCapability.Multimedia.Audio.Core |
| SAMPLE_FORMAT_S32LE | 3 | Signed 32 bit integer, little endian.
System capabilities: SystemCapability.Multimedia.Audio.Core |
## AudioChannel8+
Enumerates the audio channels.
| Name | Default Value | Description |
| :----- | :------------ | :-------------------------------------------------------------------------------- |
| CHANNEL_1 | 0x1 << 0 | Channel count 1.
System capabilities: SystemCapability.Multimedia.Audio.Core |
| CHANNEL_2 | 0x1 << 1 | Channel count 2.
System capabilities: SystemCapability.Multimedia.Audio.Core |
## AudioSamplingRate8+
Enumerates the audio sampling rates.
| Name | Default Value | Description |
| :---------------- | :------------ | :------------------------------------------------------------------------------------ |
| SAMPLE_RATE_8000 | 8000 | Sampling rate 8000.
System capabilities: SystemCapability.Multimedia.Audio.Core |
| SAMPLE_RATE_11025 | 11025 | Sampling rate 11025.
System capabilities: SystemCapability.Multimedia.Audio.Core |
| SAMPLE_RATE_12000 | 12000 | Sampling rate 12000.
System capabilities: SystemCapability.Multimedia.Audio.Core |
| SAMPLE_RATE_16000 | 16000 | Sampling rate 16000.
System capabilities: SystemCapability.Multimedia.Audio.Core |
| SAMPLE_RATE_22050 | 22050 | Sampling rate 22050.
System capabilities: SystemCapability.Multimedia.Audio.Core |
| SAMPLE_RATE_24000 | 24000 | Sampling rate 24000.
System capabilities: SystemCapability.Multimedia.Audio.Core |
| SAMPLE_RATE_32000 | 32000 | Sampling rate 32000.
System capabilities: SystemCapability.Multimedia.Audio.Core |
| SAMPLE_RATE_44100 | 44100 | Sampling rate 44100.
System capabilities: SystemCapability.Multimedia.Audio.Core |
| SAMPLE_RATE_48000 | 48000 | Sampling rate 48000.
System capabilities: SystemCapability.Multimedia.Audio.Core |
| SAMPLE_RATE_64000 | 64000 | Sampling rate 64000.
System capabilities: SystemCapability.Multimedia.Audio.Core |
| SAMPLE_RATE_96000 | 96000 | Sampling rate 96000.
System capabilities: SystemCapability.Multimedia.Audio.Core |
## AudioEncodingType8+
Enumerates the audio encoding types.
| Name | Default Value | Description |
| :-------------------- | :------------- | :------------------------------------------------------------------------------- |
| ENCODING_TYPE_INVALID | -1 | Invalid.
System capabilities: SystemCapability.Multimedia.Audio.Core |
| ENCODING_TYPE_RAW | 0 | PCM encoding.
System capabilities: SystemCapability.Multimedia.Audio.Core |
## ContentType8+
Enumerates the content types.
| Name | Default Value | Description |
| :------------------------ | :------------ | :------------------------------------------------------------------------------------- |
| CONTENT_TYPE_UNKNOWN | 0 | Unknown content.
System capabilities: SystemCapability.Multimedia.Audio.Core |
| CONTENT_TYPE_SPEECH | 1 | Speech content.
System capabilities: SystemCapability.Multimedia.Audio.Core |
| CONTENT_TYPE_MUSIC | 2 | Music content.
System capabilities: SystemCapability.Multimedia.Audio.Core |
| CONTENT_TYPE_MOVIE | 3 | Movie content.
System capabilities: SystemCapability.Multimedia.Audio.Core |
| CONTENT_TYPE_SONIFICATION | 4 | Notification content.
System capabilities: SystemCapability.Multimedia.Audio.Core |
| CONTENT_TYPE_RINGTONE | 5 | Ringtone content.
System capabilities: SystemCapability.Multimedia.Audio.Core |
## StreamUsage8+
Enumerates the stream usage.
| Name | Default Value | Description |
| :--------------------------------- | :------------ | :----------------------------------------------------------------------------------------------- |
| STREAM_USAGE_UNKNOWN | 0 | Unknown usage.
System capabilities: SystemCapability.Multimedia.Audio.Core |
| STREAM_USAGE_MEDIA | 1 | Media usage.
System capabilities: SystemCapability.Multimedia.Audio.Core |
| STREAM_USAGE_VOICE_COMMUNICATION | 2 | Voice communication usage.
System capabilities: SystemCapability.Multimedia.Audio.Core |
| STREAM_USAGE_NOTIFICATION_RINGTONE | 3 | Notification or ringtone usage.
System capabilities: SystemCapability.Multimedia.Audio.Core |
## AudioState8+
Enumerates the audio states.
| Name | Default Value | Description |
| :------------- | :------------ | :------------------------- |
| STATE_INVALID | -1 | Invalid state.
System capabilities: SystemCapability.Multimedia.Audio.Core |
| STATE_NEW | 0 | Create New instance state.
System capabilities: SystemCapability.Multimedia.Audio.Core |
| STATE_PREPARED | 1 | Prepared state.
System capabilities: SystemCapability.Multimedia.Audio.Core |
| STATE_RUNNING | 2 | Running state.
System capabilities: SystemCapability.Multimedia.Audio.Core |
| STATE_STOPPED | 3 | Stopped state.
System capabilities: SystemCapability.Multimedia.Audio.Core |
| STATE_RELEASED | 4 | Released state.
System capabilities: SystemCapability.Multimedia.Audio.Core |
| STATE_PAUSED | 5 | Paused state.
System capabilities: SystemCapability.Multimedia.Audio.Core |
## AudioRendererRate8+
Enumerates the audio renderer rates.
| Name | Default Value | Description |
| :----------------- | :------------ | :-------------------------------------------------------------------------------- |
| RENDER_RATE_NORMAL | 0 | Normal rate.
System capabilities: SystemCapability.Multimedia.Audio.Renderer |
| RENDER_RATE_DOUBLE | 1 | Double rate.
System capabilities: SystemCapability.Multimedia.Audio.Renderer |
| RENDER_RATE_HALF | 2 | Half rate.
System capabilities: SystemCapability.Multimedia.Audio.Renderer |
## InterruptType8+
Enumerates the interrupt types.
| Name | Default Value | Description |
| :------------------- | :------------ | :-------------------------------------------------------------------------------------------------------- |
| INTERRUPT_TYPE_BEGIN | 1 | Audio playback interruption started.
System capabilities: SystemCapability.Multimedia.Audio.Renderer |
| INTERRUPT_TYPE_END | 2 | Audio playback interruption ended.
System capabilities: SystemCapability.Multimedia.Audio.Renderer |
## InterruptForceType8+
Enumerates the interrupt force types.
| Name | Default Value | Description |
| :-------------- | :------------ | :------------------------------------------------------------------------------------------------------------ |
| INTERRUPT_FORCE | 0 | Forced action taken by system.
System capabilities: SystemCapability.Multimedia.Audio.Renderer |
| INTERRUPT_SHARE | 1 | App can choose to take action or ignore.
System capabilities: SystemCapability.Multimedia.Audio.Renderer |
## InterruptHint8+
Enumerates the interrupt hints.
| Name | Default Value | Description |
| :-------------------- | :------------ | :---------------------------------------------------------------------------------------------- |
| INTERRUPT_HINT_NONE | 0 | None.
System capabilities: SystemCapability.Multimedia.Audio.Renderer |
| INTERRUPT_HINT_RESUME | 1 | Resume the playback.
System capabilities: SystemCapability.Multimedia.Audio.Renderer |
| INTERRUPT_HINT_PAUSE | 2 | Paused/Pause the playback.
System capabilities: SystemCapability.Multimedia.Audio.Renderer |
| INTERRUPT_HINT_STOP | 3 | Stopped/Stop the playback.
System capabilities: SystemCapability.Multimedia.Audio.Renderer |
| INTERRUPT_HINT_DUCK | 4 | Ducked the playback.
System capabilities: SystemCapability.Multimedia.Audio.Renderer |
| INTERRUPT_HINT_UNDUCK | 5 | Unducked the playback.
System capabilities: SystemCapability.Multimedia.Audio.Renderer |
## RingtoneType8+
Enumerates the ringtone types.
| Name | Default Value | Description |
| :--------------------- | :------------ | :-------------- |
| RINGTONE_TYPE_DEFAULT | 0 | Default type. |
| RINGTONE_TYPE_MULTISIM | 1 | Multi-SIM type. |
## AudioStreamInfo8+
Describes audio stream information.
**System capabilities**: SystemCapability.Multimedia.Audio.Core
**Parameters**
| Name | Type | Mandatory | Description |
| :------------ | :-------------------- | :-------- | :-------------------- |
| samplingRate | AudioSamplingRate | Yes | Sampling rate. |
| channels | AudioChannel | Yes | Audio channels. |
| sampleFormat | AudioSampleFormat | Yes | Audio sample format. |
| encodingType | AudioEncodingType | Yes | Audio encoding type. |
## AudioRendererInfo8+
Describes audio renderer information.
**System capabilities**: SystemCapability.Multimedia.Audio.Core
**Parameters**
| Name | Type | Mandatory | Description |
| :------------ | :---------- | :-------- | :-------------------- |
| contentType | ContentType | Yes | Content type. |
| 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 |
| :-------- | :----------------- | :-------- | :-------------------------------------------------------------------------- |
| 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.
**System capabilities**: SystemCapability.Multimedia.Audio.Volume
**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.
**System capabilities**: SystemCapability.Multimedia.Audio.Core
## audioManager.setVolume
setVolume\(volumeType: AudioVolumeType, volume: number, callback: AsyncCallback\): void
Sets the volume for a stream. This method uses an asynchronous callback to return the result.
**System capabilities**: SystemCapability.Multimedia.Audio.Volume
**Parameters**
Name
|
Type
|
Mandatory
|
Description
|
volumeType
|
AudioVolumeType
|
Yes
|
Audio stream type.
|
volume
|
number
|
Yes
|
Volume to set. The value range can be obtained by calling getMinVolume and getMaxVolume.
|
callback
|
AsyncCallback<void>
|
Yes
|
Callback used to return the result.
|
**Return value**
None
**Example**
```
audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10, (err)=>{
if (err) {
console.error('Failed to set the volume. ${err.message}');
return;
}
console.log('Callback invoked to indicate a successful volume setting.');
})
```
## audioManager.setVolume
setVolume\(volumeType: AudioVolumeType, volume: number\): Promise
Sets the volume for a stream. This method uses a promise to return the result.
**System capabilities**: SystemCapability.Multimedia.Audio.Volume
**Parameters**
Name
|
Type
|
Mandatory
|
Description
|
volumeType
|
AudioVolumeType
|
Yes
|
Audio stream type.
|
volume
|
number
|
Yes
|
Volume to set. The value range can be obtained by calling getMinVolume and getMaxVolume.
|
**Return value**
Type
|
Description
|
Promise<void>
|
Promise used to return the result.
|
**Example**
```
audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(()=>
console.log('Promise returned to indicate a successful volume setting.');
)
```
## audioManager.getVolume
getVolume\(volumeType: AudioVolumeType, callback: AsyncCallback\): void
Obtains the volume of a stream. This method uses an asynchronous callback to return the query result.
**System capabilities**: SystemCapability.Multimedia.Audio.Volume
**Parameters**
Name
|
Type
|
Mandatory
|
Description
|
volumeType
|
AudioVolumeType
|
Yes
|
Audio stream type.
|
callback
|
AsyncCallback<number>
|
Yes
|
Callback used to return the volume.
|
**Return value**
None
**Example**
```
audioManager.getVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
if (err) {
console.error('Failed to obtain the volume. ${err.message}');
return;
}
console.log('Callback invoked to indicate that the volume is obtained.');
})
```
## audioManager.getVolume
getVolume\(volumeType: AudioVolumeType\): Promise
Obtains the volume of a stream. This method uses a promise to return the query result.
**System capabilities**: SystemCapability.Multimedia.Audio.Volume
**Parameters**
Name
|
Type
|
Mandatory
|
Description
|
volumeType
|
AudioVolumeType
|
Yes
|
Audio stream type.
|
**Return value**
Type
|
Description
|
Promise<number>
|
Promise used to return the volume.
|
**Example**
```
audioManager.getVolume(audio.AudioVolumeType.MEDIA).then((value) =>
console.log('Promise returned to indicate that the volume is obtained.' + value);
)
```
## audioManager.getMinVolume
getMinVolume\(volumeType: AudioVolumeType, callback: AsyncCallback\): void
Obtains the minimum volume allowed for a stream. This method uses an asynchronous callback to return the query result.
**System capabilities**: SystemCapability.Multimedia.Audio.Volume
**Parameters**
Name
|
Type
|
Mandatory
|
Description
|
volumeType
|
AudioVolumeType
|
Yes
|
Audio stream type.
|
callback
|
AsyncCallback<number>
|
Yes
|
Callback used to return the minimum volume.
|
**Return value**
None
**Example**
```
audioManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
if (err) {
console.error('Failed to obtain the minimum volume. ${err.message}');
return;
}
console.log('Callback invoked to indicate that the minimum volume is obtained.' + value);
})
```
## audioManager.getMinVolume
getMinVolume\(volumeType: AudioVolumeType\): Promise
Obtains the minimum volume allowed for a stream. This method uses a promise to return the query result.
**System capabilities**: SystemCapability.Multimedia.Audio.Volume
**Parameters**
Name
|
Type
|
Mandatory
|
Description
|
volumeType
|
AudioVolumeType
|
Yes
|
Audio stream type.
|
**Return value**
Type
|
Description
|
Promise<number>
|
Promise used to return the minimum volume.
|
**Example**
```
audioManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value) =>
console.log('Promised returned to indicate that the minimum volume is obtained.' + value);
)
```
## audioManager.getMaxVolume
getMaxVolume\(volumeType: AudioVolumeType, callback: AsyncCallback\): void
Obtains the maximum volume allowed for a stream. This method uses an asynchronous callback to return the query result.
**System capabilities**: SystemCapability.Multimedia.Audio.Volume
**Parameters**
Name
|
Type
|
Mandatory
|
Description
|
volumeType
|
AudioVolumeType
|
Yes
|
Audio stream type.
|
callback
|
AsyncCallback<number>
|
Yes
|
Callback used to return the maximum volume.
|
**Return value**
None
**Example**
```
audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
if (err) {
console.error('Failed to obtain the maximum volume. ${err.message}');
return;
}
console.log('Callback invoked to indicate that the maximum volume is obtained.' + value);
})
```
## audioManager.getMaxVolume
getMaxVolume\(volumeType: AudioVolumeType\): Promise
Obtains the maximum volume allowed for a stream. This method uses a promise to return the query result.
**System capabilities**: SystemCapability.Multimedia.Audio.Volume
**Parameters**
Name
|
Type
|
Mandatory
|
Description
|
volumeType
|
AudioVolumeType
|
Yes
|
Audio stream type.
|
**Return value**
Type
|
Description
|
Promise<number>
|
Promise used to return the maximum volume.
|
**Example**
```
audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data)=>
console.log('Promised returned to indicate that the maximum volume is obtained.');
)
```
## audioManager.mute
mute\(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback\): void
Mutes a stream. This method uses an asynchronous callback to return the result.
**System capabilities**: SystemCapability.Multimedia.Audio.Volume
**Parameters**
Name
|
Type
|
Mandatory
|
Description
|
volumeType
|
AudioVolumeType
|
Yes
|
Audio stream type.
|
mute
|
boolean
|
Yes
|
Mute status to set. The value true means to mute the stream, and false means the opposite.
|
callback
|
AsyncCallback<void>
|
Yes
|
Callback used to return the result.
|
**Return value**
None
**Example**
```
audioManager.mute(audio.AudioVolumeType.MEDIA, true, (err) => {
if (err) {
console.error('Failed to mute the stream. ${err.message}');
return;
}
console.log('Callback invoked to indicate that the stream is muted.');
})
```
## audioManager.mute
mute\(volumeType: AudioVolumeType, mute: boolean\): Promise
Mutes a stream. This method uses a promise to return the result.
**System capabilities**: SystemCapability.Multimedia.Audio.Volume
**Parameters**
Name
|
Type
|
Mandatory
|
Description
|
volumeType
|
AudioVolumeType
|
Yes
|
Audio stream type.
|
mute
|
boolean
|
Yes
|
Mute status to set. The value true means to mute the stream, and false means the opposite.
|
**Return value**
Type
|
Description
|
Promise<void>
|
Promise used to return the result.
|
**Example**
```
audioManager.mute(audio.AudioVolumeType.MEDIA, true).then(() =>
console.log('Promise returned to indicate that the stream is muted.');
)
```
## audioManager.isMute
isMute\(volumeType: AudioVolumeType, callback: AsyncCallback\): void
Checks whether a stream is muted. This method uses an asynchronous callback to return the query result.
**System capabilities**: SystemCapability.Multimedia.Audio.Volume
**Parameters**
Name
|
Type
|
Mandatory
|
Description
|
volumeType
|
AudioVolumeType
|
Yes
|
Audio stream type.
|
callback
|
AsyncCallback<boolean>
|
Yes
|
Callback used to return the mute status of the stream. The value true means that the stream is muted, and false means the opposite.
|
**Return value**
None
**Example**
```
audioManager.isMute(audio.AudioVolumeType.MEDIA, (err, value) => {
if (err) {
console.error('Failed to obtain the mute status. ${err.message}');
return;
}
console.log('Callback invoked to indicate that the mute status of the stream is obtained.' + value);
})
```
## audioManager.isMute
isMute\(volumeType: AudioVolumeType\): Promise
Checks whether a stream is muted. This method uses a promise to return the result.
**System capabilities**: SystemCapability.Multimedia.Audio.Volume
**Parameters**
Name
|
Type
|
Mandatory
|
Description
|
volumeType
|
AudioVolumeType
|
Yes
|
Audio stream type.
|
**Return value**
Type
|
Description
|
Promise<boolean>
|
Promise used to return the mute status of the stream. The value true means that the stream is muted, and false means the opposite.
|
**Example**
```
audioManager.isMute(audio.AudioVolumeType.MEDIA).then((value) =>
console.log('Promise returned to indicate that the mute status of the stream is obtained.' + value);
)
```
## audioManager.isActive
isActive\(volumeType: AudioVolumeType, callback: AsyncCallback\)
Checks whether a stream is active. This method uses an asynchronous callback to return the query result.
**System capabilities**: SystemCapability.Multimedia.Audio.Volume
**Parameters**
Name
|
Type
|
Mandatory
|
Description
|
volumeType
|
AudioVolumeType
|
Yes
|
Audio stream type.
|
callback
|
AsyncCallback<boolean>
|
Yes
|
Callback used to return the active status of the stream. The value true means that the stream is active, and false means the opposite.
|
**Return value**
None
**Example**
```
audioManager.isActive(audio.AudioVolumeType.MEDIA, (err, value) => {
if (err) {
console.error('Failed to obtain the active status of the stream. ${err.message}');
return;
}
console.log('Callback invoked to indicate that the active status of the stream is obtained.' + value);
})
```
## audioManager.isActive
isActive\(volumeType: AudioVolumeType\): Promise
Checks whether a stream is active. This method uses a promise to return the query result.
**System capabilities**: SystemCapability.Multimedia.Audio.Volume
**Parameters**
Name
|
Type
|
Mandatory
|
Description
|
volumeType
|
AudioVolumeType
|
Yes
|
Audio stream type.
|
**Return value**
Type
|
Description
|
Promise<boolean>
|
Promise used to return the active status of the stream. The value true means that the stream is active, and false means the opposite.
|
**Example**
```
audioManager.isActive(audio.AudioVolumeType.MEDIA).then((value) =>
console.log('Promise returned to indicate that the active status of the stream is obtained.' + value);
)
```
## audioManager.setRingerMode
setRingerMode\(mode: AudioRingMode, callback: AsyncCallback\): void
Sets the ringer mode. This method uses an asynchronous callback to return the result.
**System capabilities**: SystemCapability.Multimedia.Audio.Communication
**Parameters**
Name
|
Type
|
Mandatory
|
Description
|
mode
|
AudioRingMode
|
Yes
|
Ringer mode.
|
callback
|
AsyncCallback<void>
|
Yes
|
Callback used to return the result.
|
**Return value**
None
**Example**
```
audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL, (err) => {
if (err) {
console.error('Failed to set the ringer mode.​ ${err.message}');
return;
}
console.log('Callback invoked to indicate a successful setting of the ringer mode.');
})
```
## audioManager.setRingerMode
setRingerMode\(mode: AudioRingMode\): Promise
Sets the ringer mode. This method uses a promise to return the result.
**System capabilities**: SystemCapability.Multimedia.Audio.Communication
**Parameters**
Name
|
Type
|
Mandatory
|
Description
|
mode
|
AudioRingMode
|
Yes
|
Ringer mode.
|
**Return value**
Type
|
Description
|
Promise<void>
|
Promise used to return the result.
|
**Example**
```
audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() =>
console.log('Promise returned to indicate a successful setting of the ringer mode.');
)
```
## audioManager.getRingerMode
getRingerMode\(callback: AsyncCallback\): void
Obtains the ringer mode. This method uses an asynchronous callback to return the query result.
**System capabilities**: SystemCapability.Multimedia.Audio.Communication
**Parameters**
Name
|
Type
|
Mandatory
|
Description
|
callback
|
AsyncCallback<AudioRingMode>
|
Yes
|
Callback used to return the ringer mode.
|
**Return value**
None
**Example**
```
audioManager.getRingerMode((err, value) => {
if (err) {
console.error('Failed to obtain the ringer mode.​ ${err.message}');
return;
}
console.log('Callback invoked to indicate that the ringer mode is obtained.' + value);
})
```
## audioManager.getRingerMode
getRingerMode\(\): Promise
Obtains the ringer mode. This method uses a promise to return the query result.
**System capabilities**: SystemCapability.Multimedia.Audio.Communication
**Parameters**
None
**Return value**
Type
|
Description
|
Promise<AudioRingMode>
|
Promise used to return the ringer mode.
|
**Example**
```
audioManager.getRingerMode().then((value) =>
console.log('Promise returned to indicate that the ringer mode is obtained.' + value);
)
```
## audioManager.setAudioParameter
setAudioParameter\(key: string, value: string, callback: AsyncCallback\): void
Sets an audio parameter. This method uses an asynchronous callback to return the result.
**System capabilities**: SystemCapability.Multimedia.Audio.Core
**Parameters**
Name
|
Type
|
Mandatory
|
Description
|
key
|
string
|
Yes
|
Key of the audio parameter to set.
|
value
|
string
|
Yes
|
Value of the audio parameter to set.
|
callback
|
AsyncCallback<void>
|
Yes
|
Callback used to return the result.
|
**Return value**
None
**Example**
```
audioManager.setAudioParameter('PBits per sample', '8 bit', (err) => {
if (err) {
console.error('Failed to set the audio parameter. ${err.message}');
return;
}
console.log('Callback invoked to indicate a successful setting of the audio parameter.');
})
```
## audioManager.setAudioParameter
setAudioParameter\(key: string, value: string\): Promise
Sets an audio parameter. This method uses a promise to return the result.
**System capabilities**: SystemCapability.Multimedia.Audio.Core
**Parameters**
Name
|
Type
|
Mandatory
|
Description
|
key
|
string
|
Yes
|
Key of the audio parameter to set.
|
value
|
string
|
Yes
|
Value of the audio parameter to set.
|
**Return value**
Type
|
Description
|
Promise<void>
|
Promise used to return the result.
|
**Example**
```
audioManager.setAudioParameter('PBits per sample', '8 bit').then(() =>
console.log('Promise returned to indicate a successful setting of the audio parameter.');
)
```
## audioManager.getAudioParameter
getAudioParameter\(key: string, callback: AsyncCallback\)
Obtains the value of an audio parameter. This method uses an asynchronous callback to return the query result.
**System capabilities**: SystemCapability.Multimedia.Audio.Core
**Parameters**
Name
|
Type
|
Mandatory
|
Description
|
key
|
string
|
Yes
|
Key of the audio parameter whose value is to be obtained.
|
callback
|
AsyncCallback<string>
|
Yes
|
Callback used to return the value of the audio parameter.
|
**Return value**
None
**Example**
```
audioManager.getAudioParameter('PBits per sample', (err, value) => {
if (err) {
console.error('Failed to obtain the value of the audio parameter. ${err.message}');
return;
}
console.log('Callback invoked to indicate that the value of the audio parameter is obtained.' + value);
})
```
## audioManager.getAudioParameter
getAudioParameter\(key: string\): Promise
Obtains the value of an audio parameter. This method uses a promise to return the query result.
**System capabilities**: SystemCapability.Multimedia.Audio.Core
**Parameters**
Name
|
Type
|
Mandatory
|
Description
|
key
|
string
|
Yes
|
Key of the audio parameter whose value is to be obtained.
|
**Return value**
Type
|
Description
|
Promise<string>
|
Promise used to return the value of the audio parameter.
|
**Example**
```
audioManager.getAudioParameter('PBits per sample').then((value) =>
console.log('Promise returned to indicate that the value of the audio parameter is obtained.' + value);
)
```
## audioManager.getDevices
getDevices\(deviceFlag: DeviceFlag, callback: AsyncCallback\): void
Obtains the audio devices with a specific flag. This method uses an asynchronous callback to return the query result.
**System capabilities**: SystemCapability.Multimedia.Audio.Device
**Parameters**
Name
|
Type
|
Mandatory
|
Description
|
deviceFlag
|
DeviceFlag
|
Yes
|
Audio device flag.
|
callback
|
AsyncCallback<AudioDeviceDescriptors>
|
Yes
|
Callback used to return the device list.
|
**Return value**
None
**Example**
```
audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err, value)=>{
if (err) {
console.error('Failed to obtain the device list. ${err.message}');
return;
}
console.log('Callback invoked to indicate that the device list is obtained.');
})
```
## audioManager.getDevices
getDevices\(deviceFlag: DeviceFlag\): Promise
Obtains the audio devices with a specific flag. This method uses a promise to return the query result.
**System capabilities**: SystemCapability.Multimedia.Audio.Device
**Parameters**
Name
|
Type
|
Mandatory
|
Description
|
deviceFlag
|
DeviceFlag
|
Yes
|
Audio device flag.
|
**Return value**
**Example**
```
audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data)=>
console.log('Promise returned to indicate that the device list is obtained.');
)
```
## audioManager.setDeviceActive
setDeviceActive\(deviceType: DeviceType, active: boolean, callback: AsyncCallback\): void
Sets a device to the active state. This method uses an asynchronous callback to return the result.
**System capabilities**: SystemCapability.Multimedia.Audio.Device
**Parameters**
Name
|
Type
|
Mandatory
|
Description
|
deviceType
|
DeviceType
|
Yes
|
Audio device type.
|
active
|
boolean
|
Yes
|
Active status to set. The value true means to set the device to the active status, and false means the opposite.
|
callback
|
AsyncCallback<void>
|
Yes
|
Callback used to return the result.
|
**Return value**
None
**Example**
```
audioManager.setDeviceActive(audio.DeviceType.SPEAKER, true, (err)=> {
if (err) {
console.error('Failed to set the active status of the device. ${err.message}');
return;
}
console.log('Callback invoked to indicate that the device is set to the active status.');
})
```
## audioManager.setDeviceActive
setDeviceActive\(deviceType: DeviceType, active: boolean\): Promise
Sets a device to the active state. This method uses a promise to return the result.
**System capabilities**: SystemCapability.Multimedia.Audio.Device
**Parameters**
Name
|
Type
|
Mandatory
|
Description
|
deviceType
|
DeviceType
|
Yes
|
Audio device type.
|
active
|
boolean
|
Yes
|
Active status to set. The value true means to set the device to the active status, and false means the opposite.
|
**Return value**
Type
|
Description
|
Promise<void>
|
Promise used to return the result.
|
**Example**
```
audioManager.setDeviceActive(audio.DeviceType.SPEAKER, true).then(()=>
console.log('Promise returned to indicate that the device is set to the active status.');
)
```
## audioManager.isDeviceActive
isDeviceActive\(deviceType: DeviceType, callback: AsyncCallback\): void
Checks whether a device is active. This method uses an asynchronous callback to return the query result.
**System capabilities**: SystemCapability.Multimedia.Audio.Device
**Parameters**
Name
|
Type
|
Mandatory
|
Description
|
deviceType
|
DeviceType
|
Yes
|
Audio device type.
|
callback
|
AsyncCallback<boolean>
|
Yes
|
Callback used to return the active status of the device.
|
**Return value**
None
**Example**
```
audioManager.isDeviceActive(audio.DeviceType.SPEAKER, (err, value) => {
if (err) {
console.error('Failed to obtain the active status of the device. ${err.message}');
return;
}
console.log('Callback invoked to indicate that the active status of the device is obtained.');
})
```
## audioManager.isDeviceActive
isDeviceActive\(deviceType: DeviceType\): Promise
Checks whether a device is active. This method uses a promise to return the query result.
**System capabilities**: SystemCapability.Multimedia.Audio.Device
**Parameters**
Name
|
Type
|
Mandatory
|
Description
|
deviceType
|
DeviceType
|
Yes
|
Audio device type.
|
**Return value**
Type
|
Description
|
Promise<boolean>
|
Promise used to return the active status of the device.
|
**Example**
```
audioManager.isDeviceActive(audio.DeviceType.SPEAKER).then((value) =>
console.log('Promise returned to indicate that the active status of the device is obtained.' + value);
)
```
## audioManager.setMicrophoneMute
setMicrophoneMute\(mute: boolean, callback: AsyncCallback\): void
Mutes or unmutes the microphone. This method uses an asynchronous callback to return the result.
**System capabilities**: SystemCapability.Multimedia.Audio.Device
**Parameters**
Name
|
Type
|
Mandatory
|
Description
|
mute
|
boolean
|
Yes
|
Mute status to set. The value true means to mute the microphone, and false means the opposite.
|
callback
|
AsyncCallback<void>
|
Yes
|
Callback used to return the result.
|
**Return value**
None
**Example**
```
audioManager.setMicrophoneMute(true, (err) => {
if (err) {
console.error('Failed to mute the microphone. ${err.message}');
return;
}
console.log('Callback invoked to indicate that the microphone is muted.');
})
```
## audioManager.setMicrophoneMute
setMicrophoneMute\(mute: boolean\): Promise
Mutes or unmutes the microphone. This method uses a promise to return the result.
**System capabilities**: SystemCapability.Multimedia.Audio.Device
**Parameters**
Name
|
Type
|
Mandatory
|
Description
|
mute
|
boolean
|
Yes
|
Mute status to set. The value true means to mute the microphone, and false means the opposite.
|
**Return value**
Type
|
Description
|
Promise<void>
|
Promise used to return the result.
|
**Example**
```
audioManager.setMicrophoneMute(true).then(() =>
console.log('Promise returned to indicate that the microphone is muted.');
)
```
## audioManager.isMicrophoneMute
isMicrophoneMute\(callback: AsyncCallback\): void
Checks whether the microphone is muted. This method uses an asynchronous callback to return the query result.
**System capabilities**: SystemCapability.Multimedia.Audio.Device
**Parameters**
Name
|
Type
|
Mandatory
|
Description
|
callback
|
AsyncCallback<boolean>
|
Yes
|
Callback used to return the mute status of the microphone. The value true means that the microphone is muted, and false means the opposite.
|
**Return value**
None
**Example**
```
audioManager.isMicrophoneMute((err, value) => {
if (err) {
console.error('Failed to obtain the mute status of the microphone. ${err.message}');
return;
}
console.log('Callback invoked to indicate that the mute status of the microphone is obtained.' + value);
})
```
## audioManager.isMicrophoneMute
isMicrophoneMute\(\): Promise
Checks whether the microphone is muted. This method uses a promise to return the query result.
**System capabilities**: SystemCapability.Multimedia.Audio.Device
**Parameters**
None
**Return value**
Type
|
Description
|
Promise<boolean>
|
Promise used to return the mute status of the microphone. The value true means that the microphone is muted, and false means the opposite.
|
**Example**
```
audioManager.isMicrophoneMute().then((value) =>
console.log('Promise returned to indicate that the mute status of the microphone is obtained.', + value);
)
```
## audioManager.on
on(type: 'volumeChange', callback: Callback): void8+
Listens for system volume change events. This method uses a callback to get volume change events.
**System capabilities**: SystemCapability.Multimedia.Audio.Volume
**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.
**System capabilities**: SystemCapability.Multimedia.Audio.Communication
**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.
**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
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.
**System capabilities**: SystemCapability.Multimedia.Audio.Renderer
## audioRenderer.state
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. |
**Example**
```
var state = audioRenderer.state;
```
## audioRenderer.getRendererInfo
getRendererInfo(callback: AsyncCallback): void8+
Gets 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**
None
**Example**
```
audioRenderer.getRendererInfo((err, rendererInfo)=>{
console.log('Renderer GetRendererInfo:');
console.log('Renderer content:' + rendererInfo.content);
console.log('Renderer usage:' + rendererInfo.usage);
console.log('Renderer flags:' + rendererInfo.rendererFlags);
})
```
## audioRenderer.getRendererInfo
getParams(): Promise8+
Gets 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**
None
**Return value**
| Type | Description |
| :---------------------------- | :----------------------------------------------- |
| Promise | Promise used to return the renderer information. |
**Example**
```
let rendererInfo = await audioRenderer.getRendererInfo();
console.log('Renderer GetRendererInfo:');
console.log('Renderer content:' + rendererInfo.content);
console.log('Renderer usage:' + rendererInfo.usage);
console.log('Renderer flags:' + rendererInfo.rendererFlags);
```
## audioRenderer.getStreamInfo
getStreamInfo(callback: AsyncCallback): void8+
Gets 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**
None
**Example**
```
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);
})
```
## audioRenderer.getStreamInfo
getStreamInfo(): Promise8+
Gets the renderer stream information. This method uses a promise to return the result.
**System capabilities**: SystemCapability.Multimedia.Audio.Renderer
**Parameters**
None
**Return value**
| Type | Description |
| :---------------------------- | :--------------------------------------------- |
| Promise | Promise used to return the stream information. |
**Example**
```
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);
```
## audioRenderer.start
start(callback: AsyncCallback): void8+
Starts the renderer. 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 result. |
| | | | |
**Return value**
None
**Example**
```
audioRenderer.start((err)=>{
if (err) {
console.error('Renderer start failed.');
} else {
console.info('Renderer start success.');
}
})
```
## audioRenderer.start
start(): Promise8+
Starts the renderer. This method uses a promise to return the result.
**System capabilities**: SystemCapability.Multimedia.Audio.Renderer
**Parameters**
None
**Return value**
| Type | Description |
| :------------- | :--------------------------------- |
| Promise | Promise used to return the result. |
**Example**
```
await audioRenderer.start();
```
## audioRenderer.pause
pause(callback: AsyncCallback): void8+
Pauses rendering. 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 result. |
| | | | |
**Return value**
None
**Example**
```
audioRenderer.pause((err)=>{
if (err) {
console.error('Renderer pause failed');
} else {
console.log('Renderer paused.');
}
})
```
## audioRenderer.pause
pause(): Promise8+
Pauses rendering. This method uses a promise to return the result.
**System capabilities**: SystemCapability.Multimedia.Audio.Renderer
**Parameters**
None
**Return value**
| Type | Description |
| :------------- | :--------------------------------- |
| Promise | Promise used to return the result. |
**Example**
```
await audioRenderer.pause();
```
## audioRenderer.drain
drain(callback: AsyncCallback): void8+
Drains the playback buffer. 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 result. |
| | | | |
**Return value**
None
**Example**
```
audioRenderer.drain((err)=>{
if (err) {
console.error('Renderer drain failed');
} else {
console.log('Renderer drained.');
}
})
```
## audioRenderer.drain
drain(): Promise8+
Drains the playback buffer. This method uses a promise to return the result.
**System capabilities**: SystemCapability.Multimedia.Audio.Renderer
**Parameters**
None
**Return value**
| Type | Description |
| :------------- | :--------------------------------- |
| Promise | Promise used to return the result. |
**Example**
```
await audioRenderer.drain();
```
## audioRenderer.stop
stop(callback: AsyncCallback): void8+
Stops rendering. 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 result. |
| | | | |
**Return value**
None
**Example**
```
audioRenderer.stop((err)=>{
if (err) {
console.error('Renderer stop failed');
} else {
console.log('Renderer stopped.');
}
})
```
## audioRenderer.stop
stop(): Promise8+
Stops rendering. This method uses a promise to return the result.
**System capabilities**: SystemCapability.Multimedia.Audio.Renderer
**Parameters**
None
**Return value**
| Type | Description |
| :------------- | :--------------------------------- |
| Promise | Promise used to return the result. |
**Example**
```
await audioRenderer.stop();
```
## audioRenderer.release
release(callback: AsyncCallback): void8+
Releases the renderer. 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 result. |
| | | | |
**Return value**
None
**Example**
```
audioRenderer.release((err)=>{
if (err) {
console.error('Renderer release failed');
} else {
console.log('Renderer released.');
}
})
```
## audioRenderer.release
release(): Promise8+
Releases the renderer. This method uses a promise to return the result.
**System capabilities**: SystemCapability.Multimedia.Audio.Renderer
**Parameters**
None
**Return value**
| Type | Description |
| :------------- | :--------------------------------- |
| Promise | Promise used to return the result. |
**Example**
```
await audioRenderer.release();
```
## audioRenderer.write
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 |
| :------- | :---------------------- | :-------- | :--------------------------------------------------------------------------------------------------- |
| 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.
**System capabilities**: SystemCapability.Multimedia.Audio.Renderer
**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.
**System capabilities**: SystemCapability.Multimedia.Audio.Renderer
**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.
**System capabilities**: SystemCapability.Multimedia.Audio.Renderer
**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.
**System capabilities**: SystemCapability.Multimedia.Audio.Renderer
**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.
**System capabilities**: SystemCapability.Multimedia.Audio.Renderer
**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.
**System capabilities**: SystemCapability.Multimedia.Audio.Renderer
**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.
**System capabilities**: SystemCapability.Multimedia.Audio.Renderer
**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.
**System capabilities**: SystemCapability.Multimedia.Audio.Renderer
**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.
**System capabilities**: SystemCapability.Multimedia.Audio.Renderer
**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.
**System capabilities**: SystemCapability.Multimedia.Audio.Renderer
**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();
```
## AudioDeviceDescriptor
Describes an audio device.
| Name | Type | Readable | Writable | Description |
| -------- | -------- | -------- | -------- | -------- |
| deviceRole | [DeviceRole](#devicerole) | Yes | No | Device role.
**System capabilities:** SystemCapability.Multimedia.Audio.Device |
| deviceType | [DeviceType](#devicetype) | Yes | No | Device type.
**System capabilities:** SystemCapability.Multimedia.Audio.Device |
## AudioDeviceDescriptors
| Name | Description |
| -------- | -------- |
| AudioDeviceDescriptors | Array of **AudioDeviceDescriptor** objects. It is read-only.
**System capabilities:** SystemCapability.Multimedia.Audio.Device |