diff --git a/multimedia/audio_framework/common/native_audiostream_base.h b/multimedia/audio_framework/common/native_audiostream_base.h index 4d4cc435bd72da7efc52bb702493ef3a09afb23f..10332c357e5c82fbd0d17706116b29976b437e67 100644 --- a/multimedia/audio_framework/common/native_audiostream_base.h +++ b/multimedia/audio_framework/common/native_audiostream_base.h @@ -549,6 +549,34 @@ typedef struct OH_AudioCapturer_Callbacks_Struct { void* userData, OH_AudioStream_Result error); } OH_AudioCapturer_Callbacks; + +/** + * @brief Defines reason for device changes of one audio stream. + * + * @since 11 + */ +typedef enum { + /* Unknown. */ + REASON_UNKNOWN = 0, + /* New Device available. */ + REASON_NEW_DEVICE_AVAILABLE = 1, + /* Old Device unavailable. Applications should consider to pause the audio playback when this reason is + reported. */ + REASON_OLD_DEVICE_UNAVAILABLE = 2, + /* Device is overrode by user or system. */ + REASON_OVERRODE = 3, +} OH_AudioStream_DeviceChangeReason; + +/** + * @brief Callback when the output device of an audio renderer changed. + * + * @param renderer AudioRenderer where this event occurs. + * @param userData User data which is passed by user. + * @param reason Indicates that why does the output device changes. + * @since 11 + */ +typedef void (*OH_AudioRenderer_OutputDeviceChangeCallback)(OH_AudioRenderer* renderer, void* userData, + OH_AudioStream_DeviceChangeReason reason); #ifdef __cplusplus } #endif diff --git a/multimedia/audio_framework/common/native_audiostreambuilder.h b/multimedia/audio_framework/common/native_audiostreambuilder.h index 41a0e6679214153645efc7dda5ab61b1bdf88490..44b1e4ae268ac7fe821e0be9a62a0aed0a7c152d 100644 --- a/multimedia/audio_framework/common/native_audiostreambuilder.h +++ b/multimedia/audio_framework/common/native_audiostreambuilder.h @@ -164,6 +164,18 @@ OH_AudioStream_Result OH_AudioStreamBuilder_SetCapturerInfo(OH_AudioStreamBuilde OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererCallback(OH_AudioStreamBuilder* builder, OH_AudioRenderer_Callbacks callbacks, void* userData); +/** + * @brief Set the callback when the output device of an audio renderer changed. + * + * @param builder Reference provided by OH_AudioStreamBuilder_Create() + * @param callback Callback to the function that will process this device change event. + * @param userData Pointer to an application data structure that will be passed to the callback functions. + * @return {@link #AUDIOSTREAM_SUCCESS} or an undesired error. + * @since 11 + */ +OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererOutputDeviceChangeCallback(OH_AudioStreamBuilder* builder, + OH_AudioRenderer_OutputDeviceChangeCallback callback, void* userData); + /* * Set the callbacks for the capturer client * diff --git a/multimedia/audio_framework/ohaudio.ndk.json b/multimedia/audio_framework/ohaudio.ndk.json index e098fad58286b2a40a9702916c2924a3be5c98cb..daff64a649b9de05de33ffb8c7b48596f712077f 100644 --- a/multimedia/audio_framework/ohaudio.ndk.json +++ b/multimedia/audio_framework/ohaudio.ndk.json @@ -39,6 +39,10 @@ "first_introduced": "10", "name": "OH_AudioStreamBuilder_SetRendererCallback" }, + { + "first_introduced": "11", + "name": "OH_AudioStreamBuilder_SetRendererOutputDeviceChangeCallback" + }, { "first_introduced": "10", "name": "OH_AudioStreamBuilder_SetCapturerCallback" diff --git a/multimedia/player_framework/avplayer_base.h b/multimedia/player_framework/avplayer_base.h index 3128b6852522d1f81bd96a506f9951347220be0b..98b1f4080480b49233a9c803252f70005d326835 100644 --- a/multimedia/player_framework/avplayer_base.h +++ b/multimedia/player_framework/avplayer_base.h @@ -146,6 +146,10 @@ typedef enum AVPlayerOnInfoType { AV_INFO_TYPE_TRACK_INFO_UPDATE = 15, /* return the subtitle of playback. */ AV_INFO_TYPE_SUBTITLE_UPDATE = 16, + /** Return the reason when the audio output device changes. When this info is reported, the extra param of + * {@link OH_AVPlayerOnInfo} is the same as {@OH_AudioStream_DeviceChangeReason} in audio framework. + */ + AV_INFO_TYPE_AUDIO_OUTPUT_DEVICE_CHANGE = 17, } AVPlayerOnInfoType; /**