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

2026-08-25 浏览 (1)

native_audio_routing_manager.h

Overview

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

You can use the functions to create an audio routing manager, register and deregister a callback to listen for device connection status changes, and release devices.

File to include: <ohaudio/native_audio_routing_manager.h>

Library: libohaudio.so

System capability: SystemCapability.Multimedia.Audio.Core

Since: 12

Related module: OHAudio

Summary

Structs

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

Functions

Nametypedef KeywordDescription
typedef int32_t (*OH_AudioRoutingManager_OnDeviceChangedCallback)(OH_AudioDevice_ChangeType type, OH_AudioDeviceDescriptorArray *audioDeviceDescriptorArray)OH_AudioRoutingManager_OnDeviceChangedCallbackDefines a pointer to the callback that returns the changed audio device descriptor (possibly multiple descriptors).
OH_AudioCommon_Result OH_AudioManager_GetAudioRoutingManager(OH_AudioRoutingManager **audioRoutingManager)-Obtains the handle to an audio routing manager. The handle should be set as the first parameter in the routing-related functions.
OH_AudioCommon_Result OH_AudioRoutingManager_GetDevices(OH_AudioRoutingManager *audioRoutingManager, OH_AudioDevice_Flag deviceFlag, OH_AudioDeviceDescriptorArray **audioDeviceDescriptorArray)-Obtains available devices based on the device flag.
OH_AudioCommon_Result OH_AudioRoutingManager_GetAvailableDevices(OH_AudioRoutingManager *audioRoutingManager, OH_AudioDevice_Usage deviceUsage, OH_AudioDeviceDescriptorArray **audioDeviceDescriptorArray)-Obtains the available audio devices.
OH_AudioCommon_Result OH_AudioRoutingManager_GetPreferredOutputDevice(OH_AudioRoutingManager *audioRoutingManager, OH_AudioStream_Usage streamUsage, OH_AudioDeviceDescriptorArray **audioDeviceDescriptorArray)-Obtains the output device with the highest priority based on the usage scenario of an audio output stream.
OH_AudioCommon_Result OH_AudioRoutingManager_GetPreferredInputDevice(OH_AudioRoutingManager *audioRoutingManager, OH_AudioStream_SourceType sourceType, OH_AudioDeviceDescriptorArray **audioDeviceDescriptorArray)-Obtains the input device with the highest priority based on the usage scenario of an audio input stream.
OH_AudioCommon_Result OH_AudioRoutingManager_RegisterDeviceChangeCallback(OH_AudioRoutingManager *audioRoutingManager, OH_AudioDevice_Flag deviceFlag, OH_AudioRoutingManager_OnDeviceChangedCallback callback)-Registers a callback to listen for device changes of an audio routing manager.
OH_AudioCommon_Result OH_AudioRoutingManager_UnregisterDeviceChangeCallback(OH_AudioRoutingManager *audioRoutingManager, OH_AudioRoutingManager_OnDeviceChangedCallback callback)-Unregisters the callback used to listen for device changes of an audio routing manager.
OH_AudioCommon_Result OH_AudioRoutingManager_ReleaseDevices(OH_AudioRoutingManager *audioRoutingManager, OH_AudioDeviceDescriptorArray *audioDeviceDescriptorArray)-Releases audio devices available for an audio routing manager.
typedef void (*OH_AudioRoutingManager_OnDeviceBlockStatusCallback)(OH_AudioDeviceDescriptorArray *audioDeviceDescriptorArray, OH_AudioDevice_BlockStatus status, void *userData)OH_AudioRoutingManager_OnDeviceBlockStatusCallbackDefines a pointer to the callback that returns the blocked status of one or more audio devices.
OH_AudioCommon_Result OH_AudioRoutingManager_IsMicBlockDetectionSupported(OH_AudioRoutingManager *audioRoutingManager, bool *supported)-Checks whether the current device supports microphone blocking detection.
OH_AudioCommon_Result OH_AudioRoutingManager_SetMicBlockStatusCallback(OH_AudioRoutingManager *audioRoutingManager, OH_AudioRoutingManager_OnDeviceBlockStatusCallback callback, void *userData)-Sets a callback function to be invoked when the microphone's blocked status is changed.
Before using this function, check whether the current device supports microphone blocking detection. The application receives a callback only when the microphone is used for recording and the microphone's blocked status changes. Currently, this function takes effect only for the microphone on the local device.

