openharmony 鸿蒙 capi-native-audio-device-base-h

2026-08-25 浏览 (1)

native_audio_device_base.h

Overview

The file declares the types of audio device parameters and the functions for obtaining these parameters.

Library: libohaudio.so

File to include: <ohaudio/native_audio_device_base.h>

System capability: SystemCapability.Multimedia.Audio.Core

Since: 12

Related module: OHAudio

Summary

Structs

Nametypedef KeywordDescription
OH_AudioDeviceDescriptorArrayOH_AudioDeviceDescriptorArrayDescribes an array of audio device descriptors.
OH_AudioDeviceDescriptorOH_AudioDeviceDescriptorDescribes an audio device descriptor, which provides attributes of an audio device.

Enums

Nametypedef KeywordDescription
OH_AudioDevice_ChangeTypeOH_AudioDevice_ChangeTypeEnumerates the types of audio device changes.
OH_AudioDevice_RoleOH_AudioDevice_RoleEnumerates the roles of audio devices.
OH_AudioDevice_TypeOH_AudioDevice_TypeEnumerates the types of audio devices.
OH_AudioDevice_FlagOH_AudioDevice_FlagEnumerates the flags of audio devices.
OH_AudioDevice_UsageOH_AudioDevice_UsageEnumerates the usage scenarios of audio devices.
OH_AudioDevice_BlockStatusOH_AudioDevice_BlockStatusEnumerates the blocked status of audio devices. By default, an audio device is not blocked.

Functions

NameDescription
OH_AudioCommon_Result OH_AudioDeviceDescriptor_GetDeviceRole(OH_AudioDeviceDescriptor *audioDeviceDescriptor, OH_AudioDevice_Role *deviceRole)Obtains the device role based on an audio device descriptor.
OH_AudioCommon_Result OH_AudioDeviceDescriptor_GetDeviceType(OH_AudioDeviceDescriptor *audioDeviceDescriptor, OH_AudioDevice_Type *deviceType)Obtains the device type based on an audio device descriptor.
OH_AudioCommon_Result OH_AudioDeviceDescriptor_GetDeviceId(OH_AudioDeviceDescriptor *audioDeviceDescriptor, uint32_t *id)Obtains the device ID based on an audio device descriptor.
OH_AudioCommon_Result OH_AudioDeviceDescriptor_GetDeviceName(OH_AudioDeviceDescriptor *audioDeviceDescriptor, char **name)Obtains the device name based on an audio device descriptor.
OH_AudioCommon_Result OH_AudioDeviceDescriptor_GetDeviceAddress(OH_AudioDeviceDescriptor *audioDeviceDescriptor, char **address)Obtains the device address based on an audio device descriptor.
OH_AudioCommon_Result OH_AudioDeviceDescriptor_GetDeviceSampleRates(OH_AudioDeviceDescriptor *audioDeviceDescriptor, uint32_t **sampleRates, uint32_t *size)Obtains the sample rates based on an audio device descriptor.
OH_AudioCommon_Result OH_AudioDeviceDescriptor_GetDeviceChannelCounts(OH_AudioDeviceDescriptor *audioDeviceDescriptor, uint32_t **channelCounts, uint32_t *size)Obtains an array that holds the number of device channels based on an audio device descriptor.
OH_AudioCommon_Result OH_AudioDeviceDescriptor_GetDeviceDisplayName(OH_AudioDeviceDescriptor *audioDeviceDescriptor, char **displayName)Obtains the device display name based on an audio device descriptor.
OH_AudioCommon_Result OH_AudioDeviceDescriptor_GetDeviceEncodingTypes(OH_AudioDeviceDescriptor *audioDeviceDescriptor, OH_AudioStream_EncodingType **encodingTypes, uint32_t *size)Obtains the device encoding types based on an audio device descriptor.

Enum Description

OH_AudioDevice_ChangeType

enum OH_AudioDevice_ChangeType

Description

Enumerates the types of audio device changes.

Since: 12

Enum ItemDescription
AUDIO_DEVICE_CHANGE_TYPE_CONNECT = 0Device connected.
AUDIO_DEVICE_CHANGE_TYPE_DISCONNECT = 1Device disconnected.

OH_AudioDevice_Role

enum OH_AudioDevice_Role

Description

Enumerates the roles of audio devices.

Since: 12

