1# OH_AudioRenderer_Callbacks_Struct
2
3
4## Overview
5
6The **OH_AudioRenderer_Callbacks_Struct** struct defines a pointer to the callback functions related to an audio renderer.
7
8To 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. For details, see [Using OHAudio for Audio Playback](../../media/audio/using-ohaudio-for-playback.md).
9
10**System capability**: SystemCapability.Multimedia.Audio.Core
11
12**Since**: 10
13
14**Related module**: [OHAudio](_o_h_audio.md)
15
16
17## Summary
18
19
20### Member Variables
21
22| Name| Description|
23| -------- | -------- |
24| int32_t (\*[OH_AudioRenderer_OnWriteData](#oh_audiorenderer_onwritedata))([OH_AudioRenderer](_o_h_audio.md#oh_audiorenderer) \*renderer, void \*userData, void \*buffer, int32_t length) | Defines a function pointer to the callback function used to write audio data. |
25| int32_t (\*[OH_AudioRenderer_OnStreamEvent](#oh_audiorenderer_onstreamevent))([OH_AudioRenderer](_o_h_audio.md#oh_audiorenderer) \*renderer, void \*userData, [OH_AudioStream_Event](_o_h_audio.md#oh_audiostream_event) event) | Defines a function pointer to the callback function used to process audio playback stream events. |
26| int32_t (\*[OH_AudioRenderer_OnInterruptEvent](#oh_audiorenderer_oninterruptevent))([OH_AudioRenderer](_o_h_audio.md#oh_audiorenderer) \*renderer, void \*userData, [OH_AudioInterrupt_ForceType](_o_h_audio.md#oh_audiointerrupt_forcetype) type, [OH_AudioInterrupt_Hint](_o_h_audio.md#oh_audiointerrupt_hint) hint) | Defines a function pointer to the callback function used to process audio playback interruption events. |
27| int32_t (\*[OH_AudioRenderer_OnError](#oh_audiorenderer_onerror))([OH_AudioRenderer](_o_h_audio.md#oh_audiorenderer) \*renderer, void \*userData, [OH_AudioStream_Result](_o_h_audio.md#oh_audiostream_result) error) | Defines a function pointer to the callback function used to process audio playback errors. |
28
29
30## Member Variable Description
31
32> **NOTE**
33>
34> 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.
35
36
37### OH_AudioRenderer_OnError
38
39```
40int32_t (*OH_AudioRenderer_Callbacks_Struct::OH_AudioRenderer_OnError)(OH_AudioRenderer *renderer, void *userData, OH_AudioStream_Result error)
41```
42
43**Description**
44
45Defines a function pointer to the callback function used to process audio playback errors.
46
47**Parameters**
48
49| Name| Description|
50| -------- | -------- |
51| renderer | Pointer to an audio renderer instance, which is created by calling [OH_AudioStreamBuilder_GenerateRenderer](_o_h_audio.md#oh_audiostreambuilder_generaterenderer).|
52| userData | Pointer to the data storage area customized by the application.|
53| error | Audio playback error result defined by [OH_AudioStream_Result](_o_h_audio.md#oh_audiostream_result), which can be **AUDIOSTREAM_ERROR_INVALID_PARAM**, **AUDIOSTREAM_ERROR_ILLEGAL_STATE**, or **AUDIOSTREAM_ERROR_SYSTEM**.|
54| length | Length of the buffer.|
55
56
57### OH_AudioRenderer_OnInterruptEvent
58
59```
60int32_t (*OH_AudioRenderer_Callbacks_Struct::OH_AudioRenderer_OnInterruptEvent)(OH_AudioRenderer *renderer, void *userData, OH_AudioInterrupt_ForceType type, OH_AudioInterrupt_Hint hint)
61```
62
63**Description**
64
65Defines a function pointer to the callback function used to process audio playback interruption events.
66
67**Parameters**
68
69| Name| Description|
70| -------- | -------- |
71| renderer | Pointer to an audio renderer instance, which is created by calling [OH_AudioStreamBuilder_GenerateRenderer](_o_h_audio.md#oh_audiostreambuilder_generaterenderer).|
72| userData | Pointer to the data storage area customized by the application.|
73| type | Type of force that causes audio interruption. For details about the available options, see [OH_AudioInterrupt_ForceType](_o_h_audio.md#oh_audiointerrupt_forcetype).|
74| hint | Hint provided along with audio interruption. For details about the available options, see [OH_AudioInterrupt_Hint](_o_h_audio.md#oh_audiointerrupt_hint).|
75
76### OH_AudioRenderer_OnStreamEvent
77
78```
79int32_t (*OH_AudioRenderer_Callbacks_Struct::OH_AudioRenderer_OnStreamEvent)(OH_AudioRenderer *renderer, void *userData, OH_AudioStream_Event event)
80```
81
82**Description**
83
84Defines a function pointer to the callback function used to process audio playback stream events.
85
86**Parameters**
87
88| Name| Description|
89| -------- | -------- |
90| renderer | Pointer to an audio renderer instance, which is created by calling [OH_AudioStreamBuilder_GenerateRenderer](_o_h_audio.md#oh_audiostreambuilder_generaterenderer).|
91| userData | Pointer to the data storage area customized by the application.|
92| event | Audio event defined in [OH_AudioStream_Event](_o_h_audio.md#oh_audiostream_event).|
93
94
95### OH_AudioRenderer_OnWriteData
96
97```
98int32_t (*OH_AudioRenderer_Callbacks_Struct::OH_AudioRenderer_OnWriteData)(OH_AudioRenderer *renderer, void *userData, void *buffer, int32_t length)
99```
100
101**Description**
102
103Defines a function pointer to the callback function used to write audio data.
104
105The callback function is used only to write audio data. Do not call AudioRenderer APIs in it.
106
107Once 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.
108
109**Parameters**
110
111| Name| Description|
112| -------- | -------- |
113| renderer | Pointer to an audio renderer instance, which is created by calling [OH_AudioStreamBuilder_GenerateRenderer](_o_h_audio.md#oh_audiostreambuilder_generaterenderer).|
114| userData | Pointer to the data storage area customized by the application.|
115| buffer | Pointer to the playback data storage area, which is used by the application to fill in playback data.|
116| length | Length of the buffer.|
117