Function Description

OH_AudioRoutingManager_OnDeviceChangedCallback()

typedef int32_t (*OH_AudioRoutingManager_OnDeviceChangedCallback)(OH_AudioDevice_ChangeType type, OH_AudioDeviceDescriptorArray *audioDeviceDescriptorArray
)

Description

Defines a pointer to the callback that returns the changed audio device descriptor (possibly multiple descriptors).

Since: 12

Parameters

NameDescription
OH_AudioDevice_ChangeType typeDevice connection status, which is OH_AudioDevice_ChangeType. The status can be either connected or disconnected.
OH_AudioDeviceDescriptorArray *audioDeviceDescriptorArrayPointer to the audio device descriptors in the array. For details, see OH_AudioDeviceDescriptorArray. Do not release the pointer to the audioDeviceDescriptorArray struct separately. Instead, call OH_AudioRoutingManager_ReleaseDevices to release the DeviceDescriptor array.

OH_AudioManager_GetAudioRoutingManager()

OH_AudioCommon_Result OH_AudioManager_GetAudioRoutingManager(OH_AudioRoutingManager **audioRoutingManager)

Description

Obtains the handle to an audio routing manager. The handle should be set as the first parameter in the routing-related functions.

Since: 12

Parameters

NameDescription
OH_AudioRoutingManager **audioRoutingManagerHandle to the audio routing manager, which is obtained by calling OH_AudioManager_GetAudioRoutingManager.

Returns

TypeDescription
OH_AudioCommon_ResultAUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully.

OH_AudioRoutingManager_GetDevices()

OH_AudioCommon_Result OH_AudioRoutingManager_GetDevices(OH_AudioRoutingManager *audioRoutingManager, OH_AudioDevice_Flag deviceFlag, OH_AudioDeviceDescriptorArray **audioDeviceDescriptorArray)

Description

Obtains available devices based on the device flag.

Since: 12

Parameters

NameDescription
OH_AudioRoutingManager *audioRoutingManagerHandle to the audio routing manager, which is obtained by calling OH_AudioManager_GetAudioRoutingManager.
OH_AudioDevice_Flag deviceFlagDevice flag, which is used to filter the target device.
OH_AudioDeviceDescriptorArray **audioDeviceDescriptorArrayDouble pointer to the audio device descriptors in the array. Do not release the pointer to the audioDeviceDescriptorArray struct separately. Instead, call OH_AudioRoutingManager_ReleaseDevices to release the DeviceDescriptor array.

Returns

TypeDescription
OH_AudioCommon_ResultAUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully.
AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM:
1. The audioRoutingManager parameter is nullptr.
2. The deviceFlag parameter is set to an invalid value.
3. The audioDeviceDescriptorArray parameter is nullptr.
AUDIOCOMMON_RESULT_ERROR_NO_MEMORY: The memory is insufficient.

OH_AudioRoutingManager_GetAvailableDevices()

OH_AudioCommon_Result OH_AudioRoutingManager_GetAvailableDevices(OH_AudioRoutingManager *audioRoutingManager, OH_AudioDevice_Usage deviceUsage, OH_AudioDeviceDescriptorArray **audioDeviceDescriptorArray)

Description

Obtains the available audio devices.

Since: 12

Parameters

NameDescription
OH_AudioRoutingManager *audioRoutingManagerHandle to the audio routing manager, which is obtained by calling OH_AudioManager_GetAudioRoutingManager.
OH_AudioDevice_Usage deviceUsageUsage scenario of the audio device. For details about the available options, see OH_AudioDevice_Usage.
OH_AudioDeviceDescriptorArray **audioDeviceDescriptorArrayDouble pointer to the audio device descriptors in the array. Do not release the pointer to the audioDeviceDescriptorArray struct separately. Instead, call OH_AudioRoutingManager_ReleaseDevices to release the DeviceDescriptor array.

Returns

TypeDescription
OH_AudioCommon_ResultAUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully.
AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM:
1. The audioRoutingManager parameter is nullptr.
2. The deviceUsage parameter is invalid.
3. The audioDeviceDescriptorArray parameter is nullptr.
AUDIOCOMMON_RESULT_ERROR_NO_MEMORY: The memory is insufficient.