Enum ItemDescription
AUDIO_DEVICE_ROLE_INPUT = 1Input device.
AUDIO_DEVICE_ROLE_OUTPUT = 2Output device.

OH_AudioDevice_Type

enum OH_AudioDevice_Type

Description

Enumerates the types of audio devices.

Since: 12

Enum ItemDescription
AUDIO_DEVICE_TYPE_INVALID = 0Invalid device.
AUDIO_DEVICE_TYPE_EARPIECE = 1Earpiece.
AUDIO_DEVICE_TYPE_SPEAKER = 2Speaker.
AUDIO_DEVICE_TYPE_WIRED_HEADSET = 3Wired headset with a microphone.
AUDIO_DEVICE_TYPE_WIRED_HEADPHONES = 4Wired headset without microphone.
AUDIO_DEVICE_TYPE_BLUETOOTH_SCO = 7Bluetooth device using Synchronous Connection-oriented (SCO) links.
AUDIO_DEVICE_TYPE_BLUETOOTH_A2DP = 8Bluetooth device using Advanced Audio Distribution Profile (A2DP) links.
AUDIO_DEVICE_TYPE_MIC = 15Microphone.
AUDIO_DEVICE_TYPE_USB_HEADSET = 22USB headset.
AUDIO_DEVICE_TYPE_DISPLAY_PORT = 23Display port device.
AUDIO_DEVICE_TYPE_REMOTE_CAST = 24Remote cast device.
AUDIO_DEVICE_TYPE_USB_DEVICE = 25USB device (excluding USB headsets).
Since: 18
AUDIO_DEVICE_TYPE_ACCESSORY = 26Accessory device, such as the microphone on a remote control.
Since: 19
AUDIO_DEVICE_TYPE_HDMI = 27HDMI device (such as HDMI, ARC, and eARC).
Since: 19
AUDIO_DEVICE_TYPE_LINE_DIGITAL = 28Wired digital device (such as S/PDIF)
Since: 19
AUDIO_DEVICE_TYPE_HEARING_AID = 30Hearing aid device.
Since: 20
AUDIO_DEVICE_TYPE_NEARLINK = 31NearLink device.
Since: 20
AUDIO_DEVICE_TYPE_DEFAULT = 1000Default device type.

OH_AudioDevice_Flag

enum OH_AudioDevice_Flag

Description

Enumerates the flags of audio devices.

Since: 12

Enum ItemDescription
AUDIO_DEVICE_FLAG_NONE = 0No flag.
AUDIO_DEVICE_FLAG_OUTPUT = 1Output device.
AUDIO_DEVICE_FLAG_INPUT = 2Input device.
AUDIO_DEVICE_FLAG_ALL = 3All devices.

OH_AudioDevice_Usage

enum OH_AudioDevice_Usage

Description

Enumerates the usage scenarios of audio devices.

Since: 12

Enum ItemDescription
AUDIO_DEVICE_USAGE_MEDIA_OUTPUT = 1Media output device.
AUDIO_DEVICE_USAGE_MEDIA_INPUT = 2Media input device.
AUDIO_DEVICE_USAGE_MEDIA_ALL = 3All media devices.
AUDIO_DEVICE_USAGE_CALL_OUTPUT = 4Call output device.
AUDIO_DEVICE_USAGE_CALL_INPUT = 8Call input device.
AUDIO_DEVICE_USAGE_CALL_ALL = 12All call devices.

OH_AudioDevice_BlockStatus

enum OH_AudioDevice_BlockStatus

Description

Enumerates the blocked status of audio devices. By default, an audio device is not blocked.

Since: 13

Enum ItemDescription
AUDIO_DEVICE_UNBLOCKED = 0The audio device is not blocked.
AUDIO_DEVICE_BLOCKED = 1The audio device is blocked.

Function Description

OH_AudioDeviceDescriptor_GetDeviceRole()

OH_AudioCommon_Result OH_AudioDeviceDescriptor_GetDeviceRole(OH_AudioDeviceDescriptor *audioDeviceDescriptor,OH_AudioDevice_Role *deviceRole)

Description

Obtains the device role based on an audio device descriptor.

Since: 12

Parameters

