native_audio_session_manager.h
Overview
The file declares the functions related to an audio session manager.
You can call the functions to create an audio session manager, activate or deactivate an audio session, check whether an audio session is activated, and listen for audio session deactivation events.
File to include: <ohaudio/native_audio_session_manager.h>
Library: libohaudio.so
System capability: SystemCapability.Multimedia.Audio.Core
Since: 12
Related module: OHAudio
Summary
Structs
| Name | typedef Keyword | Description |
|---|---|---|
| OH_AudioSession_DeactivatedEvent | OH_AudioSession_DeactivatedEvent | Describes the event indicating that an audio session is deactivated. |
| OH_AudioSession_StateChangedEvent | OH_AudioSession_StateChangedEvent | Describes the event indicating that the audio session state changes. |
| OH_AudioSessionManager | OH_AudioSessionManager | Describes an audio session manager, which is used to manage audio sessions. |
Enums
| Name | typedef Keyword | Description |
|---|---|---|
| OH_AudioSession_Scene | OH_AudioSession_Scene | Enumerates the audio session scenes. |
| OH_AudioSession_StateChangeHint | OH_AudioSession_StateChangeHint | Enumerates the hints for audio session state changes. |
| OH_AudioSession_OutputDeviceChangeRecommendedAction | OH_AudioSession_OutputDeviceChangeRecommendedAction | Enumerates the recommended actions to take after an output device changes. |
| OH_AudioSession_DeactivatedReason | OH_AudioSession_DeactivatedReason | Enumerates the reasons for deactivating an audio session. |
| OH_AudioSession_BluetoothAndNearlinkPreferredRecordCategory | OH_AudioSession_BluetoothAndNearlinkPreferredRecordCategory | Enumerates the preferred device categories available for recording with Bluetooth or NearLink. |
Functions
Enum Description
OH_AudioSession_Scene
enum OH_AudioSession_Scene
Description
Enumerates the audio session scenes.
Since: 20
| Enum Item | Description |
|---|---|
| AUDIO_SESSION_SCENE_MEDIA = 0 | Media audio session. |
| AUDIO_SESSION_SCENE_GAME = 1 | Game audio session. |
| AUDIO_SESSION_SCENE_VOICE_COMMUNICATION = 2 | VoIP voice call audio session. |
OH_AudioSession_StateChangeHint
enum OH_AudioSession_StateChangeHint
Description
Enumerates the hints for audio session state changes.
Since: 20
| Enum Item | Description |
|---|---|
| AUDIO_SESSION_STATE_CHANGE_HINT_RESUME = 0 | A hint is displayed, indicating that the audio session is resuming. The application can proactively trigger operations such as rendering. |
| AUDIO_SESSION_STATE_CHANGE_HINT_PAUSE = 1 | A hint is displayed, indicating that the audio session is paused and the audio focus is lost temporarily. When focus is regained, the AUDIO_SESSION_STATE_CHANGE_HINT_RESUME event is received. |
| AUDIO_SESSION_STATE_CHANGE_HINT_STOP = 2 | A hint is displayed, indicating that the audio session is stopped and the audio focus is lost permanently. |
| AUDIO_SESSION_STATE_CHANGE_HINT_TIME_OUT_STOP = 3 | A hint is displayed, indicating that the audio session is stopped by the system due to no activity, and the audio focus is lost. |
| AUDIO_SESSION_STATE_CHANGE_HINT_DUCK = 4 | A hint is displayed, indicating that audio ducking starts and the audio is played at a lower volume. If OH_AudioSessionManager_EnableMuteSuggestionWhenMixWithOthers is enabled, you can choose to mute the audio. |
| AUDIO_SESSION_STATE_CHANGE_HINT_UNDUCK = 5 | A hint is displayed, indicating that audio ducking ends and the audio is played at the normal volume. If OH_AudioSessionManager_EnableMuteSuggestionWhenMixWithOthers is enabled, you can unmute the audio. |
| AUDIO_SESSION_STATE_CHANGE_HINT_MUTE_SUGGESTION = 6 | Mute suggestion. When another application starts playing non-mixable audio, the application can determine whether to mute the audio. Since: 23 |
| AUDIO_SESSION_STATE_CHANGE_HINT_UNMUTE_SUGGESTION = 7 | Unmute suggestion. When the non-mixable audio of another application has finished playing, the application can decide whether to unmute the audio. Since: 23 |
| AUDIO_SESSION_STATE_CHANGE_HINT_MUTE = 8 | A hint is displayed, indicating that the audio session is muted. This hint is received only when the following conditions are met: The OH_AudioSessionManager_SetBehavior API is called to set OH_AudioSession_BehaviorFlags.MUTE_WHEN_INTERRUPTED, the OH_AudioSessionManager_SetScene API is called, and the audio session is activated. Since: 24 |
| AUDIO_SESSION_STATE_CHANGE_HINT_UNMUTE = 9 | A hint is displayed, indicating that the audio session is unmuted. This hint is received only when the following conditions are met: The OH_AudioSessionManager_SetBehavior API is called to set OH_AudioSession_BehaviorFlags.MUTE_WHEN_INTERRUPTED, the OH_AudioSessionManager_SetScene API is called, and the audio session is activated. Since: 24 |
OH_AudioSession_OutputDeviceChangeRecommendedAction
enum OH_AudioSession_OutputDeviceChangeRecommendedAction
Description
Enumerates the recommended actions to take after an output device changes.
Common scenario example: switching between a headset and a loudspeaker device. Upon switching from the loudspeaker device to the headset upon wearing, the system suggests continuing playback and prompts that the application does not need to pause. Upon transitioning from the headset to the loudspeaker device upon removal, the system suggests suspending playback.
Since: 20
| Enum Item | Description |
|---|---|
| DEVICE_CHANGE_RECOMMEND_TO_CONTINUE = 0 | Suggests continuing playback. (This event serves as a playback maintenance indication, informing the application that audio playback does not need to stop during this device change. However, it must not be used as a criterion for triggering audio playback.) |
| DEVICE_CHANGE_RECOMMEND_TO_STOP = 1 | Suggests stopping playback. |
OH_AudioSession_DeactivatedReason
enum OH_AudioSession_DeactivatedReason
Description
Enumerates the reasons for deactivating an audio session.
Since: 12
| Enum Item | Description |
|---|---|
| DEACTIVATED_LOWER_PRIORITY = 0 | The application focus is preempted. |
| DEACTIVATED_TIMEOUT = 1 | The application times out after the stream is stopped. |
OH_AudioSession_BluetoothAndNearlinkPreferredRecordCategory
enum OH_AudioSession_BluetoothAndNearlinkPreferredRecordCategory
Description
Enumerates the preferred device categories available for recording with Bluetooth or NearLink.
Since: 21
| Enum Item | Description |
|---|---|
| PREFERRED_NONE = 0 | No specific device preference. |
| PREFERRED_DEFAULT = 1 | Prefers using Bluetooth or Nearlink devices for recording; whether to use low-latency or high-quality recording depends on the system. |
| PREFERRED_LOW_LATENCY = 2 | Prefers using Bluetooth or NearLink devices in low-latency mode for recording. |
| PREFERRED_HIGH_QUALITY = 3 | Prefers using Bluetooth or NearLink devices in high-quality mode for recording. |
Function Description
OH_AudioSession_StateChangedCallback()
typedef void (*OH_AudioSession_StateChangedCallback)(OH_AudioSession_StateChangedEvent event)
Description
Defines a function pointer to the callback used to listen for audio session state change events.
Since: 20
Parameters
| Name | Description |
|---|---|
| OH_AudioSession_StateChangedEvent event | Event indicating that the audio session state changes. |
OH_AudioSession_AvailableDeviceChangedCallback()
typedef void (*OH_AudioSession_AvailableDeviceChangedCallback)(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: 21
Parameters
| Name | Description |
|---|---|
| OH_AudioDevice_ChangeType type | Device connection status, which can be connected or disconnected. |
| OH_AudioDeviceDescriptorArray *audioDeviceDescriptorArray | Pointer to the audio device descriptors in the array. If the pointer is no longer needed, use OH_AudioSessionManager_ReleaseDevices to release it. |
OH_AudioSession_CurrentInputDeviceChangedCallback()
typedef void (*OH_AudioSession_CurrentInputDeviceChangedCallback)(OH_AudioDeviceDescriptorArray *devices, OH_AudioStream_DeviceChangeReason changeReason)
Description
Defines a function pointer to the callback used to listen for the current input device change events.
Since: 21
Parameters
| Name | Description |
|---|---|
| OH_AudioDeviceDescriptorArray *devices | Pointer to the audio device descriptors in the array. Use OH_AudioSessionManager_ReleaseDevices to release the devices pointer if it is no longer needed. |
| OH_AudioStream_DeviceChangeReason changeReason | Reason for the device change. |
OH_AudioSession_CurrentOutputDeviceChangedCallback()
typedef void (*OH_AudioSession_CurrentOutputDeviceChangedCallback)(OH_AudioDeviceDescriptorArray *devices, OH_AudioStream_DeviceChangeReason changeReason, OH_AudioSession_OutputDeviceChangeRecommendedAction recommendedAction)
Description
Defines a function pointer to the callback used to listen for the current output device change events.
Since: 20
Parameters
| Name | Description |
|---|---|
| OH_AudioDeviceDescriptorArray *devices | Audio device descriptor array, which points to OH_AudioDeviceDescriptorArray used to set the pointer variable of the audio device descriptor array. Do not release the audioDeviceDescriptorArray pointer separately. Instead, call OH_AudioSessionManager_ReleaseDevices to release the DeviceDescriptor array. |
| OH_AudioStream_DeviceChangeReason changeReason | Pointer to OH_AudioStream_DeviceChangeReason, which is used to receive the device change reason. |
| OH_AudioSession_OutputDeviceChangeRecommendedAction recommendedAction | Pointer to OH_AudioSession_OutputDeviceChangeRecommendedAction, which is used to receive the recommended operation after the device change. |
OH_AudioSession_DeactivatedCallback()
typedef int32_t (*OH_AudioSession_DeactivatedCallback)(OH_AudioSession_DeactivatedEvent event)
Description
Defines a function pointer to the callback used to listen for audio session deactivation events.
Since: 12
Parameters
| Name | Description |
|---|---|
| OH_AudioSession_DeactivatedEvent event | Event indicating that an audio session is deactivated. |
OH_AudioManager_GetAudioSessionManager()
OH_AudioCommon_Result OH_AudioManager_GetAudioSessionManager(OH_AudioSessionManager **audioSessionManager)
Description
Obtains an OH_AudioSessionManager instance. Before using the features related to the audio session manager, you must obtain an OH_AudioSessionManager instance.
Since: 12
Parameters
| Name | Description |
|---|---|
| OH_AudioSessionManager **audioSessionManager | Double pointer to the OH_AudioSessionManager instance obtained. |
Returns
| Type | Description |
|---|---|
| OH_AudioCommon_Result | AUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully. AUDIOCOMMON_RESULT_ERROR_SYSTEM: System error. |
OH_AudioSessionManager_ActivateAudioSession()
OH_AudioCommon_Result OH_AudioSessionManager_ActivateAudioSession(OH_AudioSessionManager *audioSessionManager, const OH_AudioSession_Strategy *strategy)
Description
Activates an audio session.
Since: 12
Parameters
| Name | Description |
|---|---|
| OH_AudioSessionManager *audioSessionManager | Pointer to the audio session management instance created by OH_AudioManager_GetAudioSessionManager. |
| const OH_AudioSession_Strategy *strategy | Pointer to an audio session strategy, which is an OH_AudioSession_Strategy struct. |
Returns
| Type | Description |
|---|---|
| OH_AudioCommon_Result | One of the following return values: AUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully. AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM: 1. The audioSessionManager parameter is nullptr. 2. The strategy parameter is invalid. AUDIOCOMMON_RESULT_ERROR_ILLEGAL_STATE: Invalid state. |
OH_AudioSessionManager_DeactivateAudioSession()
OH_AudioCommon_Result OH_AudioSessionManager_DeactivateAudioSession(OH_AudioSessionManager *audioSessionManager)
Description
Deactivates an audio session.
Since: 12
Parameters
| Name | Description |
|---|---|
| OH_AudioSessionManager *audioSessionManager | Pointer to the audio session management instance created by OH_AudioManager_GetAudioSessionManager. |
Returns
| Type | Description |
|---|---|
| OH_AudioCommon_Result | AUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully. AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM: The audioSessionManager parameter is nullptr. AUDIOCOMMON_RESULT_ERROR_ILLEGAL_STATE: Invalid state. |
OH_AudioSessionManager_IsAudioSessionActivated()
bool OH_AudioSessionManager_IsAudioSessionActivated(OH_AudioSessionManager *audioSessionManager)
Description
Checks whether an audio session is activated.
Since: 12
Parameters
| Name | Description |
|---|---|
| OH_AudioSessionManager *audioSessionManager | Pointer to the audio session management instance created by OH_AudioManager_GetAudioSessionManager. |
Returns
| Type | Description |
|---|---|
| bool | Check result for whether the audio session is activated. true if activated, false otherwise. |
OH_AudioSessionManager_RegisterSessionDeactivatedCallback()
OH_AudioCommon_Result OH_AudioSessionManager_RegisterSessionDeactivatedCallback(OH_AudioSessionManager *audioSessionManager, OH_AudioSession_DeactivatedCallback callback)
Description
Registers a callback to listen for audio session deactivation events.
Since: 12
Parameters
| Name | Description |
|---|---|
| OH_AudioSessionManager *audioSessionManager | Pointer to the audio session management instance created by OH_AudioManager_GetAudioSessionManager. |
| OH_AudioSession_DeactivatedCallback callback | Callback used to receive the audio session deactivation event. |
Returns
| Type | Description |
|---|---|
| OH_AudioCommon_Result | AUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully. AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM: 1. The audioSessionManager parameter is nullptr. 2. The callback parameter is nullptr. |
OH_AudioSessionManager_UnregisterSessionDeactivatedCallback()
OH_AudioCommon_Result OH_AudioSessionManager_UnregisterSessionDeactivatedCallback(OH_AudioSessionManager *audioSessionManager, OH_AudioSession_DeactivatedCallback callback)
Description
Unregisters the callback used to listen for audio session deactivation events.
Since: 12
Parameters
| Name | Description |
|---|---|
| OH_AudioSessionManager *audioSessionManager | Pointer to the audio session management instance created by OH_AudioManager_GetAudioSessionManager. |
| OH_AudioSession_DeactivatedCallback callback | Callback used to receive the audio session deactivation event. |
Returns
| Type | Description |
|---|---|
| OH_AudioCommon_Result | AUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully. AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM: 1. The audioSessionManager parameter is nullptr. 2. The callback parameter is nullptr. |
OH_AudioSessionManager_SetScene()
OH_AudioCommon_Result OH_AudioSessionManager_SetScene(OH_AudioSessionManager *audioSessionManager, OH_AudioSession_Scene scene)
Description
Sets an audio session scene.
Since: 20
Parameters
| Name | Description |
|---|---|
| OH_AudioSessionManager *audioSessionManager | Pointer to the audio session management instance created by OH_AudioManager_GetAudioSessionManager. |
| OH_AudioSession_Scene scene | Pointer to the audio session scene to be set by OH_AudioSession_Scene. |
Returns
| Type | Description |
|---|---|
| OH_AudioCommon_Result | AUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully. AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM: 1. The audioSessionManager parameter is nullptr. 2. The scene parameter is set to a value outside the valid enumeration range. AUDIOCOMMON_RESULT_ERROR_ILLEGAL_STATE: The setting is not allowed in the current system state, for example, when the audio session is not ready. AUDIOCOMMON_RESULT_ERROR_SYSTEM: A system error occurs, such as an abnormal exit of a system service. |
OH_AudioSessionManager_RegisterStateChangeCallback()
OH_AudioCommon_Result OH_AudioSessionManager_RegisterStateChangeCallback(OH_AudioSessionManager *audioSessionManager, OH_AudioSession_StateChangedCallback callback)
Description
Registers a callback to listen for audio session state change events.
Since: 20
Parameters
| Name | Description |
|---|---|
| OH_AudioSessionManager *audioSessionManager | Pointer to the audio session management instance created by OH_AudioManager_GetAudioSessionManager. |
| OH_AudioSession_StateChangedCallback callback | Callback used to receive the audio session state change event. |
Returns
| Type | Description |
|---|---|
| OH_AudioCommon_Result | AUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully. AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM: 1. The audioSessionManager parameter is nullptr. 2. The callback parameter is nullptr. AUDIOCOMMON_RESULT_ERROR_NO_MEMORY: Memory allocation fails. AUDIOCOMMON_RESULT_ERROR_SYSTEM: A system error occurs, such as an abnormal exit of a system service. |
OH_AudioSessionManager_UnregisterStateChangeCallback()
OH_AudioCommon_Result OH_AudioSessionManager_UnregisterStateChangeCallback(OH_AudioSessionManager *audioSessionManager, OH_AudioSession_StateChangedCallback callback)
Description
Unregisters the callback used to listen for audio session state change events.
Since: 20
Parameters
| Name | Description |
|---|---|
| OH_AudioSessionManager *audioSessionManager | Pointer to the audio session management instance created by OH_AudioManager_GetAudioSessionManager. |
| OH_AudioSession_StateChangedCallback callback | Callback used to receive the audio session state change event. |
Returns
| Type | Description |
|---|---|
| OH_AudioCommon_Result | AUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully. AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM: 1. The audioSessionManager parameter is nullptr. 2. The callback parameter is nullptr. AUDIOCOMMON_RESULT_ERROR_SYSTEM: A system error occurs, such as an abnormal exit of a system service. |
OH_AudioSessionManager_SetDefaultOutputDevice()
OH_AudioCommon_Result OH_AudioSessionManager_SetDefaultOutputDevice(OH_AudioSessionManager *audioSessionManager, OH_AudioDevice_Type deviceType)
Description
Sets the default audio output device.
NOTE
- This API is applicable to the following scenarios: If OH_AudioSession_Scene is set to VoIP, this API takes effect immediately after the audio session is activated. If OH_AudioSession_Scene is set to non-VoIP, this API does not take effect when the audio session is activated. It takes effect only when OH_AudioStream_Usage of the started playback is a voice message, VoIP voice call, or VoIP video call. Supported devices include the earpiece, speaker, and system default device.
- This API can be called at any time after an OH_AudioSessionManager instance is created. The system records the device set by the application. However, the setting takes effect only after the AudioSession is activated. When the application starts playback, if an external device such as a Bluetooth or wired headset is connected, the system preferentially uses the external device to play sound. Otherwise, the system uses this default device to play sound.
Device behavior difference: If the default audio output device is set to earpiece on a device without an earpiece, the speaker will still be used for audio output.
Since: 20
Parameters
| Name | Description |
|---|---|
| OH_AudioSessionManager *audioSessionManager | Pointer to the audio session management instance created by OH_AudioManager_GetAudioSessionManager. |
| OH_AudioDevice_Type deviceType | Device type. For details about the available options, see OH_AudioDevice_Type. The device types that can be set are as follows: AUDIO_DEVICE_TYPE_EARPIECE: earpiece. AUDIO_DEVICE_TYPE_SPEAKER: speaker. AUDIO_DEVICE_TYPE_DEFAULT: system default device. |
Returns
| Type | Description |
|---|---|
| OH_AudioCommon_Result | AUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully. AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM: 1. The audioSessionManager parameter is nullptr. 2. The deviceType parameter is out of the OH_AudioDevice_Type range. AUDIOCOMMON_RESULT_ERROR_SYSTEM: A system error occurs, such as an abnormal exit of a system service. |
OH_AudioSessionManager_GetDefaultOutputDevice()
OH_AudioCommon_Result OH_AudioSessionManager_GetDefaultOutputDevice(OH_AudioSessionManager *audioSessionManager, OH_AudioDevice_Type *deviceType)
Description
Obtains the default audio output device set by OH_AudioSessionManager_SetDefaultOutputDevice.
Since: 20
Parameters
| Name | Description |
|---|---|
| OH_AudioSessionManager *audioSessionManager | Pointer to the audio session management instance created by OH_AudioManager_GetAudioSessionManager. |
| OH_AudioDevice_Type *deviceType | Pointer to the device type. For details about the available options, see OH_AudioDevice_Type. The returned device types are as follows: AUDIO_DEVICE_TYPE_EARPIECE: earpiece. AUDIO_DEVICE_TYPE_SPEAKER: speaker. AUDIO_DEVICE_TYPE_DEFAULT: system default device. |
Returns
| Type | Description |
|---|---|
| OH_AudioCommon_Result | AUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully. AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM: 1. The audioSessionManager parameter is nullptr. 2. The deviceType parameter is nullptr. AUDIOCOMMON_RESULT_ERROR_ILLEGAL_STATE: The default device type cannot be obtained in the current system state, for example, when the audio session is not ready. |
OH_AudioSessionManager_ReleaseDevices()
OH_AudioCommon_Result OH_AudioSessionManager_ReleaseDevices(OH_AudioSessionManager *audioSessionManager, OH_AudioDeviceDescriptorArray *audioDeviceDescriptorArray)
Description
Releases audio devices available for an audio routing manager.
Since: 20
Parameters
| Name | Description |
|---|---|
| OH_AudioSessionManager *audioSessionManager | Pointer to the audio session management instance created by OH_AudioManager_GetAudioSessionManager. |
| OH_AudioDeviceDescriptorArray *audioDeviceDescriptorArray | Pointer to the audio device descriptors in the array to be released. |
Returns
| Type | Description |
|---|---|
| OH_AudioCommon_Result | AUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully. AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM: 1. The audioSessionManager parameter is nullptr. 2. The audioDeviceDescriptorArray parameter is nullptr. |
OH_AudioSessionManager_RegisterCurrentOutputDeviceChangeCallback()
OH_AudioCommon_Result OH_AudioSessionManager_RegisterCurrentOutputDeviceChangeCallback(OH_AudioSessionManager *audioSessionManager, OH_AudioSession_CurrentOutputDeviceChangedCallback callback)
Description
Registers a callback to listen for the current output device change events.
Since: 20
Parameters
| Name | Description |
|---|---|
| OH_AudioSessionManager *audioSessionManager | Pointer to the audio session management instance created by OH_AudioManager_GetAudioSessionManager. |
| OH_AudioSession_CurrentOutputDeviceChangedCallback callback | Callback used to return the audio device change information. |
Returns
| Type | Description |
|---|---|
| OH_AudioCommon_Result | AUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully. AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM: 1. The audioSessionManager parameter is nullptr. 2. The callback parameter is nullptr. AUDIOCOMMON_RESULT_ERROR_NO_MEMORY: Memory allocation fails. AUDIOCOMMON_RESULT_ERROR_SYSTEM: A system error occurs, such as an abnormal exit of a system service. |
OH_AudioSessionManager_UnregisterCurrentOutputDeviceChangeCallback()
OH_AudioCommon_Result OH_AudioSessionManager_UnregisterCurrentOutputDeviceChangeCallback(OH_AudioSessionManager *audioSessionManager, OH_AudioSession_CurrentOutputDeviceChangedCallback callback)
Description
Unregisters the callback used to listen for the current output device change events.
Since: 20
Parameters
| Name | Description |
|---|---|
| OH_AudioSessionManager *audioSessionManager | Pointer to the audio session management instance created by OH_AudioManager_GetAudioSessionManager. |
| OH_AudioSession_CurrentOutputDeviceChangedCallback callback | Callback used to return the audio device change information. |
Returns
| Type | Description |
|---|---|
| OH_AudioCommon_Result | AUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully. AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM: 1. The audioSessionManager parameter is nullptr. 2. The callback parameter is nullptr. AUDIOCOMMON_RESULT_ERROR_SYSTEM: A system error occurs, such as an abnormal exit of a system service. |
OH_AudioSessionManager_GetAvailableDevices()
OH_AudioCommon_Result OH_AudioSessionManager_GetAvailableDevices(OH_AudioSessionManager *audioSessionManager, OH_AudioDevice_Usage deviceUsage, OH_AudioDeviceDescriptorArray **audioDeviceDescriptorArray)
Description
Obtains the available audio devices.
Since: 21
Parameters
| Name | Description |
|---|---|
| OH_AudioSessionManager *audioSessionManager | Pointer to the audio session management instance created by OH_AudioManager_GetAudioSessionManager. |
| OH_AudioDevice_Usage deviceUsage | Type of audio device. |
| OH_AudioDeviceDescriptorArray **audioDeviceDescriptorArray | Pointer to the audio device descriptors in the array. Use OH_AudioSessionManager_ReleaseDevices to release the audioDeviceDescriptorArray pointer if the pointer is no longer needed. |
Returns
| Type | Description |
|---|---|
| OH_AudioCommon_Result | AUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully. AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM: 1. The audioSessionManager parameter is nullptr. 2. The deviceUsage parameter is invalid. 3. The audioDeviceDescriptorArray parameter is nullptr. AUDIOCOMMON_RESULT_ERROR_SYSTEM: A system error occurs, such as an abnormal exit of a system service. |
OH_AudioSessionManager_RegisterAvailableDevicesChangeCallback()
OH_AudioCommon_Result OH_AudioSessionManager_RegisterAvailableDevicesChangeCallback(OH_AudioSessionManager *audioSessionManager, OH_AudioDevice_Usage deviceUsage, OH_AudioSession_AvailableDeviceChangedCallback callback)
Description
Registers a callback to listen for available device change events.
Since: 21
Parameters
| Name | Description |
|---|---|
| OH_AudioSessionManager *audioSessionManager | Pointer to the audio session management instance created by OH_AudioManager_GetAudioSessionManager. |
| OH_AudioDevice_Usage deviceUsage | Type of audio device. |
| OH_AudioSession_AvailableDeviceChangedCallback callback | Callback used to return the available audio device change information. |
Returns
| Type | Description |
|---|---|
| OH_AudioCommon_Result | AUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully. AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM: 1. The audioSessionManager parameter is nullptr. 2. The deviceUsage parameter is set to an invalid value. 3. The callback parameter is nullptr. AUDIOCOMMON_RESULT_ERROR_SYSTEM: A system error occurs, such as an abnormal exit of a system service. |
OH_AudioSessionManager_UnregisterAvailableDevicesChangeCallback()
OH_AudioCommon_Result OH_AudioSessionManager_UnregisterAvailableDevicesChangeCallback(OH_AudioSessionManager *audioSessionManager, OH_AudioSession_AvailableDeviceChangedCallback callback)
Description
Unregisters the callback used to listen for available device change events.
Since: 21
Parameters
| Name | Description |
|---|---|
| OH_AudioSessionManager *audioSessionManager | Pointer to the audio session management instance created by OH_AudioManager_GetAudioSessionManager. |
| OH_AudioSession_AvailableDeviceChangedCallback callback | Callback used to return the available audio device change information. |
Returns
| Type | Description |
|---|---|
| OH_AudioCommon_Result | AUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully. AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM: 1. The audioSessionManager parameter is nullptr. 2. The callback parameter is nullptr. AUDIOCOMMON_RESULT_ERROR_SYSTEM: A system error occurs, such as an abnormal exit of a system service. |
OH_AudioSessionManager_SelectMediaInputDevice()
OH_AudioCommon_Result OH_AudioSessionManager_SelectMediaInputDevice(OH_AudioSessionManager *audioSessionManager, OH_AudioDeviceDescriptor *deviceDescriptor)
Description
Selects a media input device. This function is not suitable for call recording, meaning it does not apply to situations where SourceType is SOURCE_TYPE_VOICE_COMMUNICATION.
When there is a concurrent recording stream with higher priority, the actual input device used by the application may differ from the one selected.
The application can use OH_AudioSessionManager_RegisterCurrentInputDeviceChangeCallback to register a callback to listen for the actual input device.
Since: 21
Parameters
| Name | Description |
|---|---|
| OH_AudioSessionManager *audioSessionManager | Pointer to the audio session management instance created by OH_AudioManager_GetAudioSessionManager. |
| OH_AudioDeviceDescriptor *deviceDescriptor | Pointer to the target device, The available device must be in the array returned by OH_AudioSessionManager_GetAvailableDevices. If nullptr is passed, the system clears the previous setting. |
Returns
| Type | Description |
|---|---|
| OH_AudioCommon_Result | AUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully. AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM: The audioSessionManager parameter is nullptr. AUDIOCOMMON_RESULT_ERROR_SYSTEM: A system error occurs, such as an abnormal exit of a system service. |
OH_AudioSessionManager_GetSelectedMediaInputDevice()
OH_AudioCommon_Result OH_AudioSessionManager_GetSelectedMediaInputDevice(OH_AudioSessionManager *audioSessionManager, OH_AudioDeviceDescriptor **audioDeviceDescriptor)
Description
Obtains the media input device set by OH_AudioSessionManager_SelectMediaInputDevice.
Since: 21
Parameters
| Name | Description |
|---|---|
| OH_AudioSessionManager *audioSessionManager | Pointer to the audio session management instance created by OH_AudioManager_GetAudioSessionManager. |
| OH_AudioDeviceDescriptor **audioDeviceDescriptor | Media device set by OH_AudioSessionManager_SelectMediaInputDevice. If no media device is set, a device of the AUDIO_DEVICE_TYPE_INVALID type is returned. Use OH_AudioSessionManager_ReleaseDevice to release the audioDeviceDescriptor pointer if the pointer is no longer needed. |
Returns
| Type | Description |
|---|---|
| OH_AudioCommon_Result | AUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully. AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM: 1. The audioSessionManager parameter is nullptr. 2. The audioDeviceDescriptor parameter is nullptr. AUDIOCOMMON_RESULT_ERROR_SYSTEM: A system error occurs, such as an abnormal exit of a system service. |
OH_AudioSessionManager_SetBluetoothAndNearlinkPreferredRecordCategory()
OH_AudioCommon_Result OH_AudioSessionManager_SetBluetoothAndNearlinkPreferredRecordCategory(OH_AudioSessionManager *audioSessionManager, OH_AudioSession_BluetoothAndNearlinkPreferredRecordCategory category)
Description
Sets the preferred device category for recording with Bluetooth or NearLink. Applications can set this category before connecting to Bluetooth or NearLink devices, and the system prioritizes using the device for recording when the device is connected.
When there is a concurrent recording stream with higher priority, the actual input device used by the application may differ from the set preferred device.
The application can use OH_AudioSessionManager_RegisterCurrentInputDeviceChangeCallback to register a callback to listen for the actual input device.
Since: 21
Parameters
| Name | Description |
|---|---|
| OH_AudioSessionManager *audioSessionManager | Pointer to the audio session management instance created by OH_AudioManager_GetAudioSessionManager. |
| OH_AudioSession_BluetoothAndNearlinkPreferredRecordCategory category | Preferred device category available for recording with Bluetooth or NearLink. |
Returns
| Type | Description |
|---|---|
| OH_AudioCommon_Result | AUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully. AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM: 1. The audioSessionManager parameter is nullptr. 2. The category parameter is incorrect. AUDIOCOMMON_RESULT_ERROR_SYSTEM: A system error occurs, such as an abnormal exit of a system service. |
OH_AudioSessionManager_GetBluetoothAndNearlinkPreferredRecordCategory()
OH_AudioCommon_Result OH_AudioSessionManager_GetBluetoothAndNearlinkPreferredRecordCategory(OH_AudioSessionManager *audioSessionManager, OH_AudioSession_BluetoothAndNearlinkPreferredRecordCategory *category)
Description
Obtains the preferred device category for recording with Bluetooth or NearLink.
Since: 21
Parameters
| Name | Description |
|---|---|
| OH_AudioSessionManager *audioSessionManager | Pointer to the audio session management instance created by OH_AudioManager_GetAudioSessionManager. |
| OH_AudioSession_BluetoothAndNearlinkPreferredRecordCategory *category | Preferred device category available for recording with Bluetooth or NearLink. |
Returns
| Type | Description |
|---|---|
| OH_AudioCommon_Result | AUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully. AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM: 1. The audioSessionManager parameter is nullptr. 2. The category parameter is nullptr. AUDIOCOMMON_RESULT_ERROR_SYSTEM: A system error occurs, such as an abnormal exit of a system service. |
OH_AudioSessionManager_RegisterCurrentInputDeviceChangeCallback()
OH_AudioCommon_Result OH_AudioSessionManager_RegisterCurrentInputDeviceChangeCallback(OH_AudioSessionManager *audioSessionManager, OH_AudioSession_CurrentInputDeviceChangedCallback callback)
Description
Registers a callback to listen for input device changes of an audio session manager.
Since: 21
Parameters
| Name | Description |
|---|---|
| OH_AudioSessionManager *audioSessionManager | Pointer to the audio session management instance created by OH_AudioManager_GetAudioSessionManager. |
| OH_AudioSession_CurrentInputDeviceChangedCallback callback | Callback used to return the input audio device change information. |
Returns
| Type | Description |
|---|---|
| OH_AudioCommon_Result | AUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully. AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM: 1. The audioSessionManager parameter is nullptr. 2. The callback parameter is nullptr. AUDIOCOMMON_RESULT_ERROR_NO_MEMORY: The memory is insufficient. AUDIOCOMMON_RESULT_ERROR_SYSTEM: A system error occurs, such as an abnormal exit of a system service. |
OH_AudioSessionManager_UnregisterCurrentInputDeviceChangeCallback()
OH_AudioCommon_Result OH_AudioSessionManager_UnregisterCurrentInputDeviceChangeCallback(OH_AudioSessionManager *audioSessionManager, OH_AudioSession_CurrentInputDeviceChangedCallback callback)
Description
Unregisters the callback used to listen for input device changes of an audio session manager.
Since: 21
Parameters
| Name | Description |
|---|---|
| OH_AudioSessionManager *audioSessionManager | Pointer to the audio session management instance created by OH_AudioManager_GetAudioSessionManager. |
| OH_AudioSession_CurrentInputDeviceChangedCallback callback | Callback used to return the input audio device change information. |
Returns
| Type | Description |
|---|---|
| OH_AudioCommon_Result | AUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully. AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM: 1. The audioSessionManager parameter is nullptr. 2. The callback parameter is nullptr. AUDIOCOMMON_RESULT_ERROR_SYSTEM: A system error occurs, such as an abnormal exit of a system service. |
OH_AudioSessionManager_ReleaseDevice()
OH_AudioCommon_Result OH_AudioSessionManager_ReleaseDevice(OH_AudioSessionManager *audioSessionManager, OH_AudioDeviceDescriptor *audioDeviceDescriptor)
Description
Releases an audio device for an audio session manager.
Since: 21
Parameters
| Name | Description |
|---|---|
| OH_AudioSessionManager *audioSessionManager | Pointer to the audio session management instance created by OH_AudioManager_GetAudioSessionManager. |
| OH_AudioDeviceDescriptor *audioDeviceDescriptor | Pointer to the audio device descriptor to be released. |
Returns
| Type | Description |
|---|---|
| OH_AudioCommon_Result | AUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully. AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM: 1. The audioSessionManager parameter is nullptr. 2. The audioDeviceDescriptor parameter is nullptr. |
OH_AudioSessionManager_EnableMuteSuggestionWhenMixWithOthers()
OH_AudioCommon_Result OH_AudioSessionManager_EnableMuteSuggestionWhenMixWithOthers(OH_AudioSessionManager *audioSessionManager, bool enable)
Description
Enables the function of receiving mute playback suggestion notifications during mixed playback. Generally, in the audio mixing mode, if the audio of another application is played at the same time, the two pieces of audio are played in mixed mode. In certain scenarios (such as games or broadcasts), applications can enable mute suggestion notifications to enhance user experience. If this function is enabled, mute suggestion and unmute suggestion notifications are sent through the OH_AudioSession_StateChangedCallback callback after the audio session state change event is subscribed to. The callback is registered by OH_AudioSessionManager_RegisterStateChangeCallback.
Receiving the muted suggestion indicates that another application starts to play audio, and the played audio and the audio of this application cannot be mixed. This function is supported only for audio sessions for which OH_AudioSession_Scene is set and the activation mode is set to OH_AudioSession_ConcurrencyMode.CONCURRENCY_MIX_WITH_OTHERS.
This function takes effect only once when the audio session is activated. You need to enable the function again before each activation of the audio session.
Since: 23
Parameters
| Name | Description |
|---|---|
| OH_AudioSessionManager *audioSessionManager | Pointer to the audio session management instance created by OH_AudioManager_GetAudioSessionManager. |
| bool enable | Whether to enable the mute suggestion callback function. true to enable, false otherwise. |
Returns
| Type | Description |
|---|---|
| OH_AudioCommon_Result | AUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully. AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM: The audioSessionManager parameter is nullptr. AUDIOCOMMON_RESULT_ERROR_ILLEGAL_STATE: 1. Audio session scene not set. 2. Call this function after the audio session is activated. AUDIOCOMMON_RESULT_ERROR_SYSTEM: A system error occurs, such as an abnormal exit of a system service. |
OH_AudioSessionManager_IsOtherMediaPlaying()
bool OH_AudioSessionManager_IsOtherMediaPlaying(OH_AudioSessionManager *audioSessionManager)
Description
Checks whether audio of the MUSIC, MOVIE, AUDIOBOOK, and GAME media types is being played by other applications. The activated audio sessions of the media types are also checked.
Since: 23
Parameters
| Name | Description |
|---|---|
| OH_AudioSessionManager *audioSessionManager | Pointer to the audio session management instance created by OH_AudioManager_GetAudioSessionManager. |
Returns
| Type | Description |
|---|---|
| bool | Whether another application is playing media audio. true means yes; false otherwise. |
OH_AudioSessionManager_SetBehavior()
OH_AudioCommon_Result OH_AudioSessionManager_SetBehavior(OH_AudioSessionManager *audioSessionManager, uint32_t behavior)
Description
Configures audio session behavior parameters. (Multiple flags can be combined.) If this API is called while an audio session is active, you must call the OH_AudioSessionManager_ActivateAudioSession API again for the settings to take effect.
Since: 24
Parameters
| Name | Description |
|---|---|
| OH_AudioSessionManager *audioSessionManager | Pointer to the audio session management instance created by OH_AudioManager_GetAudioSessionManager. |
| uint32_t behavior | Audio session behavior flag. This can be a single flag or a bitwise OR combination of multiple flags. For details about the supported audio session behaviors, see OH_AudioSession_BehaviorFlags. |
Returns
| Type | Description |
|---|---|
| OH_AudioCommon_Result | AUDIOCOMMON_RESULT_SUCCESS: The function is executed successfully. AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM: The parameter value is a null pointer or out of range. AUDIOCOMMON_RESULT_ERROR_ILLEGAL_STATE: Invalid state. |
你可能感兴趣的鸿蒙文章
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