OH_AudioRoutingManager_GetPreferredOutputDevice()

OH_AudioCommon_Result OH_AudioRoutingManager_GetPreferredOutputDevice(OH_AudioRoutingManager *audioRoutingManager, OH_AudioStream_Usage streamUsage, OH_AudioDeviceDescriptorArray **audioDeviceDescriptorArray)

Description

Obtains the output device with the highest priority based on the usage scenario of an audio output stream.

Since: 12

Parameters

NameDescription
OH_AudioRoutingManager *audioRoutingManagerHandle to the audio routing manager, which is obtained by calling OH_AudioManager_GetAudioRoutingManager.
OH_AudioStream_Usage streamUsageUsage scenario of the audio output stream. For details about the available options, see OH_AudioStream_Usage.
OH_AudioDeviceDescriptorArray **audioDeviceDescriptorArrayDouble pointer to the audio device descriptors in the array. Do not release the pointer to the audioDeviceDescriptorArray struct separately. Instead, call OH_AudioRoutingManager_ReleaseDevices to release the DeviceDescriptor array.

Returns

TypeDescription
OH_AudioCommon_ResultAUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully.
AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM:
1. The audioRoutingManager parameter is nullptr.
2. The streamUsage parameter is invalid.
3. The audioDeviceDescriptorArray parameter is nullptr.
AUDIOCOMMON_RESULT_ERROR_NO_MEMORY: The memory is insufficient.

OH_AudioRoutingManager_GetPreferredInputDevice()

OH_AudioCommon_Result OH_AudioRoutingManager_GetPreferredInputDevice(OH_AudioRoutingManager *audioRoutingManager, OH_AudioStream_SourceType sourceType, OH_AudioDeviceDescriptorArray **audioDeviceDescriptorArray)

Description

Obtains the input device with the highest priority based on the usage scenario of an audio input stream.

Since: 12

Parameters

NameDescription
OH_AudioRoutingManager *audioRoutingManagerHandle to the audio routing manager, which is obtained by calling OH_AudioManager_GetAudioRoutingManager.
OH_AudioStream_SourceType sourceTypeUsage scenario of the audio input stream. For details about the available options, see OH_AudioStream_SourceType.
OH_AudioDeviceDescriptorArray **audioDeviceDescriptorArrayDouble pointer to the audio device descriptors in the array. Do not release the pointer to the audioDeviceDescriptorArray struct separately. Instead, call OH_AudioRoutingManager_ReleaseDevices to release the DeviceDescriptor array.

Returns

TypeDescription
OH_AudioCommon_ResultAUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully.
AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM:
1. The audioRoutingManager parameter is nullptr.
2. The sourceType parameter is invalid.
3. The audioDeviceDescriptorArray parameter is nullptr.
AUDIOCOMMON_RESULT_ERROR_NO_MEMORY: The memory is insufficient.

OH_AudioRoutingManager_RegisterDeviceChangeCallback()

OH_AudioCommon_Result OH_AudioRoutingManager_RegisterDeviceChangeCallback(OH_AudioRoutingManager *audioRoutingManager, OH_AudioDevice_Flag deviceFlag, OH_AudioRoutingManager_OnDeviceChangedCallback callback)

Description

Registers a callback to listen for device changes of an audio routing manager.

Since: 12

Parameters

NameDescription
OH_AudioRoutingManager *audioRoutingManagerHandle to the audio routing manager, which is obtained by calling OH_AudioManager_GetAudioRoutingManager.
OH_AudioDevice_Flag deviceFlagDevice flag.
OH_AudioRoutingManager_OnDeviceChangedCallback callbackCallback function used to return the changed audio device descriptor.

Returns

TypeDescription
OH_AudioCommon_ResultAUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully.
AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM:
1. The audioRoutingManager parameter is nullptr.
2. The deviceFlag parameter is set to an invalid value.
3. The callback parameter is nullptr.

OH_AudioRoutingManager_UnregisterDeviceChangeCallback()

OH_AudioCommon_Result OH_AudioRoutingManager_UnregisterDeviceChangeCallback(OH_AudioRoutingManager *audioRoutingManager, OH_AudioRoutingManager_OnDeviceChangedCallback callback)

Description

Unregisters the callback used to listen for device changes of an audio routing manager.

Since: 12

Parameters

