1# Volume Management
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
7**AudioVolumeManager** is provided for system volume management. Before using this API, you must call **getVolumeManager()** to obtain an **AudioVolumeManager** instance.
8
9Currently, **AudioVolumeManager** can be used to obtain volume information and listen for volume changes. It cannot be used to adjust the system volume. If you want to adjust the system volume, follow the instructions provided in [Adjusting the System Volume Using the Volume Panel](#adjusting-the-system-volume-using-the-volume-panel).
10
11```ts
12import { audio } from '@kit.AudioKit';
13
14let audioManager = audio.getAudioManager();
15let audioVolumeManager = audioManager.getVolumeManager();
16```
17
18### Listening for System Volume Changes
19
20You can set an event to listen for system volume changes.
21
22```ts
23import { audio } from '@kit.AudioKit';
24
25audioVolumeManager.on('volumeChange', (volumeEvent: audio.VolumeEvent) => {
26  console.info(`VolumeType of stream: ${volumeEvent.volumeType} `);
27  console.info(`Volume level: ${volumeEvent.volume} `);
28  console.info(`Whether to updateUI: ${volumeEvent.updateUi} `);
29});
30```
31
32<!--Del-->
33### Adjusting the System Volume (for System Applications Only)
34
35Currently, adjusting the system volume is mainly conducted by using system APIs, which are available for 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.
36<!--DelEnd-->
37
38### Adjusting the System Volume Using the Volume Panel
39
40An application cannot directly adjust the system volume. However, it can invoke the system volume panel for users to adjust the volume. When the user adjusts the volume, a volume prompt UI is displayed to explicitly notify the user that the system volume changes.
41
42To achieve this, you can use the ArkTS component **AVVolumePanel** in your application. For details, see the [AVVolumePanel Reference](../../reference/apis-audio-kit/ohos-multimedia-avvolumepanel.md).
43
44## Audio Stream Volume
45
46The **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:
47
48```ts
49let volume = 1.0;  // Specified volume. The value range is [0.00-1.00]. The value 1 indicates the maximum volume.
50avPlayer.setVolume(volume);
51```
52
53The code snippet below uses the API in the [AudioRenderer](../../reference/apis-audio-kit/js-apis-audio.md#audiocreateaudiorenderer8) class:
54
55```ts
56import { BusinessError } from '@kit.BasicServicesKit';
57
58audioRenderer.setVolume(0.5).then(() => {  // The volume range is [0.0-1.0].
59  console.info('Invoke setVolume succeeded.');
60}).catch((err: BusinessError) => {
61  console.error(`Invoke setVolume failed, code is ${err.code}, message is ${err.message}`);
62});
63```
64