From e74b44f4fd66aede62f83c3877bb38293c1e0fc0 Mon Sep 17 00:00:00 2001 From: Vaidegi B Date: Thu, 23 Sep 2021 18:23:00 +0530 Subject: [PATCH] Update audio_management.md Signed-off-by: Vaidegi B --- .../js-reference/audio-management.md | 269 ++++++++---------- 1 file changed, 118 insertions(+), 151 deletions(-) diff --git a/en/application-dev/js-reference/audio-management.md b/en/application-dev/js-reference/audio-management.md index e538c610ff..195effeb78 100644 --- a/en/application-dev/js-reference/audio-management.md +++ b/en/application-dev/js-reference/audio-management.md @@ -1,63 +1,63 @@ # Audio Management -- [Modules to Import](#s56d19203690d4782bfc74069abb6bd71) -- [Required Permissions](#section11257113618419) -- [getAudioManager\(\): AudioManager](#section84581011418) -- [AudioVolumeType](#section92261857172218) -- [DeviceFlag](#section11285183164210) -- [DeviceRole](#section380038142619) -- [DeviceType](#section11727420122710) -- [AudioRingMode7+](#section14948916131018) -- [AudioManager](#section8265143814015) - - [setVolume\(volumeType: AudioVolumeType, volume: number, callback: AsyncCallback\): void](#section189141826104616) - - [setVolume\(volumeType: AudioVolumeType, volume: number\): Promise](#section102021249114612) - - [getVolume\(volumeType: AudioVolumeType, callback: AsyncCallback\): void](#section4387320194714) - - [getVolume\(volumeType: AudioVolumeType\): Promise](#section04121965119) - - [getMinVolume\(volumeType: AudioVolumeType, callback: AsyncCallback\): void](#section188714283511) - - [getMinVolume\(volumeType: AudioVolumeType\): Promise](#section41556389511) - - [getMaxVolume\(volumeType: AudioVolumeType, callback: AsyncCallback\): void](#section690395418516) - - [getMaxVolume\(volumeType: AudioVolumeType\): Promise](#section155151345217) - - [mute\(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback\): void7+](#section13516136134613) - - [mute\(volumeType: AudioVolumeType, mute: boolean\): Promise7+](#section7519036144616) - - [isMute\(volumeType: AudioVolumeType, callback: AsyncCallback\): void7+](#section10684183819585) - - [isMute\(volumeType: AudioVolumeType\): Promise7+](#section6920211145610) - - [isActive\(volumeType: AudioVolumeType, callback: AsyncCallback\): void7+](#section380012544121) - - [isActive\(volumeType: AudioVolumeType\): Promise7+](#section1880315481216) - - [setRingerMode\(mode: AudioRingMode, callback: AsyncCallback\): void7+](#section18572131483613) - - [setRingerMode\(mode: AudioRingMode\): Promise7+](#section55741914143615) - - [getRingerMode\(callback: AsyncCallback\): void7+](#section149044108162) - - [getRingerMode\(\): Promise7+](#section13908210101620) - - [setAudioParameter\(key: string, value: string, callback: AsyncCallback\): void7+](#section1691957174818) - - [setAudioParameter\(key: string, value: string\): Promise7+](#section18121057174820) - - [getAudioParameter\(key: string, callback: AsyncCallback\): void7+](#section1415145714812) - - [getAudioParameter\(key: string\): Promise7+](#section3185577485) - - [getDevices\(deviceFlag: DeviceFlag, callback: AsyncCallback\): void](#section11536182020523) - - [getDevices\(deviceFlag: DeviceFlag\): Promise](#section181733125210) - - [setDeviceActive\(deviceType: DeviceType, active: boolean, callback: AsyncCallback\): void7+](#section103558400222) - - [setDeviceActive\(deviceType: DeviceType, active: boolean\): Promise7+](#section1235914401228) - - [isDeviceActive\(deviceType: DeviceType, callback: AsyncCallback\): void7+](#section12363240122219) - - [isDeviceActive\(deviceType: DeviceType\): Promise7+](#section18366184012213) - - [setMicrophoneMute\(mute: boolean, callback: AsyncCallback\): void7+](#section14703163618122) - - [setMicrophoneMute\(mute: boolean\): Promise7+](#section56287111791) - - [isMicrophoneMute\(callback: AsyncCallback\): void7+](#section6632141119912) - - [isMicrophoneMute\(\): Promise7+](#section196363111918) - -- [AudioDeviceDescriptor](#section164657411927) - - [Attributes](#section4947115405) - -- [AudioDeviceDescriptors](#section5181155710523) - -## Modules to Import + - [Modules to Import](#modules-to-import) + - [Required Permissions](#required-permissions) + - [getAudioManager\(\): AudioManager](#getaudiomanager-audiomanager) + - [AudioVolumeType](#audiovolumetype) + - [DeviceFlag](#deviceflag) + - [DeviceRole](#devicerole) + - [DeviceType](#devicetype) + - [ActiveDeviceType7+](#activedevicetype) + - [AudioRingMode7+](#audioringmode) + - [AudioManager](#audiomanager) + - [setVolume\(volumeType: AudioVolumeType, volume: number, callback: AsyncCallback\): void](#setvolume-asynccallback) + - [setVolume\(volumeType: AudioVolumeType, volume: number\): Promise](#setvolume-promise) + - [getVolume\(volumeType: AudioVolumeType, callback: AsyncCallback\): void](#getvolume-asynccallback) + - [getVolume\(volumeType: AudioVolumeType\): Promise](#getvolume-promise) + - [getMinVolume\(volumeType: AudioVolumeType, callback: AsyncCallback\): void](#getminvolume-asynccallback) + - [getMinVolume\(volumeType: AudioVolumeType\): Promise](#getminvolume-promise) + - [getMaxVolume\(volumeType: AudioVolumeType, callback: AsyncCallback\): void](#getmaxvolume-asynccallback) + - [getMaxVolume\(volumeType: AudioVolumeType\): Promise](#getmaxvolume-promise) + - [mute\(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback\): void7+](#mute-asynccallback) + - [mute\(volumeType: AudioVolumeType, mute: boolean\): Promise7+](#mute-promise) + - [isMute\(volumeType: AudioVolumeType, callback: AsyncCallback\): void7+](#ismute-asynccallback) + - [isMute\(volumeType: AudioVolumeType\): Promise7+](#ismute-promise) + - [isActive\(volumeType: AudioVolumeType, callback: AsyncCallback\): void7+](#isactive-asynccallback) + - [isActive\(volumeType: AudioVolumeType\): Promise7+](#isactive-promise) + - [setRingerMode\(mode: AudioRingMode, callback: AsyncCallback\): void7+](#setringermode-asynccallback) + - [setRingerMode\(mode: AudioRingMode\): Promise7+](#setringermode-promise) + - [getRingerMode\(callback: AsyncCallback\): void7+](#getringermode-asynccallback) + - [getRingerMode\(\): Promise7+](#getringermode-promise) + - [setAudioParameter\(key: string, value: string, callback: AsyncCallback\): void7+](#setaudioparameter-asynccallback) + - [setAudioParameter\(key: string, value: string\): Promise7+](#setaudioparameter-promise) + - [getAudioParameter\(key: string, callback: AsyncCallback\): void7+](#getaudioparameter-asynccallback) + - [getAudioParameter\(key: string\): Promise7+](#getaudioparameter-promise) + - [getDevices\(deviceFlag: DeviceFlag, callback: AsyncCallback\): void](#getdevices-asynccallback) + - [getDevices\(deviceFlag: DeviceFlag\): Promise](#getdevices-promise) + - [setDeviceActive\(deviceType: ActiveDeviceType, active: boolean, callback: AsyncCallback\): void7+](#setdeviceactive-asynccallback) + - [setDeviceActive\(deviceType: ActiveDeviceType, active: boolean\): Promise7+](#setdeviceactive-promise) + - [isDeviceActive\(deviceType: ActiveDeviceType, callback: AsyncCallback\): void7+](#isdeviceactive-asynccallback) + - [isDeviceActive\(deviceType: ActiveDeviceType\): Promise7+](#isdeviceactive-promise) + - [setMicrophoneMute\(mute: boolean, callback: AsyncCallback\): void7+](#setmicrophonemute-asynccallback) + - [setMicrophoneMute\(mute: boolean\): Promise7+](#setmicrophonemute-promise) + - [isMicrophoneMute\(callback: AsyncCallback\): void7+](#ismicrophonemute-asynccallback) + - [isMicrophoneMute\(\): Promise7+](#ismicrophonemute-promise) + - [AudioDeviceDescriptor](#audiodevicedescriptor) + - [Attributes](#attributes) + - [AudioDeviceDescriptors](#audiodevicedescriptors) + + +## Modules to Import ``` import audio from '@ohos.multimedia.audio'; ``` -## Required Permissions +## Required Permissions None -## getAudioManager\(\): AudioManager +## getAudioManager\(\): AudioManager Obtains an **AudioManager** instance. @@ -78,13 +78,14 @@ Obtains an **AudioManager** instance. + **Example** ``` var audioManager = audio.getAudioManager(); ``` -## AudioVolumeType +## AudioVolumeType Enumerates audio stream types. @@ -114,7 +115,7 @@ Enumerates audio stream types. -## DeviceFlag +## DeviceFlag Enumerates audio device flags. @@ -151,7 +152,7 @@ Enumerates audio device flags. -## DeviceRole +## DeviceRole Enumerates audio device roles. @@ -181,65 +182,31 @@ Enumerates audio device roles. -## DeviceType +## DeviceType Enumerates audio device types. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Default Value

