• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# native_audio_volume_manager.h
2
3## Overview
4
5The file declares the functions related to an audio volume manager. You can call the functions to create an audio volume manager.
6
7**Library**: libohaudio.so
8
9**System capability**: SystemCapability.Multimedia.Audio.Core
10
11**Since**: 20
12
13**Related module**: [OHAudio](capi-ohaudio.md)
14
15## Summary
16
17### Structs
18
19| Name| typedef Keyword| Description|
20| -- | -- | -- |
21| [OH_AudioVolumeManager](capi-ohaudio-oh-audiovolumemanager.md) | OH_AudioVolumeManager | Describes an audio volume manager, which provides various functions for obtaining system volume information.|
22
23### Functions
24
25| Name| typedef Keyword| Description|
26| -- | -- | -- |
27| [typedef void (\*OH_AudioVolumeManager_OnStreamVolumeChangeCallback)(void *userData,OH_AudioStream_Usage usage,int32_t volumeLevel,bool updateUi)](#oh_audiovolumemanager_onstreamvolumechangecallback) | OH_AudioVolumeManager_OnStreamVolumeChangeCallback | Defines the prototype of the volume change callback function, which is passed in [OH_AudioVolumeManager_RegisterStreamVolumeChangeCallback](capi-native-audio-volume-manager-h.md#oh_audiovolumemanager_registerstreamvolumechangecallback).|
28| [typedef void (\*OH_AudioVolumeManager_OnRingerModeChangeCallback)(void *userData,OH_AudioRingerMode ringerMode)](#oh_audiovolumemanager_onringermodechangecallback) | OH_AudioVolumeManager_OnRingerModeChangeCallback | Defines the prototype of the ringer mode change callback function, which is passed in [OH_AudioVolumeManager_RegisterStreamVolumeChangeCallback](capi-native-audio-volume-manager-h.md#oh_audiovolumemanager_registerstreamvolumechangecallback).|
29| [OH_AudioCommon_Result OH_AudioManager_GetAudioVolumeManager(OH_AudioVolumeManager **volumeManager)](#oh_audiomanager_getaudiovolumemanager) | - | Obtains an OH_AudioVolumeManager instance.|
30| [OH_AudioCommon_Result OH_AudioVolumeManager_GetMaxVolumeByUsage(OH_AudioVolumeManager *volumeManager,OH_AudioStream_Usage usage, int32_t *maxVolumeLevel)](#oh_audiovolumemanager_getmaxvolumebyusage) | - | Obtains the maximum volume level of an audio stream of a specified usage type.|
31| [OH_AudioCommon_Result OH_AudioVolumeManager_GetMinVolumeByUsage(OH_AudioVolumeManager *volumeManager,OH_AudioStream_Usage usage, int32_t *minVolumeLevel)](#oh_audiovolumemanager_getminvolumebyusage) | - | Obtains the minimum volume level of an audio stream of a specified usage type.|
32| [OH_AudioCommon_Result OH_AudioVolumeManager_GetVolumeByUsage(OH_AudioVolumeManager *volumeManager,OH_AudioStream_Usage usage, int32_t *volumeLevel)](#oh_audiovolumemanager_getvolumebyusage) | - | Obtains the system volume level of an audio stream of a specified usage type.|
33| [OH_AudioCommon_Result OH_AudioVolumeManager_IsMuteByUsage(OH_AudioVolumeManager *volumeManager,OH_AudioStream_Usage usage, bool *muted)](#oh_audiovolumemanager_ismutebyusage) | - | Checks whether an audio stream of a specified usage type is muted.|
34| [OH_AudioCommon_Result OH_AudioVolumeManager_RegisterStreamVolumeChangeCallback(OH_AudioVolumeManager *volumeManager, OH_AudioStream_Usage usage,OH_AudioVolumeManager_OnStreamVolumeChangeCallback callback, void *userData)](#oh_audiovolumemanager_registerstreamvolumechangecallback) | - | Registers the volume change callback function.|
35| [OH_AudioCommon_Result OH_AudioVolumeManager_UnregisterStreamVolumeChangeCallback(OH_AudioVolumeManager *volumeManager,OH_AudioVolumeManager_OnStreamVolumeChangeCallback callback)](#oh_audiovolumemanager_unregisterstreamvolumechangecallback) | - | Unregisters the volume change callback function.|
36| [OH_AudioCommon_Result OH_AudioVolumeManager_GetRingerMode(OH_AudioVolumeManager *volumeManager,OH_AudioRingerMode *ringerMode)](#oh_audiovolumemanager_getringermode) | - | Obtains the ringer mode in use.|
37| [OH_AudioCommon_Result OH_AudioVolumeManager_RegisterRingerModeChangeCallback(OH_AudioVolumeManager *volumeManager,OH_AudioVolumeManager_OnRingerModeChangeCallback callback, void *userData)](#oh_audiovolumemanager_registerringermodechangecallback) | - | Registers the ringer mode change callback function.|
38| [OH_AudioCommon_Result OH_AudioVolumeManager_UnregisterRingerModeChangeCallback(OH_AudioVolumeManager *volumeManager,OH_AudioVolumeManager_OnRingerModeChangeCallback callback)](#oh_audiovolumemanager_unregisterringermodechangecallback) | - | Unregisters the ringer mode change callback function.|
39
40## Function Description
41
42### OH_AudioVolumeManager_OnStreamVolumeChangeCallback()
43
44```
45typedef void (*OH_AudioVolumeManager_OnStreamVolumeChangeCallback)(void *userData,OH_AudioStream_Usage usage,int32_t volumeLevel,bool updateUi)
46```
47
48**Description**
49
50Defines the prototype of the volume change callback function, which is passed in [OH_AudioVolumeManager_RegisterStreamVolumeChangeCallback](capi-native-audio-volume-manager-h.md#oh_audiovolumemanager_registerstreamvolumechangecallback).
51
52**Since**: 20
53
54
55**Parameters**
56
57| Name| Description|
58| -- | -- |
59| void *userData | Pointer to user data.|
60| [OH_AudioStream_Usage](capi-native-audiostream-base-h.md#oh_audiostream_usage) usage | Usage type of the audio stream for which the volume is changed.|
61| int32_t volumeLevel | Volume level after change.|
62| bool updateUi | Whether to update the UI accordingly.|
63
64### OH_AudioVolumeManager_OnRingerModeChangeCallback()
65
66```
67typedef void (*OH_AudioVolumeManager_OnRingerModeChangeCallback)(void *userData,OH_AudioRingerMode ringerMode)
68```
69
70**Description**
71
72Defines the prototype of the ringer mode change callback function, which is passed in [OH_AudioVolumeManager_RegisterStreamVolumeChangeCallback](capi-native-audio-volume-manager-h.md#oh_audiovolumemanager_registerstreamvolumechangecallback).
73
74**Since**: 20
75
76
77**Parameters**
78
79| Name| Description|
80| -- | -- |
81| void *userData | Pointer to user data.|
82| [OH_AudioRingerMode](capi-native-audio-common-h.md#oh_audioringermode) ringerMode | Ringer mode after change.|
83
84### OH_AudioManager_GetAudioVolumeManager()
85
86```
87OH_AudioCommon_Result OH_AudioManager_GetAudioVolumeManager(OH_AudioVolumeManager **volumeManager)
88```
89
90**Description**
91
92Obtains an OH_AudioVolumeManager instance.
93
94**Since**: 20
95
96
97**Parameters**
98
99| Name| Description|
100| -- | -- |
101| [OH_AudioVolumeManager](capi-ohaudio-oh-audiovolumemanager.md) **volumeManager | Double pointer to an OH_AudioVolumeManager instance, which is used to receive the created audio volume manager instance.|
102
103**Returns**
104
105| Type| Description|
106| -- | -- |
107| [OH_AudioCommon_Result](capi-native-audio-common-h.md#oh_audiocommon_result) | **AUDIOCOMMON_RESULT_SUCCESS**: The function is executed successfully.<br>**AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM**: The **volumeManager** parameter is nullptr.|
108
109### OH_AudioVolumeManager_GetMaxVolumeByUsage()
110
111```
112OH_AudioCommon_Result OH_AudioVolumeManager_GetMaxVolumeByUsage(OH_AudioVolumeManager *volumeManager,OH_AudioStream_Usage usage, int32_t *maxVolumeLevel)
113```
114
115**Description**
116
117Obtains the maximum volume level of an audio stream of a specified usage type.
118
119**Since**: 20
120
121
122**Parameters**
123
124| Name| Description|
125| -- | -- |
126| [OH_AudioVolumeManager](capi-ohaudio-oh-audiovolumemanager.md) *volumeManager | Pointer to an OH_AudioVolumeManager instance.|
127| [OH_AudioStream_Usage](capi-native-audiostream-base-h.md#oh_audiostream_usage) usage | Usage type of the audio stream.|
128| int32_t *maxVolumeLevel | Pointer to the maximum volume level.|
129
130**Returns**
131
132| Type| Description|
133| -- | -- |
134| [OH_AudioCommon_Result](capi-native-audio-common-h.md#oh_audiocommon_result) | **AUDIOCOMMON_RESULT_SUCCESS**: The function is executed successfully.<br>**AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM**: The **volumeManager** or **maxVolumeLevel** parameter is nullptr, or **usage** is invalid.<br>**AUDIOCOMMON_RESULT_ERROR_SYSTEM**: A system processing error occurs.|
135
136### OH_AudioVolumeManager_GetMinVolumeByUsage()
137
138```
139OH_AudioCommon_Result OH_AudioVolumeManager_GetMinVolumeByUsage(OH_AudioVolumeManager *volumeManager,OH_AudioStream_Usage usage, int32_t *minVolumeLevel)
140```
141
142**Description**
143
144Obtains the minimum volume level of an audio stream of a specified usage type.
145
146**Since**: 20
147
148
149**Parameters**
150
151| Name| Description|
152| -- | -- |
153| [OH_AudioVolumeManager](capi-ohaudio-oh-audiovolumemanager.md) *volumeManager | Pointer to an OH_AudioVolumeManager instance.|
154| [OH_AudioStream_Usage](capi-native-audiostream-base-h.md#oh_audiostream_usage) usage | Usage type of the audio stream.|
155| int32_t *minVolumeLevel | Pointer to the minimum volume level.|
156
157**Returns**
158
159| Type| Description|
160| -- | -- |
161| [OH_AudioCommon_Result](capi-native-audio-common-h.md#oh_audiocommon_result) | **AUDIOCOMMON_RESULT_SUCCESS**: The function is executed successfully.<br>**AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM**: The **volumeManager** or **minVolumeLevel** parameter is nullptr, or **usage** is invalid.<br>**AUDIOCOMMON_RESULT_ERROR_SYSTEM**: A system processing error occurs.|
162
163### OH_AudioVolumeManager_GetVolumeByUsage()
164
165```
166OH_AudioCommon_Result OH_AudioVolumeManager_GetVolumeByUsage(OH_AudioVolumeManager *volumeManager,OH_AudioStream_Usage usage, int32_t *volumeLevel)
167```
168
169**Description**
170
171Obtains the system volume level of an audio stream of a specified usage type.
172
173**Since**: 20
174
175
176**Parameters**
177
178| Name| Description|
179| -- | -- |
180| [OH_AudioVolumeManager](capi-ohaudio-oh-audiovolumemanager.md) *volumeManager | Pointer to an OH_AudioVolumeManager instance.|
181| [OH_AudioStream_Usage](capi-native-audiostream-base-h.md#oh_audiostream_usage) usage | Usage type of the audio stream.|
182| int32_t *volumeLevel | Pointer to the system volume level.|
183
184**Returns**
185
186| Type| Description|
187| -- | -- |
188| [OH_AudioCommon_Result](capi-native-audio-common-h.md#oh_audiocommon_result) | **AUDIOCOMMON_RESULT_SUCCESS**: The function is executed successfully.<br>**AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM**: The **volumeManager** or **volumeLevel** parameter is nullptr, or **usage** is invalid.<br>**AUDIOCOMMON_RESULT_ERROR_SYSTEM**: A system processing error occurs.|
189
190### OH_AudioVolumeManager_IsMuteByUsage()
191
192```
193OH_AudioCommon_Result OH_AudioVolumeManager_IsMuteByUsage(OH_AudioVolumeManager *volumeManager,OH_AudioStream_Usage usage, bool *muted)
194```
195
196**Description**
197
198Checks whether an audio stream of a specified usage type is muted.
199
200**Since**: 20
201
202
203**Parameters**
204
205| Name| Description|
206| -- | -- |
207| [OH_AudioVolumeManager](capi-ohaudio-oh-audiovolumemanager.md) *volumeManager | Pointer to an OH_AudioVolumeManager instance.|
208| [OH_AudioStream_Usage](capi-native-audiostream-base-h.md#oh_audiostream_usage) usage | Usage type of the audio stream.|
209| bool *muted | Pointer to the check result.|
210
211**Returns**
212
213| Type| Description|
214| -- | -- |
215| [OH_AudioCommon_Result](capi-native-audio-common-h.md#oh_audiocommon_result) | **AUDIOCOMMON_RESULT_SUCCESS**: The function is executed successfully.<br>**AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM**: The **volumeManager** or **muted** parameter is nullptr, or **usage** is invalid.<br>**AUDIOCOMMON_RESULT_ERROR_SYSTEM**: A system processing error occurs.|
216
217### OH_AudioVolumeManager_RegisterStreamVolumeChangeCallback()
218
219```
220OH_AudioCommon_Result OH_AudioVolumeManager_RegisterStreamVolumeChangeCallback(OH_AudioVolumeManager *volumeManager, OH_AudioStream_Usage usage,OH_AudioVolumeManager_OnStreamVolumeChangeCallback callback, void *userData)
221```
222
223**Description**
224
225Registers the volume change callback function.
226
227**Since**: 20
228
229
230**Parameters**
231
232| Name| Description|
233| -- | -- |
234| [OH_AudioVolumeManager](capi-ohaudio-oh-audiovolumemanager.md) *volumeManager | Pointer to an OH_AudioVolumeManager instance.|
235| [OH_AudioStream_Usage](capi-native-audiostream-base-h.md#oh_audiostream_usage) usage | Usage type of the audio stream.|
236| [OH_AudioVolumeManager_OnStreamVolumeChangeCallback](capi-native-audio-volume-manager-h.md#oh_audiovolumemanager_onstreamvolumechangecallback) callback | [OH_AudioVolumeManager_OnStreamVolumeChangeCallback](capi-native-audio-volume-manager-h.md#oh_audiovolumemanager_onstreamvolumechangecallback), which is called when the volume of the audio stream changes.|
237| void *userData | Pointer to user data.|
238
239**Returns**
240
241| Type| Description|
242| -- | -- |
243| [OH_AudioCommon_Result](capi-native-audio-common-h.md#oh_audiocommon_result) | **AUDIOCOMMON_RESULT_SUCCESS**: The function is executed successfully.<br>**AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM**: The **volumeManager**, **usage**, or **callback** parameter is nullptr, or **usage** is invalid.<br>**AUDIOCOMMON_RESULT_ERROR_SYSTEM**: A system processing error occurs.|
244
245### OH_AudioVolumeManager_UnregisterStreamVolumeChangeCallback()
246
247```
248OH_AudioCommon_Result OH_AudioVolumeManager_UnregisterStreamVolumeChangeCallback(OH_AudioVolumeManager *volumeManager,OH_AudioVolumeManager_OnStreamVolumeChangeCallback callback)
249```
250
251**Description**
252
253Unregisters the volume change callback function.
254
255**Since**: 20
256
257
258**Parameters**
259
260| Name| Description|
261| -- | -- |
262| [OH_AudioVolumeManager](capi-ohaudio-oh-audiovolumemanager.md) *volumeManager | Pointer to an OH_AudioVolumeManager instance.|
263| [OH_AudioVolumeManager_OnStreamVolumeChangeCallback](capi-native-audio-volume-manager-h.md#oh_audiovolumemanager_onstreamvolumechangecallback) callback | Pointer to the callback function passed by [OH_AudioVolumeManager_RegisterStreamVolumeChangeCallback](capi-native-audio-volume-manager-h.md#oh_audiovolumemanager_registerstreamvolumechangecallback).|
264
265**Returns**
266
267| Type| Description|
268| -- | -- |
269| [OH_AudioCommon_Result](capi-native-audio-common-h.md#oh_audiocommon_result) | **AUDIOCOMMON_RESULT_SUCCESS**: The function is executed successfully.<br>**AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM**: The **volumeManager** or **callback** parameter is nullptr.<br>**AUDIOCOMMON_RESULT_ERROR_SYSTEM**: A system processing error occurs.|
270
271### OH_AudioVolumeManager_GetRingerMode()
272
273```
274OH_AudioCommon_Result OH_AudioVolumeManager_GetRingerMode(OH_AudioVolumeManager *volumeManager,OH_AudioRingerMode *ringerMode)
275```
276
277**Description**
278
279Obtains the ringer mode in use.
280
281**Since**: 20
282
283
284**Parameters**
285
286| Name| Description|
287| -- | -- |
288| [OH_AudioVolumeManager](capi-ohaudio-oh-audiovolumemanager.md) *volumeManager | Pointer to an OH_AudioVolumeManager instance.|
289| [OH_AudioRingerMode](capi-native-audio-common-h.md#oh_audioringermode) *ringerMode | Pointer to the ringer mode.|
290
291**Returns**
292
293| Type| Description|
294| -- | -- |
295| [OH_AudioCommon_Result](capi-native-audio-common-h.md#oh_audiocommon_result) | **AUDIOCOMMON_RESULT_SUCCESS**: The function is executed successfully.<br>**AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM**: The **volumeManager** or **ringerMode** parameter is nullptr.<br>**AUDIOCOMMON_RESULT_ERROR_SYSTEM**: A system processing error occurs.|
296
297### OH_AudioVolumeManager_RegisterRingerModeChangeCallback()
298
299```
300OH_AudioCommon_Result OH_AudioVolumeManager_RegisterRingerModeChangeCallback(OH_AudioVolumeManager *volumeManager,OH_AudioVolumeManager_OnRingerModeChangeCallback callback, void *userData)
301```
302
303**Description**
304
305Registers the ringer mode change callback function.
306
307**Since**: 20
308
309
310**Parameters**
311
312| Name| Description|
313| -- | -- |
314| [OH_AudioVolumeManager](capi-ohaudio-oh-audiovolumemanager.md) *volumeManager | Pointer to an OH_AudioVolumeManager instance.|
315| [OH_AudioVolumeManager_OnRingerModeChangeCallback](capi-native-audio-volume-manager-h.md#oh_audiovolumemanager_onringermodechangecallback) callback | [OH_AudioVolumeManager_OnRingerModeChangeCallback](capi-native-audio-volume-manager-h.md#oh_audiovolumemanager_onringermodechangecallback), which is called when the ringer mode changes.|
316| void *userData | Pointer to user data.|
317
318**Returns**
319
320| Type| Description|
321| -- | -- |
322| [OH_AudioCommon_Result](capi-native-audio-common-h.md#oh_audiocommon_result) | **AUDIOCOMMON_RESULT_SUCCESS**: The function is executed successfully.<br>**AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM**: The **volumeManager** or **callback** parameter is nullptr.<br>**AUDIOCOMMON_RESULT_ERROR_SYSTEM**: A system processing error occurs.|
323
324### OH_AudioVolumeManager_UnregisterRingerModeChangeCallback()
325
326```
327OH_AudioCommon_Result OH_AudioVolumeManager_UnregisterRingerModeChangeCallback(OH_AudioVolumeManager *volumeManager,OH_AudioVolumeManager_OnRingerModeChangeCallback callback)
328```
329
330**Description**
331
332Unregisters the ringer mode change callback function.
333
334**Since**: 20
335
336
337**Parameters**
338
339| Name| Description|
340| -- | -- |
341| [OH_AudioVolumeManager](capi-ohaudio-oh-audiovolumemanager.md) *volumeManager | Pointer to an OH_AudioVolumeManager instance.|
342| [OH_AudioVolumeManager_OnRingerModeChangeCallback](capi-native-audio-volume-manager-h.md#oh_audiovolumemanager_onringermodechangecallback) callback | Pointer to the callback function passed by [OH_AudioVolumeManager_RegisterRingerModeChangeCallback](capi-native-audio-volume-manager-h.md#oh_audiovolumemanager_registerringermodechangecallback).|
343
344**Returns**
345
346| Type| Description|
347| -- | -- |
348| [OH_AudioCommon_Result](capi-native-audio-common-h.md#oh_audiocommon_result) | **AUDIOCOMMON_RESULT_SUCCESS**: The function is executed successfully.<br>**AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM**: The **volumeManager** or **callback** parameter is nullptr.<br>**AUDIOCOMMON_RESULT_ERROR_SYSTEM**: A system processing error occurs.|
349