NameDescription
OH_AudioRoutingManager *audioRoutingManagerHandle to the audio routing manager, which is obtained by calling OH_AudioManager_GetAudioRoutingManager.
OH_AudioRoutingManager_OnDeviceChangedCallback callbackCallback function used to return the changed audio device descriptor.

Returns

TypeDescription
OH_AudioCommon_ResultAUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully.
AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM:
1. The audioRoutingManager parameter is nullptr.
2. The callback parameter is nullptr.

OH_AudioRoutingManager_ReleaseDevices()

OH_AudioCommon_Result OH_AudioRoutingManager_ReleaseDevices(OH_AudioRoutingManager *audioRoutingManager, OH_AudioDeviceDescriptorArray *audioDeviceDescriptorArray)

Description

Releases audio devices available for an audio routing manager.

Since: 12

Parameters

NameDescription
OH_AudioRoutingManager *audioRoutingManagerHandle to the audio routing manager, which is obtained by calling OH_AudioManager_GetAudioRoutingManager.
OH_AudioDeviceDescriptorArray *audioDeviceDescriptorArrayPointer to the array of audio devices, which are obtained by calling OH_AudioRoutingManager_GetDevices.

Returns

TypeDescription
OH_AudioCommon_ResultAUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully.
AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM:
1. The audioRoutingManager parameter is nullptr.
2. The audioDeviceDescriptorArray parameter is nullptr.

OH_AudioRoutingManager_OnDeviceBlockStatusCallback()

typedef void (*OH_AudioRoutingManager_OnDeviceBlockStatusCallback)(OH_AudioDeviceDescriptorArray *audioDeviceDescriptorArray, OH_AudioDevice_BlockStatus status, void *userData)

Description

Defines a pointer to the callback that returns the blocked status of one or more audio devices.

Since: 13

Parameters

NameDescription
OH_AudioDeviceDescriptorArray *audioDeviceDescriptorArrayPointer to the array of audio devices, which are obtained by calling OH_AudioRoutingManager_GetDevices. Do not release the pointer to the audioDeviceDescriptorArray struct separately. Instead, call OH_AudioRoutingManager_ReleaseDevices to release the DeviceDescriptor array.
OH_AudioDevice_BlockStatus statusBlocked status of the audio device.
void *userDataPointer to user data.

OH_AudioRoutingManager_IsMicBlockDetectionSupported()

OH_AudioCommon_Result OH_AudioRoutingManager_IsMicBlockDetectionSupported(OH_AudioRoutingManager *audioRoutingManager, bool *supported)

Description

Checks whether the current device supports microphone blocking detection.

Since: 13

Parameters

NameDescription
OH_AudioRoutingManager *audioRoutingManagerHandle to the audio routing manager, which is obtained by calling OH_AudioManager_GetAudioRoutingManager.
bool *supportedCheck result for the support of microphone blocking detection. true if supported, false otherwise.

Returns

TypeDescription
OH_AudioCommon_ResultAUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully.
AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM:
1. The audioRoutingManager parameter is nullptr.
2. The supported parameter is nullptr.

OH_AudioRoutingManager_SetMicBlockStatusCallback()

OH_AudioCommon_Result OH_AudioRoutingManager_SetMicBlockStatusCallback(OH_AudioRoutingManager *audioRoutingManager, OH_AudioRoutingManager_OnDeviceBlockStatusCallback callback, void *userData)

Description

Sets a callback function to be invoked when the microphone's blocked status is changed.

Before using this function, check whether the current device supports microphone blocking detection. The application receives a callback only when the microphone is used for recording and the microphone's blocked status changes. Currently, this function takes effect only for the microphone on the local device.

Since: 13

Parameters

NameDescription
OH_AudioRoutingManager *audioRoutingManagerHandle to the audio routing manager, which is obtained by calling OH_AudioManager_GetAudioRoutingManager.
OH_AudioRoutingManager_OnDeviceBlockStatusCallback callbackPointer to the OH_AudioRoutingManager_OnDeviceBlockStatusCallback callback, which is used to return the blocked status.
void *userDataPointer to user data.

Returns

TypeDescription
OH_AudioCommon_ResultAUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully.
AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM:
1. The audioRoutingManager parameter is nullptr.
2. The callback parameter is nullptr.

你可能感兴趣的鸿蒙文章

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