NameDescription
OH_AudioDeviceDescriptor *audioDeviceDescriptorPointer to an audio device descriptor, which is obtained by calling OH_AudioRoutingManager_GetDevices or OH_AudioRoutingManager_OnDeviceChangedCallback.
OH_AudioDevice_Role *deviceRolePointer to the device role. This variable, which will store the device role value, points to an OH_AudioDevice_Role.

Returns

TypeDescription
OH_AudioCommon_ResultOperation result. AUDIOCOMMON_RESULT_SUCCESS is returned if the operation is successful; AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM is returned otherwise.

OH_AudioDeviceDescriptor_GetDeviceType()

OH_AudioCommon_Result OH_AudioDeviceDescriptor_GetDeviceType(OH_AudioDeviceDescriptor *audioDeviceDescriptor,OH_AudioDevice_Type *deviceType)

Description

Obtains the device type based on an audio device descriptor.

Since: 12

Parameters

NameDescription
OH_AudioDeviceDescriptor *audioDeviceDescriptorPointer to an audio device descriptor, which is obtained by calling OH_AudioRoutingManager_GetDevices or OH_AudioRoutingManager_OnDeviceChangedCallback.
OH_AudioDevice_Type *deviceTypePointer to the device type. This variable, which will store the device type value, points to an OH_AudioDevice_Type.

Returns

TypeDescription
OH_AudioCommon_ResultOperation result. AUDIOCOMMON_RESULT_SUCCESS is returned if the operation is successful; AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM is returned otherwise.

OH_AudioDeviceDescriptor_GetDeviceId()

OH_AudioCommon_Result OH_AudioDeviceDescriptor_GetDeviceId(OH_AudioDeviceDescriptor *audioDeviceDescriptor,uint32_t *id)

Description

Obtains the device ID based on an audio device descriptor.

Since: 12

Parameters

NameDescription
OH_AudioDeviceDescriptor *audioDeviceDescriptorPointer to an audio device descriptor, which is obtained by calling OH_AudioRoutingManager_GetDevices or OH_AudioRoutingManager_OnDeviceChangedCallback.
uint32_t *idPointer to the device ID, which is a variable for setting the device role.

Returns

TypeDescription
OH_AudioCommon_ResultOperation result. AUDIOCOMMON_RESULT_SUCCESS is returned if the operation is successful; AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM is returned otherwise.

OH_AudioDeviceDescriptor_GetDeviceName()

OH_AudioCommon_Result OH_AudioDeviceDescriptor_GetDeviceName(OH_AudioDeviceDescriptor *audioDeviceDescriptor,char **name)

Description

Obtains the device name based on an audio device descriptor.

Since: 12

Parameters

NameDescription
OH_AudioDeviceDescriptor *audioDeviceDescriptorPointer to an audio device descriptor, which is obtained by calling OH_AudioRoutingManager_GetDevices or OH_AudioRoutingManager_OnDeviceChangedCallback.
char **nameDouble pointer to the device name.
Do not release the pointer to the device name separately. Instead, call OH_AudioRoutingManager_ReleaseDevices to release all the device descriptors when they are no longer needed.

Returns

TypeDescription
OH_AudioCommon_ResultOperation result. AUDIOCOMMON_RESULT_SUCCESS is returned if the operation is successful; AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM is returned otherwise.

OH_AudioDeviceDescriptor_GetDeviceAddress()

OH_AudioCommon_Result OH_AudioDeviceDescriptor_GetDeviceAddress(OH_AudioDeviceDescriptor *audioDeviceDescriptor,char **address)

Description

Obtains the device address based on an audio device descriptor.

Since: 12

Parameters

NameDescription
OH_AudioDeviceDescriptor *audioDeviceDescriptorPointer to an audio device descriptor, which is obtained by calling OH_AudioRoutingManager_GetDevices or OH_AudioRoutingManager_OnDeviceChangedCallback.
char **addressDouble pointer to the MAC address of the device.
Do not release the pointer to the MAC address separately. Instead, call OH_AudioRoutingManager_ReleaseDevices to release all the device descriptors when they are no longer needed.

Returns

TypeDescription
OH_AudioCommon_ResultOperation result. AUDIOCOMMON_RESULT_SUCCESS is returned if the operation is successful; AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM is returned otherwise.

OH_AudioDeviceDescriptor_GetDeviceSampleRates()