-

Description

-

INVALID

-

0

-

Invalid device

-

SPEAKER

-

1

-

Speaker

-

WIRED_HEADSET

-

2

-

Wired headset

-

BLUETOOTH_SCO

-

3

-

Bluetooth device using the synchronous connection oriented (SCO) link

-

BLUETOOTH_A2DP

-

4

-

Bluetooth device using the advanced audio distribution profile (A2DP)

-

MIC

-

5

-

Microphone

-
+| Name | Default Value | Description | +| -------------- | ------------- | --------------------------------------------------------------------- | +| INVALID | 0 | Invalid device | +| EARPIECE | 1 | Earpiece | +| SPEAKER | 2 | Speaker | +| WIRED_HEADSET | 3 | Wired headset | +| BLUETOOTH_SCO | 7 | Bluetooth device using the synchronous connection oriented (SCO) link | +| BLUETOOTH_A2DP | 8 | Bluetooth device using the advanced audio distribution profile (A2DP) | +| MIC | 15 | Microphone | + + +## ActiveDeviceType7+ + +Enumerates active device types. + +| Name | Default Value | Description | +| ------------- | ------------- | --------------------------------------------------------------------- | +| SPEAKER | 2 | Speaker | +| BLUETOOTH_SCO | 7 | Bluetooth device using the synchronous connection oriented (SCO) link | -## AudioRingMode7+ +## AudioRingMode7+ Enumerates ringer modes. @@ -280,7 +247,7 @@ Enumerates ringer modes. Implements audio volume and audio device management. -### setVolume\(volumeType: AudioVolumeType, volume: number, callback: AsyncCallback\): void +### 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. @@ -343,7 +310,7 @@ audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10, (err)=>{ }) ``` -### 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. @@ -406,7 +373,7 @@ audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(()=> ) ``` -### getVolume\(volumeType: AudioVolumeType, callback: AsyncCallback\): void +### getVolume\(volumeType: AudioVolumeType, callback: AsyncCallback\): void Obtains the volume of a stream. This method uses an asynchronous callback to return the query result. @@ -460,7 +427,7 @@ audioManager.getVolume(audio.AudioVolumeType.MEDIA, (err, value) => { }) ``` -### getVolume\(volumeType: AudioVolumeType\): Promise +### getVolume\(volumeType: AudioVolumeType\): Promise Obtains the volume of a stream. This method uses a promise to return the query result. @@ -514,7 +481,7 @@ audioManager.getVolume(audio.AudioVolumeType.MEDIA).then((value) => ) ``` -### getMinVolume\(volumeType: AudioVolumeType, callback: AsyncCallback\): void +### 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. @@ -568,7 +535,7 @@ audioManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err, value) => { }) ``` -### getMinVolume\(volumeType: AudioVolumeType\): Promise +### getMinVolume\(volumeType: AudioVolumeType\): Promise Obtains the minimum volume allowed for a stream. This method uses a promise to return the query result. @@ -622,7 +589,7 @@ audioManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value) => ) ``` -### getMaxVolume\(volumeType: AudioVolumeType, callback: AsyncCallback\): void +### 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. @@ -676,7 +643,7 @@ audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA, (err, value) => { }) ``` -### getMaxVolume\(volumeType: AudioVolumeType\): Promise +### getMaxVolume\(volumeType: AudioVolumeType\): Promise Obtains the maximum volume allowed for a stream. This method uses a promise to return the query result. @@ -730,7 +697,7 @@ audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data)=> ) ``` -### mute\(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback\): void7+ +### mute\(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback\): void7+ Mutes a stream. This method uses an asynchronous callback to return the execution result. @@ -793,7 +760,7 @@ audioManager.mute(audio.AudioVolumeType.MEDIA, true, (err) => { }) ``` -### mute\(volumeType: AudioVolumeType, mute: boolean\): Promise7+ +### mute\(volumeType: AudioVolumeType, mute: boolean\): Promise7+ Mutes a stream. This method uses a promise to return the execution result. @@ -856,7 +823,7 @@ audioManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => ) ``` -### isMute\(volumeType: AudioVolumeType, callback: AsyncCallback\): void7+ +### isMute\(volumeType: AudioVolumeType, callback: AsyncCallback\): void7+ Checks whether a stream is muted. This method uses an asynchronous callback to return the query result. @@ -910,7 +877,7 @@ audioManager.isMute(audio.AudioVolumeType.MEDIA, (err, value) => { }) ``` -### isMute\(volumeType: AudioVolumeType\): Promise7+ +### isMute\(volumeType: AudioVolumeType\): Promise7+ Checks whether a stream is muted. This method uses a promise to return the execution result. @@ -964,7 +931,7 @@ audioManager.isMute(audio.AudioVolumeType.MEDIA).then((value) => ) ``` -### isActive\(volumeType: AudioVolumeType, callback: AsyncCallback\): void7+ +### isActive\(volumeType: AudioVolumeType, callback: AsyncCallback\): void7+ Checks whether a stream is active. This method uses an asynchronous callback to return the query result. @@ -1018,7 +985,7 @@ audioManager.isActive(audio.AudioVolumeType.MEDIA, (err, value) => { }) ``` -### isActive\(volumeType: AudioVolumeType\): Promise7+ +### isActive\(volumeType: AudioVolumeType\): Promise7+ Checks whether a stream is active. This method uses a promise to return the query result. @@ -1072,7 +1039,7 @@ audioManager.isActive(audio.AudioVolumeType.MEDIA).then((value) => ) ``` -### setRingerMode\(mode: AudioRingMode, callback: AsyncCallback\): void7+ +### setRingerMode\(mode: AudioRingMode, callback: AsyncCallback\): void7+ Sets the ringer mode. This method uses an asynchronous callback to return the execution result. @@ -1126,7 +1093,7 @@ audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL, (err) => { }) ``` -### setRingerMode\(mode: AudioRingMode\): Promise7+ +### setRingerMode\(mode: AudioRingMode\): Promise7+ Sets the ringer mode. This method uses a promise to return the execution result. @@ -1180,7 +1147,7 @@ audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() => ) ``` -### getRingerMode\(callback: AsyncCallback\): void7+ +### getRingerMode\(callback: AsyncCallback\): void7+ Obtains the ringer mode. This method uses an asynchronous callback to return the query result. @@ -1225,7 +1192,7 @@ audioManager.getRingerMode((err, value) => { }) ``` -### getRingerMode\(\): Promise7+ +### getRingerMode\(\): Promise7+ Obtains the ringer mode. This method uses a promise to return the query result. @@ -1258,7 +1225,7 @@ audioManager.getRingerMode().then((value) => ) ``` -### setAudioParameter\(key: string, value: string, callback: AsyncCallback\): void7+ +### setAudioParameter\(key: string, value: string, callback: AsyncCallback\): void7+ Sets an audio parameter. This method uses an asynchronous callback to return the execution result. @@ -1321,7 +1288,7 @@ audioManager.setAudioParameter('PBits per sample', '8 bit', (err) => { }) ``` -### setAudioParameter\(key: string, value: string\): Promise7+ +### setAudioParameter\(key: string, value: string\): Promise7+ Sets an audio parameter. This method uses a promise to return the execution result. @@ -1384,7 +1351,7 @@ audioManager.setAudioParameter('PBits per sample', '8 bit').then(() => ) ``` -### getAudioParameter\(key: string, callback: AsyncCallback\): void7+ +### getAudioParameter\(key: string, callback: AsyncCallback\): void7+ Obtains the value of an audio parameter. This method uses an asynchronous callback to return the query result. @@ -1438,7 +1405,7 @@ audioManager.getAudioParameter('PBits per sample', (err, value) => { }) ``` -### getAudioParameter\(key: string\): Promise7+ +### getAudioParameter\(key: string\): Promise7+ Obtains the value of an audio parameter. This method uses a promise to return the query result. @@ -1492,7 +1459,7 @@ audioManager.getAudioParameter('PBits per sample').then((value) => ) ``` -### getDevices\(deviceFlag: DeviceFlag, callback: AsyncCallback\): void +### 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. @@ -1546,7 +1513,7 @@ audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err, value)=>{ }) ``` -### getDevices\(deviceFlag: DeviceFlag\): Promise +### getDevices\(deviceFlag: DeviceFlag\): Promise Obtains the audio devices with a specific flag. This method uses a promise to return the query result. @@ -1600,7 +1567,7 @@ audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data)=> ) ``` -### setDeviceActive\(deviceType: DeviceType, active: boolean, callback: AsyncCallback\): void7+ +### setDeviceActive\(deviceType: ActiveDeviceType, active: boolean, callback: AsyncCallback\): void7+ Sets a device to the active state. This method uses an asynchronous callback to return the execution result. @@ -1619,7 +1586,7 @@ Sets a device to the active state. This method uses an asynchronous callback to

