openharmony 鸿蒙 capi-native-audio-volume-manager-h

2026-08-25 浏览 (1)

native_audio_volume_manager.h

Overview

The file declares the functions related to an audio volume manager.

You can call the functions to create an audio volume manager.

File to include: <ohaudio/native_audio_volume_manager.h>

Library: libohaudio.so

System capability: SystemCapability.Multimedia.Audio.Core

Since: 20

Related module: OHAudio

Summary

Structs

Nametypedef KeywordDescription
OH_AudioVolumeManagerOH_AudioVolumeManagerDescribes an audio volume manager, which provides various functions for obtaining system volume information.

Functions

Nametypedef KeywordDescription
typedef void (*OH_AudioVolumeManager_OnStreamVolumeChangeCallback)(void *userData, OH_AudioStream_Usage usage, int32_t volumeLevel, bool updateUi)OH_AudioVolumeManager_OnStreamVolumeChangeCallbackDefines the prototype of the volume change callback function, which is passed in OH_AudioVolumeManager_RegisterStreamVolumeChangeCallback.
typedef void (*OH_AudioVolumeManager_OnRingerModeChangeCallback)(void *userData, OH_AudioRingerMode ringerMode)OH_AudioVolumeManager_OnRingerModeChangeCallbackDefines the prototype of the ringer mode change callback function, which is passed in OH_AudioVolumeManager_RegisterRingerModeChangeCallback.
OH_AudioCommon_Result OH_AudioManager_GetAudioVolumeManager(OH_AudioVolumeManager **volumeManager)-Obtains an OH_AudioVolumeManager instance.
OH_AudioCommon_Result OH_AudioVolumeManager_GetMaxVolumeByUsage(OH_AudioVolumeManager *volumeManager, OH_AudioStream_Usage usage, int32_t *maxVolumeLevel)-Obtains the maximum volume level of an audio stream of a specified usage type.
OH_AudioCommon_Result OH_AudioVolumeManager_GetMinVolumeByUsage(OH_AudioVolumeManager *volumeManager, OH_AudioStream_Usage usage, int32_t *minVolumeLevel)-Obtains the minimum volume level of an audio stream of a specified usage type.
OH_AudioCommon_Result OH_AudioVolumeManager_GetVolumeByUsage(OH_AudioVolumeManager *volumeManager, OH_AudioStream_Usage usage, int32_t *volumeLevel)-Obtains the system volume level of an audio stream of a specified usage type.
OH_AudioCommon_Result OH_AudioVolumeManager_IsMuteByUsage(OH_AudioVolumeManager *volumeManager, OH_AudioStream_Usage usage, bool *muted)-Checks whether an audio stream of a specified usage type is muted.
OH_AudioCommon_Result OH_AudioVolumeManager_RegisterStreamVolumeChangeCallback(OH_AudioVolumeManager *volumeManager, OH_AudioStream_Usage usage, OH_AudioVolumeManager_OnStreamVolumeChangeCallback callback, void *userData)-Registers the volume change callback function.
OH_AudioCommon_Result OH_AudioVolumeManager_UnregisterStreamVolumeChangeCallback(OH_AudioVolumeManager *volumeManager, OH_AudioVolumeManager_OnStreamVolumeChangeCallback callback)-Unregisters the volume change callback function.
OH_AudioCommon_Result OH_AudioVolumeManager_GetRingerMode(OH_AudioVolumeManager *volumeManager, OH_AudioRingerMode *ringerMode)-Obtains the ringer mode in use.
OH_AudioCommon_Result OH_AudioVolumeManager_RegisterRingerModeChangeCallback(OH_AudioVolumeManager *volumeManager, OH_AudioVolumeManager_OnRingerModeChangeCallback callback, void *userData)-Registers the ringer mode change callback function.
OH_AudioCommon_Result OH_AudioVolumeManager_UnregisterRingerModeChangeCallback(OH_AudioVolumeManager *volumeManager, OH_AudioVolumeManager_OnRingerModeChangeCallback callback)-Unregisters the ringer mode change callback function.

Function Description

OH_AudioVolumeManager_OnStreamVolumeChangeCallback()

typedef void (*OH_AudioVolumeManager_OnStreamVolumeChangeCallback)(void *userData, OH_AudioStream_Usage usage, int32_t volumeLevel, bool updateUi)

Description

Defines the prototype of the volume change callback function, which is passed in OH_AudioVolumeManager_RegisterStreamVolumeChangeCallback.

Since: 20

Parameters

NameDescription
void *userDataPointer to user data.
OH_AudioStream_Usage usageUsage type of the audio stream for which the volume is changed.
int32_t volumeLevelVolume level after change.
bool updateUiWhether to show the volume change on the UI. true to show, false otherwise.

OH_AudioVolumeManager_OnRingerModeChangeCallback()

typedef void (*OH_AudioVolumeManager_OnRingerModeChangeCallback)(void *userData, OH_AudioRingerMode ringerMode)