OH_AudioCommon_Result OH_AudioDeviceDescriptor_GetDeviceSampleRates(OH_AudioDeviceDescriptor *audioDeviceDescriptor,uint32_t **sampleRates, uint32_t *size)

Description

Obtains the sample rates based on an audio device descriptor.

Since: 12

Parameters

NameDescription
OH_AudioDeviceDescriptor *audioDeviceDescriptorPointer to an audio device descriptor, which is obtained by calling OH_AudioRoutingManager_GetDevices or OH_AudioRoutingManager_OnDeviceChangedCallback.
uint32_t **sampleRatesDouble pointer to the array of sample rates.
Do not release the pointer to the sample rates separately. Instead, call OH_AudioRoutingManager_ReleaseDevices to release all the device descriptors when they are no longer needed.
uint32_t *sizePointer to the size of the array.

Returns

TypeDescription
OH_AudioCommon_ResultOperation result. AUDIOCOMMON_RESULT_SUCCESS is returned if the operation is successful; AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM is returned otherwise.

OH_AudioDeviceDescriptor_GetDeviceChannelCounts()

OH_AudioCommon_Result OH_AudioDeviceDescriptor_GetDeviceChannelCounts(OH_AudioDeviceDescriptor *audioDeviceDescriptor,uint32_t **channelCounts, uint32_t *size)

Description

Obtains an array that holds the number of device channels based on an audio device descriptor.

Since: 12

Parameters

NameDescription
OH_AudioDeviceDescriptor *audioDeviceDescriptorPointer to an audio device descriptor, which is obtained by calling OH_AudioRoutingManager_GetDevices or OH_AudioRoutingManager_OnDeviceChangedCallback.
uint32_t **channelCountsDouble pointer to the array that holds the channel counts.
Do not release the pointer to the channel counts separately. Instead, call OH_AudioRoutingManager_ReleaseDevices to release all the device descriptors when they are no longer needed.
uint32_t *sizePointer to the size of the array.

Returns

TypeDescription
OH_AudioCommon_ResultOperation result. AUDIOCOMMON_RESULT_SUCCESS is returned if the operation is successful; AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM is returned otherwise.

OH_AudioDeviceDescriptor_GetDeviceDisplayName()

OH_AudioCommon_Result OH_AudioDeviceDescriptor_GetDeviceDisplayName(OH_AudioDeviceDescriptor *audioDeviceDescriptor,char **displayName)

Description

Obtains the device display name based on an audio device descriptor.

Since: 12

Parameters

NameDescription
OH_AudioDeviceDescriptor *audioDeviceDescriptorPointer to an audio device descriptor, which is obtained by calling OH_AudioRoutingManager_GetDevices or OH_AudioRoutingManager_OnDeviceChangedCallback.
char **displayNameDouble pointer to the display name.
Do not release the pointer to the display name separately. Instead, call OH_AudioRoutingManager_ReleaseDevices to release all the device descriptors when they are no longer needed.

Returns

TypeDescription
OH_AudioCommon_ResultOperation result. AUDIOCOMMON_RESULT_SUCCESS is returned if the operation is successful; AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM is returned otherwise.

OH_AudioDeviceDescriptor_GetDeviceEncodingTypes()

OH_AudioCommon_Result OH_AudioDeviceDescriptor_GetDeviceEncodingTypes(OH_AudioDeviceDescriptor *audioDeviceDescriptor,OH_AudioStream_EncodingType **encodingTypes, uint32_t *size)

Description

Obtains the device encoding types based on an audio device descriptor.

Since: 12

Parameters

NameDescription
OH_AudioDeviceDescriptor *audioDeviceDescriptorPointer to an audio device descriptor, which is obtained by calling OH_AudioRoutingManager_GetDevices or OH_AudioRoutingManager_OnDeviceChangedCallback.
OH_AudioStream_EncodingType **encodingTypesDouble pointer to the device encoding type. For details about the available options, see OH_AudioStream_EncodingType.
Do not release the pointer to the encoding type separately. Instead, call OH_AudioRoutingManager_ReleaseDevices to release all the device descriptors when they are no longer needed.
uint32_t *sizePointer to the size of the device encoding type.

Returns

TypeDescription
OH_AudioCommon_ResultOperation result. AUDIOCOMMON_RESULT_SUCCESS is returned if the operation is successful; AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM is returned otherwise.

你可能感兴趣的鸿蒙文章

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