deviceType

-

DeviceType

+

ActiveDeviceType

Yes

@@ -1654,7 +1621,7 @@ None **Example** ``` -audioManager.setDeviceActive(audio.DeviceType.SPEAKER, true, (err)=> { +audioManager.setDeviceActive(audio.ActiveDeviceType.SPEAKER, true, (err)=> { if (err) { console.error('Failed to set the active status of the device. ${err.message}'); return; @@ -1663,7 +1630,7 @@ audioManager.setDeviceActive(audio.DeviceType.SPEAKER, true, (err)=> { }) ``` -### setDeviceActive\(deviceType: DeviceType, active: boolean\): Promise7+ +### setDeviceActive\(deviceType: ActiveDeviceType, active: boolean\): Promise7+ Sets a device to the active state. This method uses a promise to return the execution result. @@ -1682,7 +1649,7 @@ Sets a device to the active state. This method uses a promise to return the exec

deviceType

-

DeviceType

+

ActiveDeviceType

Yes

@@ -1721,12 +1688,12 @@ Sets a device to the active state. This method uses a promise to return the exec **Example** ``` -audioManager.setDeviceActive(audio.DeviceType.SPEAKER, true).then(()=> +audioManager.setDeviceActive(audio.ActiveDeviceType.SPEAKER, true).then(()=> console.log('Promise returned to indicate that the device is set to the active status.'); ) ``` -### isDeviceActive\(deviceType: DeviceType, callback: AsyncCallback\): void7+ +### isDeviceActive\(deviceType: DeviceType, callback: AsyncCallback\): void7+ Checks whether a device is active. This method uses an asynchronous callback to return the query result. @@ -1745,7 +1712,7 @@ Checks whether a device is active. This method uses an asynchronous callback to

