1 Star 0 Fork 5.1K

youguilin / docs

forked from OpenHarmony / docs 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
development-guidelines-on-audio-management.md 18.59 KB
一键复制 编辑 原始数据 按行查看 历史
mamingshuai 提交于 2021-06-02 01:00 . update OpenHarmony 2.0 Canary

Development Guidelines on Audio Management

When to Use

You use audio management APIs to set and obtain volume, and get information about input/output devices.

Available APIs

Table 1 Audio

API

Description

getAudioManager(): AudioManager

Obtains an AudioManager instance.

AudioManager

Manages audio volume and audio device information.

AudioDeviceDescriptor

Describes audio devices.

AudioVolumeType

Enumerates audio volume types.

DeviceFlag

Enumerates flags of supported devices.

DeviceRole

Enumerates device roles.

DeviceType

Enumerates device types.

Table 2 AudioManager methods

Method

Description

setVolume(audioType: AudioVolumeType,volume: number,callback: AsyncCallback<void>): void

Sets the volume of a stream asynchronously and uses a callback to return the execution result.

setVolume(audioType: AudioVolumeType,volume: number): Promise<void>

Sets the volume of a stream asynchronously and uses a Promise to return the execution result.

getVolume(audioType: AudioVolumeType, callback: AsyncCallback<number>): void

Obtains the volume of a stream asynchronously and uses a callback to return the execution result.

getVolume(audioType: AudioVolumeType): Promise<number>

Obtains the volume of a stream asynchronously and uses a Promise to return the execution result.

getMinVolume(audioType: AudioVolumeType, callback: AsyncCallback<number>): void

Obtains the minimum volume of a stream asynchronously and uses a callback to return the execution result.

getMinVolume(audioType: AudioVolumeType): Promise<number>

Obtains the minimum volume of a stream asynchronously and uses a Promise to return the execution result.

getMaxVolume(audioType: AudioVolumeType, callback: AsyncCallback<number>): void

Obtains the maximum volume of a stream asynchronously and uses a callback to return the execution result.

getMaxVolume(audioType: AudioVolumeType): Promise<number>

Obtains the maximum volume of a stream asynchronously and uses a Promise to return the execution result.

getDevices(deviceFlag: DeviceFlag, callback: AsyncCallback<AudioDeviceDescriptors>): void

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

getDevices(deviceFlag: DeviceFlag): Promise<AudioDeviceDescriptors>

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

Table 3 AudioDeviceDescriptor attributes

Parameter

Description

deviceRole: DeviceRole

Audio device role

deviceType: DeviceType

Audio device type

Table 4 AudioVolumeType enums

Enum

Description

MEDIA = 1

Audio streams for media purpose

RINGTONE = 2

Audio streams for ring tones

Table 5 DeviceFlag enums

Enum

Description

OUTPUT_DEVICES_FLAG = 1

Output devices

INPUT_DEVICES_FLAG = 2

Input devices

ALL_DEVICES_FLAG = 3

All devices

Table 6 DeviceRole enums

Enum

Description

INPUT_DEVICE = 1

Input role

OUTPUT_DEVICE = 2

Output role

Table 7 DeviceType enums

Enum

Description

INVALID = 0

Invalid device

SPEAKER = 1

Speaker

WIRED_HEADSET = 2

Wired headset

BLUETOOTH_SCO = 3

Bluetooth device using the synchronous connection oriented link (SCO)

BLUETOOTH_A2DP = 4

Bluetooth device using advanced audio distribution profile (A2DP)

MIC = 5

Microphone

Development Procedure

  1. Obtain an audio manager.

    const audioManager = audio.getAudioManager();
  2. Set the audio stream volume.

    audioManager.getVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
       if (err) {
    	   console.error(`failed to get volume ${err.message}`);
    	   return;
       }
       console.log(`Media getVolume  ${value}`);
    });
1
https://gitee.com/yougl/docs.git
git@gitee.com:yougl/docs.git
yougl
docs
docs
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891