1# OH_AudioCapturer_Callbacks_Struct 2 3## Overview 4 5The struct defines a pointer to the callback functions related to an audio capturer. 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. For details, see [Using OHAudio for Audio Recording](../../media/audio/using-ohaudio-for-recording.md). 8 9**Since**: 10 10 11**Deprecated from**: 20 12 13**Substitute** 14 15Use the following callback types for substitute: 16 17[OH_AudioCapturer_OnReadDataCallback](capi-native-audiocapturer-h.md#oh_audiocapturer_onreaddatacallback), [OH_AudioCapturer_OnDeviceChangeCallback](capi-native-audiocapturer-h.md#oh_audiocapturer_ondevicechangecallback), [OH_AudioCapturer_OnInterruptCallback](capi-native-audiocapturer-h.md#oh_audiocapturer_oninterruptcallback), and [OH_AudioCapturer_OnErrorCallback](capi-native-audiocapturer-h.md#oh_audiocapturer_onerrorcallback) 18 19**Related module**: [OHAudio](capi-ohaudio.md) 20 21**Header file**: [native_audiostream_base.h](capi-native-audiostream-base-h.md) 22 23## Summary 24 25### Member Functions 26 27| Name| Description| 28| -- | -- | 29| [int32_t (\*OH_AudioCapturer_OnReadData)(OH_AudioCapturer* capturer,void* userData,void* buffer,int32_t length)](#oh_audiocapturer_onreaddata) | Defines a function pointer to the callback function used to read audio data.| 30| [int32_t (\*OH_AudioCapturer_OnStreamEvent)(OH_AudioCapturer* capturer,void* userData,OH_AudioStream_Event event)](#oh_audiocapturer_onstreamevent) | Defines a function pointer to the callback function used to process audio recording stream events.| 31| [int32_t (\*OH_AudioCapturer_OnInterruptEvent)(OH_AudioCapturer* capturer,void* userData,OH_AudioInterrupt_ForceType type,OH_AudioInterrupt_Hint hint)](#oh_audiocapturer_oninterruptevent) | Defines a function pointer to the callback function used to process audio recording interruption events.| 32| [int32_t (\*OH_AudioCapturer_OnError)(OH_AudioCapturer* capturer, void* userData, OH_AudioStream_Result error)](#oh_audiocapturer_onerror)| Defines a function pointer to the callback function used to process audio recording errors.| 33 34## Member Function Description 35 36> **NOTE** 37> 38> 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. 39 40### OH_AudioCapturer_OnReadData() 41 42``` 43int32_t (*OH_AudioCapturer_OnReadData)(OH_AudioCapturer* capturer,void* userData,void* buffer,int32_t length) 44``` 45 46**Description** 47 48Defines a function pointer to the callback function used to read audio data. 49 50The callback function is used only to read audio data. Do not call AudioCapturer APIs in it. 51 52**Since**: 10 53 54**Deprecated from**: 20 55 56**Substitute**: [OH_AudioCapturer_OnReadDataCallback](capi-native-audiocapturer-h.md#oh_audiocapturer_onreaddatacallback) 57 58**Parameters** 59 60| Name| Description| 61| -- | -- | 62| [OH_AudioCapturer](capi-ohaudio-oh-audiocapturerstruct.md)* capturer | Pointer to an audio capturer instance, which is created by calling [OH_AudioStreamBuilder_GenerateCapturer](capi-native-audiostreambuilder-h.md#oh_audiostreambuilder_generatecapturer).| 63| void* userData | Pointer to the data storage area customized by the application. | 64| void* buffer | Pointer to the playback data storage area, which is used by the application to fill in playback data. | 65| int32_t length | Length of the buffer. | 66 67### OH_AudioCapturer_OnStreamEvent() 68 69``` 70int32_t (*OH_AudioCapturer_OnStreamEvent)(OH_AudioCapturer* capturer,void* userData,OH_AudioStream_Event event) 71``` 72 73**Description** 74 75Defines a function pointer to the callback function used to process audio recording stream events. 76 77**Since**: 10 78 79**Deprecated from**: 20 80 81**Substitute**: [OH_AudioCapturer_OnDeviceChangeCallback](capi-native-audiocapturer-h.md#oh_audiocapturer_ondevicechangecallback) 82 83**Parameters** 84 85| Name| Description| 86| -- | -- | 87| [OH_AudioCapturer](capi-ohaudio-oh-audiocapturerstruct.md)* capturer | Pointer to an audio capturer instance, which is created by calling [OH_AudioStreamBuilder_GenerateCapturer](capi-native-audiostreambuilder-h.md#oh_audiostreambuilder_generatecapturer).| 88| void* userData | Pointer to the data storage area customized by the application.| 89| [OH_AudioStream_Event](capi-native-audiostream-base-h.md#oh_audiostream_event) event | Audio event.| 90 91### OH_AudioCapturer_OnInterruptEvent() 92 93``` 94int32_t (*OH_AudioCapturer_OnInterruptEvent)(OH_AudioCapturer* capturer,void* userData,OH_AudioInterrupt_ForceType type,OH_AudioInterrupt_Hint hint) 95``` 96 97**Description** 98 99Defines a function pointer to the callback function used to process audio recording interruption events. 100 101**Since**: 10 102 103**Deprecated from**: 20 104 105**Substitute**: [OH_AudioCapturer_OnInterruptCallback](capi-native-audiocapturer-h.md#oh_audiocapturer_oninterruptcallback) 106 107**Parameters** 108 109| Name | Description| 110|--| -- | 111| [OH_AudioCapturer](capi-ohaudio-oh-audiocapturerstruct.md)* capturer | Pointer to an audio capturer instance, which is created by calling [OH_AudioStreamBuilder_GenerateCapturer](capi-native-audiostreambuilder-h.md#oh_audiostreambuilder_generatecapturer).| 112| void* userData | Pointer to the data storage area customized by the application.| 113| [OH_AudioInterrupt_ForceType](capi-native-audiostream-base-h.md#oh_audiointerrupt_forcetype) type | Type of force that causes audio interruption.| 114| [OH_AudioInterrupt_Hint](capi-native-audiostream-base-h.md#oh_audiointerrupt_hint) hint | Hint provided along with audio interruption.| 115 116 117### OH_AudioCapturer_OnError() 118 119``` 120int32_t (*OH_AudioCapturer_OnError)(OH_AudioCapturer* capturer, void* userData, OH_AudioStream_Result error) 121``` 122 123**Description** 124 125Defines a function pointer to the callback function used to process audio recording errors. 126 127**Since**: 10 128 129**Deprecated from**: 20 130 131**Substitute**: [OH_AudioCapturer_OnErrorCallback](capi-native-audiocapturer-h.md#oh_audiocapturer_onerrorcallback) 132 133**Parameters** 134 135| Name | Description| 136|--| -- | 137| [OH_AudioCapturer](capi-ohaudio-oh-audiocapturerstruct.md)* capturer | Pointer to an audio capturer instance, which is created by calling [OH_AudioStreamBuilder_GenerateCapturer](capi-native-audiostreambuilder-h.md#oh_audiostreambuilder_generatecapturer).| 138| void* userData | Pointer to the data storage area customized by the application.| 139| [OH_AudioStream_Result](capi-native-audiostream-base-h.md#oh_audiostream_result) error | Audio recording error result, which may be **AUDIOSTREAM_ERROR_INVALID_PARAM**, **AUDIOSTREAM_ERROR_ILLEGAL_STATE**, or **AUDIOSTREAM_ERROR_SYSTEM**.| 140