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
| Name | typedef Keyword | Description |
|---|---|---|
| OH_AudioRoutingManager | OH_AudioRoutingManager | Describes an audio routing manager, which is used for audio routing management. |
Functions
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
| Name | Description |
|---|---|
| OH_AudioDevice_ChangeType type | Device connection status, which is OH_AudioDevice_ChangeType. The status can be either connected or disconnected. |
| OH_AudioDeviceDescriptorArray *audioDeviceDescriptorArray | Pointer 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
| Name | Description |
|---|---|
| OH_AudioRoutingManager **audioRoutingManager | Handle to the audio routing manager, which is obtained by calling OH_AudioManager_GetAudioRoutingManager. |
Returns
| Type | Description |
|---|---|
| OH_AudioCommon_Result | AUDIOCOMMON_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
| Name | Description |
|---|---|
| OH_AudioRoutingManager *audioRoutingManager | Handle to the audio routing manager, which is obtained by calling OH_AudioManager_GetAudioRoutingManager. |
| OH_AudioDevice_Flag deviceFlag | Device flag, which is used to filter the target device. |
| OH_AudioDeviceDescriptorArray **audioDeviceDescriptorArray | Double 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
| Type | Description |
|---|---|
| OH_AudioCommon_Result | AUDIOCOMMON_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
| Name | Description |
|---|---|
| OH_AudioRoutingManager *audioRoutingManager | Handle to the audio routing manager, which is obtained by calling OH_AudioManager_GetAudioRoutingManager. |
| OH_AudioDevice_Usage deviceUsage | Usage scenario of the audio device. For details about the available options, see OH_AudioDevice_Usage. |
| OH_AudioDeviceDescriptorArray **audioDeviceDescriptorArray | Double 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
| Type | Description |
|---|---|
| OH_AudioCommon_Result | AUDIOCOMMON_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
| Name | Description |
|---|---|
| OH_AudioRoutingManager *audioRoutingManager | Handle to the audio routing manager, which is obtained by calling OH_AudioManager_GetAudioRoutingManager. |
| OH_AudioStream_Usage streamUsage | Usage scenario of the audio output stream. For details about the available options, see OH_AudioStream_Usage. |
| OH_AudioDeviceDescriptorArray **audioDeviceDescriptorArray | Double 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
| Type | Description |
|---|---|
| OH_AudioCommon_Result | AUDIOCOMMON_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
| Name | Description |
|---|---|
| OH_AudioRoutingManager *audioRoutingManager | Handle to the audio routing manager, which is obtained by calling OH_AudioManager_GetAudioRoutingManager. |
| OH_AudioStream_SourceType sourceType | Usage scenario of the audio input stream. For details about the available options, see OH_AudioStream_SourceType. |
| OH_AudioDeviceDescriptorArray **audioDeviceDescriptorArray | Double 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
| Type | Description |
|---|---|
| OH_AudioCommon_Result | AUDIOCOMMON_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
| Name | Description |
|---|---|
| OH_AudioRoutingManager *audioRoutingManager | Handle to the audio routing manager, which is obtained by calling OH_AudioManager_GetAudioRoutingManager. |
| OH_AudioDevice_Flag deviceFlag | Device flag. |
| OH_AudioRoutingManager_OnDeviceChangedCallback callback | Callback function used to return the changed audio device descriptor. |
Returns
| Type | Description |
|---|---|
| OH_AudioCommon_Result | AUDIOCOMMON_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
| Name | Description |
|---|---|
| OH_AudioRoutingManager *audioRoutingManager | Handle to the audio routing manager, which is obtained by calling OH_AudioManager_GetAudioRoutingManager. |
| OH_AudioRoutingManager_OnDeviceChangedCallback callback | Callback function used to return the changed audio device descriptor. |
Returns
| Type | Description |
|---|---|
| OH_AudioCommon_Result | AUDIOCOMMON_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
| Name | Description |
|---|---|
| OH_AudioRoutingManager *audioRoutingManager | Handle to the audio routing manager, which is obtained by calling OH_AudioManager_GetAudioRoutingManager. |
| OH_AudioDeviceDescriptorArray *audioDeviceDescriptorArray | Pointer to the array of audio devices, which are obtained by calling OH_AudioRoutingManager_GetDevices. |
Returns
| Type | Description |
|---|---|
| OH_AudioCommon_Result | AUDIOCOMMON_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
| Name | Description |
|---|---|
| OH_AudioDeviceDescriptorArray *audioDeviceDescriptorArray | Pointer 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 status | Blocked status of the audio device. |
| void *userData | Pointer 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
| Name | Description |
|---|---|
| OH_AudioRoutingManager *audioRoutingManager | Handle to the audio routing manager, which is obtained by calling OH_AudioManager_GetAudioRoutingManager. |
| bool *supported | Check result for the support of microphone blocking detection. true if supported, false otherwise. |
Returns
| Type | Description |
|---|---|
| OH_AudioCommon_Result | AUDIOCOMMON_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
| Name | Description |
|---|---|
| OH_AudioRoutingManager *audioRoutingManager | Handle to the audio routing manager, which is obtained by calling OH_AudioManager_GetAudioRoutingManager. |
| OH_AudioRoutingManager_OnDeviceBlockStatusCallback callback | Pointer to the OH_AudioRoutingManager_OnDeviceBlockStatusCallback callback, which is used to return the blocked status. |
| void *userData | Pointer to user data. |
Returns
| Type | Description |
|---|---|
| OH_AudioCommon_Result | AUDIOCOMMON_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 鸿蒙 arkts-apis-audio-AudioManager
openharmony 鸿蒙 capi-ohaudiosuite-oh-audiosuite-spacerenderpositionparams