1# OH_AudioRenderer_Callbacks_Struct 2 3## Overview 4 5The struct defines a pointer to the callback functions related to an audio renderer. 6 7To avoid unexpected behavior, ensure that every member variable of the struct is initialized by a custom callback method or a null pointer when setting the audio callback functions. 8 9For details, see [Using OHAudio for Audio Playback](../../media/audio/using-ohaudio-for-playback.md). 10 11**Since**: 10 12 13**Deprecated from**: 20 14 15**Substitute** 16 17Use the following callback types for substitute: 18 19[OH_AudioRenderer_OnWriteDataCallback](capi-native-audiostream-base-h.md#oh_audiorenderer_onwritedatacallback), [OH_AudioRenderer_OutputDeviceChangeCallback](capi-native-audiostream-base-h.md#oh_audiorenderer_outputdevicechangecallback), [OH_AudioRenderer_OnInterruptCallback](capi-native-audiorenderer-h.md#oh_audiorenderer_oninterruptcallback), and [OH_AudioRenderer_OnErrorCallback](capi-native-audiorenderer-h.md#oh_audiorenderer_onerrorcallback) 20 21**Related module**: [OHAudio](capi-ohaudio.md) 22 23**Header file**: [native_audiostream_base.h](capi-native-audiostream-base-h.md) 24 25## Summary 26 27### Member Functions 28 29| Name| Description| 30| -- | -- | 31| [int32_t (\*OH_AudioRenderer_OnWriteData)(OH_AudioRenderer* renderer, void* userData, void* buffer, int32_t length)](#oh_audiorenderer_onwritedata) | Defines a function pointer to the callback function used to write audio data.| 32| [int32_t (\*OH_AudioRenderer_OnStreamEvent)(OH_AudioRenderer* renderer, void* userData, OH_AudioStream_Event event)](#oh_audiorenderer_onstreamevent) | Defines a function pointer to the callback function used to process audio playback stream events.| 33| [int32_t (\*OH_AudioRenderer_OnInterruptEvent)(OH_AudioRenderer* renderer, void* userData, OH_AudioInterrupt_ForceType type, OH_AudioInterrupt_Hint hint)](#oh_audiorenderer_oninterruptevent) | Defines a function pointer to the callback function used to process audio playback interruption events.| 34| [int32_t (\*OH_AudioRenderer_OnError)(OH_AudioRenderer* renderer, void* userData, OH_AudioStream_Result error)](#oh_audiorenderer_onerror)| Defines a function pointer to the callback function used to process audio playback errors.| 35 36## Member Function Description 37 38> **NOTE** 39> 40> No enumerated values are defined as the return values of the following callbacks. In the current version, no processing specific to the return value is provided. To support expansion in later versions, the default value **0** is used. 41 42### OH_AudioRenderer_OnWriteData() 43 44``` 45int32_t (*OH_AudioRenderer_OnWriteData)(OH_AudioRenderer* renderer, void* userData, void* buffer, int32_t length) 46``` 47 48**Description** 49 50Defines a function pointer to the callback function used to write audio data. 51 52The callback function is used only to write audio data. Do not call AudioRenderer APIs in it. 53 54Once the callback function finishes its execution, the audio service queues the data pointed to by **buffer** for playback. Therefore, do not change the data outside the callback. It is crucial to fill **buffer** with the exact length (specified by **length**) of data designated for playback; otherwise, noises may occur during playback. 55 56**Since**: 10 57 58**Deprecated from**: 20 59 60**Substitute**: [OH_AudioRenderer_OnWriteDataCallback](capi-native-audiostream-base-h.md#oh_audiorenderer_onwritedatacallback) 61 62**Parameters** 63 64| Name| Description| 65| -- | -- | 66| [OH_AudioRenderer](capi-ohaudio-oh-audiorendererstruct.md)* renderer | Pointer to an audio renderer instance, which is created by calling [OH_AudioStreamBuilder_GenerateRenderer](capi-native-audiostreambuilder-h.md#oh_audiostreambuilder_generaterenderer).| 67| void* userData | Pointer to the data storage area customized by the application. | 68| void* buffer | Pointer to the playback data storage area, which is used by the application to fill in playback data. | 69| int32_t length | Length of the buffer. | 70 71### OH_AudioRenderer_OnStreamEvent() 72 73``` 74int32_t (*OH_AudioRenderer_OnStreamEvent)(OH_AudioRenderer* renderer, void* userData, OH_AudioStream_Event event) 75``` 76 77**Description** 78 79Defines a function pointer to the callback function used to process audio playback stream events. 80 81**Since**: 10 82 83**Deprecated from**: 20 84 85**Substitute**: [OH_AudioRenderer_OutputDeviceChangeCallback](capi-native-audiostream-base-h.md#oh_audiorenderer_outputdevicechangecallback) 86 87**Parameters** 88 89| Name| Description| 90| -- | -- | 91| [OH_AudioRenderer](capi-ohaudio-oh-audiorendererstruct.md)* renderer | Pointer to an audio renderer instance, which is created by calling [OH_AudioStreamBuilder_GenerateRenderer](capi-native-audiostreambuilder-h.md#oh_audiostreambuilder_generaterenderer).| 92| void* userData | Pointer to the data storage area customized by the application.| 93| [OH_AudioStream_Event](capi-native-audiostream-base-h.md#oh_audiostream_event) event | Audio event.| 94 95### OH_AudioRenderer_OnInterruptEvent() 96 97``` 98int32_t (*OH_AudioRenderer_OnInterruptEvent)(OH_AudioRenderer* renderer, void* userData, OH_AudioInterrupt_ForceType type, OH_AudioInterrupt_Hint hint) 99``` 100 101**Description** 102 103Defines a function pointer to the callback function used to process audio playback interruption events. 104 105**Since**: 10 106 107**Deprecated from**: 20 108 109**Substitute**: [OH_AudioRenderer_OnInterruptCallback](capi-native-audiorenderer-h.md#oh_audiorenderer_oninterruptcallback) 110 111**Parameters** 112 113| Name | Description| 114|--| -- | 115| [OH_AudioRenderer](capi-ohaudio-oh-audiorendererstruct.md)* renderer | Pointer to an audio renderer instance, which is created by calling [OH_AudioStreamBuilder_GenerateRenderer](capi-native-audiostreambuilder-h.md#oh_audiostreambuilder_generaterenderer).| 116| void* userData | Pointer to the data storage area customized by the application.| 117| [OH_AudioInterrupt_ForceType](capi-native-audiostream-base-h.md#oh_audiointerrupt_forcetype) type | Type of force that causes audio interruption.| 118| [OH_AudioInterrupt_Hint](capi-native-audiostream-base-h.md#oh_audiointerrupt_hint) hint | Hint provided along with audio interruption.| 119 120 121### OH_AudioRenderer_OnError() 122 123``` 124int32_t (*OH_AudioRenderer_OnError)(OH_AudioRenderer* renderer, void* userData, OH_AudioStream_Result error) 125``` 126 127**Description** 128 129Defines a function pointer to the callback function used to process audio playback errors. 130 131**Since**: 10 132 133**Deprecated from**: 20 134 135**Substitute**: [OH_AudioRenderer_OnErrorCallback](capi-native-audiorenderer-h.md#oh_audiorenderer_onerrorcallback) 136 137**Parameters** 138 139| Name | Description| 140|--| -- | 141| [OH_AudioRenderer](capi-ohaudio-oh-audiorendererstruct.md)* renderer | Pointer to an audio renderer instance, which is created by calling [OH_AudioStreamBuilder_GenerateRenderer](capi-native-audiostreambuilder-h.md#oh_audiostreambuilder_generaterenderer).| 142| void* userData | Pointer to the data storage area customized by the application.| 143| [OH_AudioStream_Result](capi-native-audiostream-base-h.md#oh_audiostream_result) error | Audio playback error result, which may be **AUDIOSTREAM_ERROR_INVALID_PARAM**, **AUDIOSTREAM_ERROR_ILLEGAL_STATE**, or **AUDIOSTREAM_ERROR_SYSTEM**.| 144