1# Volume Management (ArkTS) 2 3You can use different APIs to manage the system volume and audio stream volume. The system volume and audio stream volume refer to the volume of a OpenHarmony device and the volume of a specified audio stream, respectively. The audio stream volume is restricted by the system volume. 4 5## System Volume 6 7The API for managing the system volume is **AudioVolumeManager**. Before using this API, you must call **getVolumeManager()** to obtain an **AudioVolumeManager** instance. Currently, this API can be used to obtain volume information and listen for volume changes. It cannot be used to adjust the system volume. 8 9```ts 10import audio from '@ohos.multimedia.audio'; 11 12let audioManager = audio.getAudioManager(); 13let audioVolumeManager = audioManager.getVolumeManager(); 14``` 15 16### Listening for System Volume Changes 17 18You can set an event to listen for system volume changes. 19 20```ts 21import audio from '@ohos.multimedia.audio'; 22 23audioVolumeManager.on('volumeChange', (volumeEvent: audio.VolumeEvent) => { 24 console.info(`VolumeType of stream: ${volumeEvent.volumeType} `); 25 console.info(`Volume level: ${volumeEvent.volume} `); 26 console.info(`Whether to updateUI: ${volumeEvent.updateUi} `); 27}); 28``` 29 30### Adjusting the System Volume (for System Applications Only) 31 32Currently, the system volume is mainly adjusted by using system APIs, which serve the physical volume button and the Settings application. When the user presses the volume button, a system API is called to adjust the system volume, including the volume for media, ringtone, or notification. 33 34## Audio Stream Volume 35 36The **setVolume()** API in both the **AVPlayer** and **AudioRenderer** classes can be used to set the audio stream volume. The code snippet below uses the API in the [AVPlayer](../reference/apis-media-kit/js-apis-media.md#mediacreateavplayer9) class: 37 38```ts 39let volume = 1.0 // Specified volume. The value range is [0.00-1.00]. The value 1 indicates the maximum volume. 40avPlayer.setVolume(volume); 41``` 42 43The code snippet below uses the API in the [AudioRenderer](../reference/apis-audio-kit/js-apis-audio.md#audiocreateaudiorenderer8) class: 44 45```ts 46import { BusinessError } from '@ohos.base'; 47 48audioRenderer.setVolume(0.5).then(() => { // The volume range is [0.0-1.0]. 49 console.info('Invoke setVolume succeeded.'); 50}).catch((err: BusinessError) => { 51 console.error(`Invoke setVolume failed, code is ${err.code}, message is ${err.message}`); 52}); 53``` 54