deviceType

-

DeviceType

+

ActiveDeviceType

Yes

@@ -1771,7 +1738,7 @@ None **Example** ``` -audioManager.isDeviceActive(audio.DeviceType.SPEAKER, (err, value) => { +audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER, (err, value) => { if (err) { console.error('Failed to obtain the active status of the device. ${err.message}'); return; @@ -1780,7 +1747,7 @@ audioManager.isDeviceActive(audio.DeviceType.SPEAKER, (err, value) => { }) ``` -### isDeviceActive\(deviceType: DeviceType\): Promise7+ +### isDeviceActive\(deviceType: ActiveDeviceType\): Promise7+ Checks whether a device is active. This method uses a promise to return the query result. @@ -1799,7 +1766,7 @@ Checks whether a device is active. This method uses a promise to return the quer

deviceType

-

DeviceType

+

ActiveDeviceType

Yes

@@ -1829,12 +1796,12 @@ Checks whether a device is active. This method uses a promise to return the quer **Example** ``` -audioManager.isDeviceActive(audio.DeviceType.SPEAKER).then((value) => +audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER).then((value) => console.log('Promise returned to indicate that the active status of the device is obtained.' + value); ) ``` -### setMicrophoneMute\(mute: boolean, callback: AsyncCallback\): void7+ +### setMicrophoneMute\(mute: boolean, callback: AsyncCallback\): void7+ Mutes or unmutes the microphone. This method uses an asynchronous callback to return the execution result. @@ -1888,7 +1855,7 @@ audioManager.setMicrophoneMute(true, (err) => { }) ``` -### setMicrophoneMute\(mute: boolean\): Promise7+ +### setMicrophoneMute\(mute: boolean\): Promise7+ Mutes or unmutes the microphone. This method uses a promise to return the execution result. @@ -1942,7 +1909,7 @@ audioManager.setMicrophoneMute(true).then(() => ) ``` -### isMicrophoneMute\(callback: AsyncCallback\): void7+ +### isMicrophoneMute\(callback: AsyncCallback\): void7+ Checks whether the microphone is muted. This method uses an asynchronous callback to return the query result. @@ -1987,7 +1954,7 @@ audioManager.isMicrophoneMute((err, value) => { }) ``` -### isMicrophoneMute\(\): Promise7+ +### isMicrophoneMute\(\): Promise7+ Checks whether the microphone is muted. This method uses a promise to return the query result. @@ -2020,11 +1987,11 @@ audioManager.isMicrophoneMute().then((value) => ) ``` -## AudioDeviceDescriptor +## AudioDeviceDescriptor Describes an audio device. -### Attributes +### Attributes

Name

@@ -2064,7 +2031,7 @@ Describes an audio device.
-## AudioDeviceDescriptors +## AudioDeviceDescriptors

Name

-- GitLab