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

2026-08-25 浏览 (1)

native_audio_manager.h

Overview

The file declares the functions related to an audio manager.

File to include: <ohaudio/native_audio_manager.h>

Library: libohaudio.so

System capability: SystemCapability.Multimedia.Audio.Core

Since: 12

Related module: OHAudio

Summary

Structs

Nametypedef KeywordDescription
OH_AudioManagerOH_AudioManagerDescribes an audio manager, which is used for audio management.

Functions

Nametypedef KeywordDescription
typedef void (*OH_AudioManager_OnAudioSceneChangeCallback)(void *userData, OH_AudioScene scene)OH_AudioManager_OnAudioSceneChangeCallbackDefines the prototype of the audio scene change callback function, which is passed in OH_AudioManager_RegisterAudioSceneChangeCallback.
OH_AudioCommon_Result OH_GetAudioManager(OH_AudioManager **audioManager)-Obtains an OH_AudioManager instance.
Before using the features related to the audio manager, you must obtain an OH_AudioManager instance.
OH_AudioCommon_Result OH_GetAudioScene(OH_AudioManager* manager, OH_AudioScene *scene)-Obtains the audio scene.
OH_AudioCommon_Result OH_AudioManager_RegisterAudioSceneChangeCallback(OH_AudioManager *manager, OH_AudioManager_OnAudioSceneChangeCallback callback, void *userData)-Registers the audio scene change callback function.
OH_AudioCommon_Result OH_AudioManager_UnregisterAudioSceneChangeCallback(OH_AudioManager *manager, OH_AudioManager_OnAudioSceneChangeCallback callback)-Unregisters the audio scene change callback function.

Function Description

OH_AudioManager_OnAudioSceneChangeCallback()

typedef void (*OH_AudioManager_OnAudioSceneChangeCallback) (void *userData, OH_AudioScene scene)

Description

Defines the prototype of the audio scene change callback function, which is passed in OH_AudioManager_RegisterAudioSceneChangeCallback.

Since: 20

Parameters

NameDescription
void *userDataPointer to user data.
OH_AudioScene sceneAudio scene after change.

OH_GetAudioManager()

OH_AudioCommon_Result OH_GetAudioManager(OH_AudioManager **audioManager)

Description

Obtains an OH_AudioManager instance.
Before using the features related to the audio manager, you must obtain an OH_AudioManager instance.

Since: 12

Parameters

NameDescription
OH_AudioManager **audioManagerDouble pointer to an OH_AudioManager, which is used to receive the audio manager instance created.

Returns

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

OH_GetAudioScene()

OH_AudioCommon_Result OH_GetAudioScene(OH_AudioManager* manager, OH_AudioScene *scene)

Description

Obtains the audio scene.

Since: 12

Parameters

NameDescription
OH_AudioManager* managerPointer to an OH_AudioManager instance, which is created by calling OH_GetAudioManager.
OH_AudioScene *scenePointer to an OH_AudioScene, which is used to receive the audio scene.

Returns

TypeDescription
OH_AudioCommon_ResultAUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully.
AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM:
1. The audioManager parameter is nullptr.
2. The scene parameter is nullptr.

OH_AudioManager_RegisterAudioSceneChangeCallback()

OH_AudioCommon_Result OH_AudioManager_RegisterAudioSceneChangeCallback(OH_AudioManager *manager,OH_AudioManager_OnAudioSceneChangeCallback callback, void *userData)

Description

Registers the audio scene change callback function.

Since: 20

Parameters

NameDescription
OH_AudioManager *managerPointer to an OH_AudioManager instance.
OH_AudioManager_OnAudioSceneChangeCallback callbackOH_AudioManager_OnAudioSceneChangeCallback invoked when the audio scene changes.
void *userDataPointer to user data.

Returns

TypeDescription
OH_AudioCommon_ResultAUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully.
AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM:
1. The manager parameter is nullptr.
2. The callback parameter is nullptr.
AUDIOCOMMON_RESULT_ERROR_SYSTEM: System error.

OH_AudioManager_UnregisterAudioSceneChangeCallback()

OH_AudioCommon_Result OH_AudioManager_UnregisterAudioSceneChangeCallback(OH_AudioManager *manager,OH_AudioManager_OnAudioSceneChangeCallback callback)

Description

Unregisters the audio scene change callback function.

Since: 20

Parameters

NameDescription
OH_AudioManager *managerPointer to an OH_AudioManager instance.
OH_AudioManager_OnAudioSceneChangeCallback callbackPointer to the callback function passed by OH_AudioManager_OnAudioSceneChangeCallback.

Returns

TypeDescription
OH_AudioCommon_ResultAUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully.
AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM:
1. The manager parameter is nullptr.
2. The callback parameter is nullptr.
AUDIOCOMMON_RESULT_ERROR_SYSTEM: System error.

你可能感兴趣的鸿蒙文章

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/qkKW9kFz