Description

Defines the prototype of the ringer mode change callback function, which is passed in OH_AudioVolumeManager_RegisterRingerModeChangeCallback.

Since: 20

Parameters

NameDescription
void *userDataPointer to user data.
OH_AudioRingerMode ringerModeRinger mode after change.

OH_AudioManager_GetAudioVolumeManager()

OH_AudioCommon_Result OH_AudioManager_GetAudioVolumeManager(OH_AudioVolumeManager **volumeManager)

Description

Obtains an OH_AudioVolumeManager instance.

Since: 20

Parameters

NameDescription
OH_AudioVolumeManager **volumeManagerDouble pointer to an OH_AudioVolumeManager instance, which is used to receive the created audio volume manager instance.

Returns

TypeDescription
OH_AudioCommon_ResultAUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully.
AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM: The volumeManager parameter is nullptr.

OH_AudioVolumeManager_GetMaxVolumeByUsage()

OH_AudioCommon_Result OH_AudioVolumeManager_GetMaxVolumeByUsage(OH_AudioVolumeManager *volumeManager, OH_AudioStream_Usage usage, int32_t *maxVolumeLevel)

Description

Obtains the maximum volume level of an audio stream of a specified usage type.

Since: 20

Parameters

NameDescription
OH_AudioVolumeManager *volumeManagerPointer to an OH_AudioVolumeManager instance.
OH_AudioStream_Usage usageUsage type of the audio stream.
int32_t *maxVolumeLevelPointer to the maximum volume level.

Returns

TypeDescription
OH_AudioCommon_ResultAUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully.
AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM: The volumeManager or maxVolumeLevel parameter is nullptr, or usage is invalid.
AUDIOCOMMON_RESULT_ERROR_SYSTEM: A system processing error occurs.

OH_AudioVolumeManager_GetMinVolumeByUsage()

OH_AudioCommon_Result OH_AudioVolumeManager_GetMinVolumeByUsage(OH_AudioVolumeManager *volumeManager, OH_AudioStream_Usage usage, int32_t *minVolumeLevel)

Description

Obtains the minimum volume level of an audio stream of a specified usage type.

Since: 20

Parameters

NameDescription
OH_AudioVolumeManager *volumeManagerPointer to an OH_AudioVolumeManager instance.
OH_AudioStream_Usage usageUsage type of the audio stream.
int32_t *minVolumeLevelPointer to the minimum volume level.

Returns

TypeDescription
OH_AudioCommon_ResultAUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully.
AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM: The volumeManager or minVolumeLevel parameter is nullptr, or usage is invalid.
AUDIOCOMMON_RESULT_ERROR_SYSTEM: A system processing error occurs.

OH_AudioVolumeManager_GetVolumeByUsage()

OH_AudioCommon_Result OH_AudioVolumeManager_GetVolumeByUsage(OH_AudioVolumeManager *volumeManager, OH_AudioStream_Usage usage, int32_t *volumeLevel)

Description

Obtains the system volume level of an audio stream of a specified usage type.

Since: 20

Parameters

NameDescription
OH_AudioVolumeManager *volumeManagerPointer to an OH_AudioVolumeManager instance.
OH_AudioStream_Usage usageUsage type of the audio stream.
int32_t *volumeLevelPointer to the system volume level.

Returns

TypeDescription
OH_AudioCommon_ResultAUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully.
AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM: The volumeManager or volumeLevel parameter is nullptr, or usage is invalid.
AUDIOCOMMON_RESULT_ERROR_SYSTEM: A system processing error occurs.

OH_AudioVolumeManager_IsMuteByUsage()

OH_AudioCommon_Result OH_AudioVolumeManager_IsMuteByUsage(OH_AudioVolumeManager *volumeManager, OH_AudioStream_Usage usage, bool *muted)

Description

Checks whether an audio stream of a specified usage type is muted.

Since: 20

Parameters

NameDescription
OH_AudioVolumeManager *volumeManagerPointer to an OH_AudioVolumeManager instance.
OH_AudioStream_Usage usageUsage type of the audio stream.
bool *mutedPointer to the check result for whether the audio stream is muted. true if muted, false otherwise.

Returns

TypeDescription
OH_AudioCommon_ResultAUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully.
AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM: The volumeManager or muted parameter is nullptr, or usage is invalid.
AUDIOCOMMON_RESULT_ERROR_SYSTEM: A system processing error occurs.

OH_AudioVolumeManager_RegisterStreamVolumeChangeCallback()

OH_AudioCommon_Result OH_AudioVolumeManager_RegisterStreamVolumeChangeCallback(OH_AudioVolumeManager *volumeManager, OH_AudioStream_Usage usage, OH_AudioVolumeManager_OnStreamVolumeChangeCallback callback, void *userData)

Description

Registers the volume change callback function.

Since: 20

Parameters

NameDescription
OH_AudioVolumeManager *volumeManagerPointer to an OH_AudioVolumeManager instance.
OH_AudioStream_Usage usageUsage type of the audio stream.
OH_AudioVolumeManager_OnStreamVolumeChangeCallback callbackOH_AudioVolumeManager_OnStreamVolumeChangeCallback, which is called when the volume of the audio stream changes.
void *userDataPointer to user data.

Returns

TypeDescription
OH_AudioCommon_ResultAUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully.
AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM: The volumeManager, usage, or callback parameter is nullptr, or usage is invalid.
AUDIOCOMMON_RESULT_ERROR_SYSTEM: A system processing error occurs.

OH_AudioVolumeManager_UnregisterStreamVolumeChangeCallback()

OH_AudioCommon_Result OH_AudioVolumeManager_UnregisterStreamVolumeChangeCallback(OH_AudioVolumeManager *volumeManager, OH_AudioVolumeManager_OnStreamVolumeChangeCallback callback)

Description

Unregisters the volume change callback function.

Since: 20

Parameters

NameDescription
OH_AudioVolumeManager *volumeManagerPointer to an OH_AudioVolumeManager instance.
OH_AudioVolumeManager_OnStreamVolumeChangeCallback callbackPointer to the callback function passed by OH_AudioVolumeManager_RegisterStreamVolumeChangeCallback.

Returns

TypeDescription
OH_AudioCommon_ResultAUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully.
AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM: The volumeManager or callback parameter is nullptr.
AUDIOCOMMON_RESULT_ERROR_SYSTEM: A system processing error occurs.

OH_AudioVolumeManager_GetRingerMode()

OH_AudioCommon_Result OH_AudioVolumeManager_GetRingerMode(OH_AudioVolumeManager *volumeManager, OH_AudioRingerMode *ringerMode)

Description

Obtains the ringer mode in use.

Since: 20

Parameters

NameDescription
OH_AudioVolumeManager *volumeManagerPointer to an OH_AudioVolumeManager instance.
OH_AudioRingerMode *ringerModePointer to the ringer mode.

Returns

TypeDescription
OH_AudioCommon_ResultAUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully.
AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM: The volumeManager or ringerMode parameter is nullptr.
AUDIOCOMMON_RESULT_ERROR_SYSTEM: A system processing error occurs.

OH_AudioVolumeManager_RegisterRingerModeChangeCallback()

OH_AudioCommon_Result OH_AudioVolumeManager_RegisterRingerModeChangeCallback(OH_AudioVolumeManager *volumeManager, OH_AudioVolumeManager_OnRingerModeChangeCallback callback, void *userData)

Description

Registers the ringer mode change callback function.

Since: 20

Parameters

NameDescription
OH_AudioVolumeManager *volumeManagerPointer to an OH_AudioVolumeManager instance.
OH_AudioVolumeManager_OnRingerModeChangeCallback callbackOH_AudioVolumeManager_OnRingerModeChangeCallback, which is called when the ringer mode changes.
void *userDataPointer to user data.

Returns

TypeDescription
OH_AudioCommon_ResultAUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully.
AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM: The volumeManager or callback parameter is nullptr.
AUDIOCOMMON_RESULT_ERROR_SYSTEM: A system processing error occurs.

OH_AudioVolumeManager_UnregisterRingerModeChangeCallback()

OH_AudioCommon_Result OH_AudioVolumeManager_UnregisterRingerModeChangeCallback(OH_AudioVolumeManager *volumeManager, OH_AudioVolumeManager_OnRingerModeChangeCallback callback)

Description

Unregisters the ringer mode change callback function.

Since: 20

Parameters

NameDescription
OH_AudioVolumeManager *volumeManagerPointer to an OH_AudioVolumeManager instance.
OH_AudioVolumeManager_OnRingerModeChangeCallback callbackPointer to the callback function passed by OH_AudioVolumeManager_RegisterRingerModeChangeCallback.

Returns

TypeDescription
OH_AudioCommon_ResultAUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully.
AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM: The volumeManager or callback parameter is nullptr.
AUDIOCOMMON_RESULT_ERROR_SYSTEM: A system processing error occurs.

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 capi-native-audiostreambuilder-h

openharmony 鸿蒙 capi-ohaudiosuite

openharmony 鸿蒙 js-apis-inner-multimedia-systemSoundPlayer

openharmony 鸿蒙 arkts-apis-audio-i

openharmony 鸿蒙 capi-ohaudio

openharmony 鸿蒙 capi-ohmidi

openharmony 鸿蒙 arkts-apis-audio-AudioManager

openharmony 鸿蒙 capi-ohaudiosuite-oh-audiosuite-spacerenderpositionparams

openharmony 鸿蒙 capi-ohaudio-oh-audiostreaminfo

openharmony 鸿蒙 errorcode-ringtone

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/nHoirJfk