native_audiostreambuilder.h
Overview
The file declares the functions related to an audio stream builder.
You can use the functions to create and destroy an audio stream builder, set audio stream attributes, and set callbacks.
File to include: <ohaudio/native_audiostreambuilder.h>
Library: libohaudio.so
System capability: SystemCapability.Multimedia.Audio.Core
Since: 10
Related module: OHAudio
Summary
Functions
Function Description
OH_AudioStreamBuilder_Create()
OH_AudioStream_Result OH_AudioStreamBuilder_Create(OH_AudioStreamBuilder** builder, OH_AudioStream_Type type)
Description
Creates an audio stream builder, which can be an audio renderer or capturer.
You need to call OH_AudioStreamBuilder_Destroy to destroy the builder when it is no longer required.
Since: 10
Parameters
| Name | Description |
|---|---|
| OH_AudioStreamBuilder** builder | Double pointer to the audio stream builder created. |
| OH_AudioStream_Type type | Type of the audio stream builder, which can be AUDIOSTREAM_TYPE_RENDERER or AUDIOSTREAM_TYPE_CAPTURER. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. |
OH_AudioStreamBuilder_Destroy()
OH_AudioStream_Result OH_AudioStreamBuilder_Destroy(OH_AudioStreamBuilder* builder)
Description
Destroys an audio stream builder.
You need to call this function to destroy the builder when it is no longer required.
Since: 10
Parameters
| Name | Description |
|---|---|
| OH_AudioStreamBuilder* builder | Pointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: The builder parameter is nullptr. AUDIOSTREAM_ERROR_ILLEGAL_STATE: The execution status is abnormal. |
OH_AudioStreamBuilder_SetSamplingRate()
OH_AudioStream_Result OH_AudioStreamBuilder_SetSamplingRate(OH_AudioStreamBuilder* builder, int32_t rate)
Description
Sets the sampling rate of an audio stream.
Since: 10
Parameters
| Name | Description |
|---|---|
| OH_AudioStreamBuilder* builder | Pointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create. |
| int32_t rate | Sampling rate. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: 1. The builder parameter is nullptr. 2. The rate parameter is invalid. |
OH_AudioStreamBuilder_SetChannelCount()
OH_AudioStream_Result OH_AudioStreamBuilder_SetChannelCount(OH_AudioStreamBuilder* builder, int32_t channelCount)
Description
Sets the number of channels for an audio stream.
Since: 10
Parameters
| Name | Description |
|---|---|
| OH_AudioStreamBuilder* builder | Pointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create. |
| int32_t channelCount | Number of channels. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: 1. The builder parameter is nullptr. 2. The channelCount parameter is invalid. |
OH_AudioStreamBuilder_SetSampleFormat()
OH_AudioStream_Result OH_AudioStreamBuilder_SetSampleFormat(OH_AudioStreamBuilder* builder,OH_AudioStream_SampleFormat format)
Description
Sets the sampling format of an audio stream.
Since: 10
Parameters
| Name | Description |
|---|---|
| OH_AudioStreamBuilder* builder | Pointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create. |
| OH_AudioStream_SampleFormat format | Sampling format. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: The builder parameter is nullptr. |
OH_AudioStreamBuilder_SetEncodingType()
OH_AudioStream_Result OH_AudioStreamBuilder_SetEncodingType(OH_AudioStreamBuilder* builder,OH_AudioStream_EncodingType encodingType)
Description
Sets the encoding type of an audio stream.
Since: 10
Parameters
| Name | Description |
|---|---|
| OH_AudioStreamBuilder* builder | Pointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create. |
| OH_AudioStream_EncodingType encodingType | Encoding type. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: The builder parameter is nullptr. |
OH_AudioStreamBuilder_SetLatencyMode()
OH_AudioStream_Result OH_AudioStreamBuilder_SetLatencyMode(OH_AudioStreamBuilder* builder,OH_AudioStream_LatencyMode latencyMode)
Description
Sets the latency mode of an audio stream.
Since: 10
Parameters
| Name | Description |
|---|---|
| OH_AudioStreamBuilder* builder | Pointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create. |
| OH_AudioStream_LatencyMode latencyMode | Latency mode. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: The builder parameter is nullptr. |
OH_AudioStreamBuilder_SetChannelLayout()
OH_AudioStream_Result OH_AudioStreamBuilder_SetChannelLayout(OH_AudioStreamBuilder* builder,OH_AudioChannelLayout channelLayout)
Description
Sets the channel layout for an audio stream.
Since: 12
Parameters
| Name | Description |
|---|---|
| OH_AudioStreamBuilder* builder | Pointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create. |
| OH_AudioChannelLayout channelLayout | Channel layout. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: The builder parameter is nullptr. |
OH_AudioStreamBuilder_SetRendererInfo()
OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererInfo(OH_AudioStreamBuilder* builder,OH_AudioStream_Usage usage)
Description
Sets the usage scenario of an audio renderer.
Since: 10
Parameters
| Name | Description |
|---|---|
| OH_AudioStreamBuilder* builder | Pointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create. |
| OH_AudioStream_Usage usage | Usage scenario of the audio renderer. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: 1. The builder parameter is nullptr. 2. The usage parameter is invalid. |
OH_AudioStreamBuilder_SetVolumeMode()
OH_AudioStream_Result OH_AudioStreamBuilder_SetVolumeMode(OH_AudioStreamBuilder* builder,OH_AudioStream_VolumeMode volumeMode)
Description
Sets the volume mode for an audio stream.
Since: 19
Parameters
| Name | Description |
|---|---|
| OH_AudioStreamBuilder* builder | Pointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create. |
| OH_AudioStream_VolumeMode volumeMode | Volume mode of the audio stream. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: 1. The builder parameter is nullptr. 2. The volumeMode parameter is invalid. |
OH_AudioStreamBuilder_SetCapturerInfo()
OH_AudioStream_Result OH_AudioStreamBuilder_SetCapturerInfo(OH_AudioStreamBuilder* builder,OH_AudioStream_SourceType sourceType)
Description
Sets the usage scenario of an audio capturer.
Since: 10
Parameters
| Name | Description |
|---|---|
| OH_AudioStreamBuilder* builder | Pointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create. |
| OH_AudioStream_SourceType sourceType | Usage scenario of the audio capturer. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: 1. The builder parameter is nullptr. 2. The sourceType parameter is invalid. |
OH_AudioStreamBuilder_SetRendererCallback()
OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererCallback(OH_AudioStreamBuilder* builder,OH_AudioRenderer_Callbacks callbacks, void* userData)
Description
Sets callbacks for an audio renderer.
Since: 10
Deprecated from: 20
Substitute
Use the following APIs for substitute:
OH_AudioStreamBuilder_SetRendererWriteDataCallback, OH_AudioStreamBuilder_SetRendererInterruptCallback, OH_AudioStreamBuilder_SetRendererOutputDeviceChangeCallback, and OH_AudioStreamBuilder_SetRendererErrorCallback
Parameters
| Name | Description |
|---|---|
| OH_AudioStreamBuilder* builder | Pointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create. |
| OH_AudioRenderer_Callbacks callbacks | Callbacks that will be used to process events related to audio output streams. |
| void* userData | Pointer to the application data passed through the callbacks. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: 1. The builder parameter is nullptr. 2. The StreamType parameter is invalid. |
OH_AudioStreamBuilder_SetRendererOutputDeviceChangeCallback()
OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererOutputDeviceChangeCallback(OH_AudioStreamBuilder* builder,OH_AudioRenderer_OutputDeviceChangeCallback callback, void* userData)
Description
Sets the callback for audio renderer device change events.
Since: 11
Parameters
| Name | Description |
|---|---|
| OH_AudioStreamBuilder* builder | Pointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create. |
| OH_AudioRenderer_OutputDeviceChangeCallback callback | Callback that will be used to process events related to audio renderer device changes. |
| void* userData | Pointer to the application data passed through the callbacks. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: 1. The builder parameter is nullptr. 2. The StreamType parameter is invalid. |
OH_AudioStreamBuilder_SetRendererPrivacy()
OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererPrivacy(OH_AudioStreamBuilder* builder,OH_AudioStream_PrivacyType privacy)
Description
Sets the privacy type for the audio stream being played. The privacy type specifies whether the audio stream can be recorded by other applications.
Since: 12
Parameters
| Name | Description |
|---|---|
| OH_AudioStreamBuilder* builder | Pointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create. |
| OH_AudioStream_PrivacyType privacy | Privacy type, which specifies whether the audio stream can be recorded by other applications. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: 1. The builder parameter is nullptr. 2. The StreamType parameter is invalid. |
OH_AudioStreamBuilder_SetCapturerCallback()
OH_AudioStream_Result OH_AudioStreamBuilder_SetCapturerCallback(OH_AudioStreamBuilder* builder,OH_AudioCapturer_Callbacks callbacks, void* userData)
Description
Sets callbacks for an audio capturer.
Since: 10
Deprecated from: 20
Substitute
Use the following APIs for substitute:
OH_AudioStreamBuilder_SetCapturerReadDataCallback, OH_AudioStreamBuilder_SetCapturerDeviceChangeCallback, OH_AudioStreamBuilder_SetCapturerInterruptCallback, and OH_AudioStreamBuilder_SetCapturerErrorCallback
Parameters
| Name | Description |
|---|---|
| OH_AudioStreamBuilder* builder | Pointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create. |
| OH_AudioCapturer_Callbacks callbacks | Callbacks that will be used to process events related to audio input streams. |
| void* userData | Pointer to the application data passed through the callbacks. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: 1. The builder parameter is nullptr. 2. The StreamType parameter is invalid. |
OH_AudioStreamBuilder_SetWriteDataWithMetadataCallback()
OH_AudioStream_Result OH_AudioStreamBuilder_SetWriteDataWithMetadataCallback(OH_AudioStreamBuilder* builder,OH_AudioRenderer_WriteDataWithMetadataCallback callback, void* userData)
Description
Sets the callback used to write both audio data and metadata.
Since: 12
Parameters
| Name | Description |
|---|---|
| OH_AudioStreamBuilder* builder | Pointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create. |
| OH_AudioRenderer_WriteDataWithMetadataCallback callback | Callback used to write both audio data and metadata. |
| void* userData | Pointer to the application data passed through the callbacks. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: 1. The builder parameter is nullptr. 2. The StreamType parameter is invalid. |
OH_AudioStreamBuilder_GenerateRenderer()
OH_AudioStream_Result OH_AudioStreamBuilder_GenerateRenderer(OH_AudioStreamBuilder* builder,OH_AudioRenderer** audioRenderer)
Description
Creates an audio renderer instance.
Since: 10
Parameters
| Name | Description |
|---|---|
| OH_AudioStreamBuilder* builder | Pointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create. |
| OH_AudioRenderer** audioRenderer | Double pointer to the audio renderer instance created. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: 1. The builder parameter is nullptr. 2. The StreamType parameter is invalid. 3. The OHAudioRenderer instance fails to be created. |
OH_AudioStreamBuilder_GenerateCapturer()
OH_AudioStream_Result OH_AudioStreamBuilder_GenerateCapturer(OH_AudioStreamBuilder* builder,OH_AudioCapturer** audioCapturer)
Description
Creates an audio capturer instance.
Since: 10
Parameters
| Name | Description |
|---|---|
| OH_AudioStreamBuilder* builder | Pointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create. |
| OH_AudioCapturer** audioCapturer | Double pointer to the audio capturer instance created. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: 1. The builder parameter is nullptr. 2. The StreamType parameter is invalid. 3. The OHAudioCapturer instance fails to be created. |
OH_AudioStreamBuilder_SetFrameSizeInCallback()
OH_AudioStream_Result OH_AudioStreamBuilder_SetFrameSizeInCallback(OH_AudioStreamBuilder* builder,int32_t frameSize)
Description
Sets the frame size for each callback during playback. The frame size must be at least equal to the size of the data processed by the audio hardware at a time and less than half of the internal buffer capacity.
In the case of low-latency playback, frameSize can be set to the frame length corresponding to the audio that lasts for 5 ms, 10 ms, 15 ms, or 20 ms.
In the case of common playback, frameSize can be set to the frame length corresponding to the audio that lasts for 20 ms to 100 ms. For example, if the sampling rate is 48000 Hz, the frame length of 20 ms audio data is calculated as follows: frameSize = 48000 x 0.02, that is, 960 sampling points.
Since: 11
Parameters
| Name | Description |
|---|---|
| OH_AudioStreamBuilder* builder | Pointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create. |
| int32_t frameSize | Frame size. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: The builder parameter is nullptr. |
OH_AudioStreamBuilder_SetRendererInterruptMode()
OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererInterruptMode(OH_AudioStreamBuilder* builder,OH_AudioInterrupt_Mode mode)
Description
Sets the interrupt mode of the stream client.
Since: 12
Parameters
| Name | Description |
|---|---|
| OH_AudioStreamBuilder* builder | Pointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create. |
| OH_AudioInterrupt_Mode mode | Audio interruption mode. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: 1. The builder parameter is nullptr. 2. The mode parameter is invalid. 3. The StreamType parameter is invalid. |
OH_AudioStreamBuilder_SetRendererWriteDataCallback()
OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererWriteDataCallback(OH_AudioStreamBuilder* builder,OH_AudioRenderer_OnWriteDataCallback callback, void* userData)
Description
Sets the callback used to write audio data.
This function is similar to OH_AudioStreamBuilder_SetRendererCallback. If both the functions are used, only the last callback takes effect.
Since: 12
Parameters
| Name | Description |
|---|---|
| OH_AudioStreamBuilder* builder | Pointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create. |
| OH_AudioRenderer_OnWriteDataCallback callback | Callback to be used to write audio data. |
| void* userData | Pointer to the application data passed through the callbacks. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: 1. The builder parameter is nullptr. 2. The StreamType parameter is invalid. |
OH_AudioStreamBuilder_SetRendererWriteDataCallbackAdvanced()
OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererWriteDataCallbackAdvanced(OH_AudioStreamBuilder* builder,OH_AudioRenderer_OnWriteDataCallbackAdvanced callback, void* userData)
Description
Sets the callback used to write audio data.
This function is similar to OH_AudioStreamBuilder_SetRendererWriteDataCallback.
If both the functions are used, only the last callback takes effect.
Unlike OH_AudioStreamBuilder_SetRendererWriteDataCallback, OH_AudioStreamBuilder_SetRendererWriteDataCallbackAdvanced allows an application to pass variable-length audio data and notify the system of the length of the data written.
Since: 20
Parameters
| Name | Description |
|---|---|
| OH_AudioStreamBuilder* builder | Pointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create. |
| OH_AudioRenderer_OnWriteDataCallbackAdvanced callback | Callback to be used to write audio data. |
| void* userData | Pointer to the application data passed through the callbacks. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: An input parameter is invalid. For example, the builder parameter is nullptr. |
OH_AudioStreamBuilder_SetRendererInterruptCallback()
OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererInterruptCallback(OH_AudioStreamBuilder* builder,OH_AudioRenderer_OnInterruptCallback callback, void* userData)
Description
Sets the callback for interruption events of an audio renderer.
This function is similar to OH_AudioStreamBuilder_SetRendererCallback. If both the functions are used, only the last callback takes effect.
Since: 20
Parameters
| Name | Description |
|---|---|
| OH_AudioStreamBuilder* builder | Pointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create. |
| OH_AudioRenderer_OnInterruptCallback callback | Callback used to receive interruption events. |
| void* userData | Pointer to the application data struct that will be passed to the callback. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: A parameter is invalid. For example, the builder parameter is nullptr. |
OH_AudioStreamBuilder_SetRendererErrorCallback()
OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererErrorCallback(OH_AudioStreamBuilder* builder,OH_AudioRenderer_OnErrorCallback callback, void* userData)
Description
Sets the callback for error events of an audio renderer.
This function is similar to OH_AudioStreamBuilder_SetRendererCallback. If both the functions are used, only the last callback takes effect.
Since: 20
Parameters
| Name | Description |
|---|---|
| OH_AudioStreamBuilder* builder | Pointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create. |
| OH_AudioRenderer_OnErrorCallback callback | Callback used to receive error events. |
| void* userData | Pointer to the application data struct that will be passed to the callback. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: A parameter is invalid. For example, the builder parameter is nullptr. |
OH_AudioStreamBuilder_SetCapturerReadDataCallback()
OH_AudioStream_Result OH_AudioStreamBuilder_SetCapturerReadDataCallback(OH_AudioStreamBuilder* builder,OH_AudioCapturer_OnReadDataCallback callback, void* userData)
Description
Sets the callback used to read data for an audio capturer.
This function is similar to OH_AudioStreamBuilder_SetCapturerCallback. If both the functions are used, only the last callback takes effect.
Since: 20
Parameters
| Name | Description |
|---|---|
| OH_AudioStreamBuilder* builder | Pointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create. |
| OH_AudioCapturer_OnReadDataCallback callback | Callback used to receive data read events. |
| void* userData | Pointer to the application data struct that will be passed to the callback. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: A parameter is invalid. For example, the builder parameter is nullptr. |
OH_AudioStreamBuilder_SetCapturerDeviceChangeCallback()
OH_AudioStream_Result OH_AudioStreamBuilder_SetCapturerDeviceChangeCallback(OH_AudioStreamBuilder* builder,OH_AudioCapturer_OnDeviceChangeCallback callback, void* userData)
Description
Sets the callback for audio capturer device change events.
This function is similar to OH_AudioStreamBuilder_SetCapturerCallback. If both the functions are used, only the last callback takes effect.
Since: 20
Parameters
| Name | Description |
|---|---|
| OH_AudioStreamBuilder* builder | Pointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create. |
| OH_AudioCapturer_OnDeviceChangeCallback callback | Callback used to receive device change events. |
| void* userData | Pointer to the application data struct that will be passed to the callback. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: A parameter is invalid. For example, the builder parameter is nullptr. |
OH_AudioStreamBuilder_SetCapturerInterruptCallback()
OH_AudioStream_Result OH_AudioStreamBuilder_SetCapturerInterruptCallback(OH_AudioStreamBuilder* builder,OH_AudioCapturer_OnInterruptCallback callback, void* userData)
Description
Sets the callback for interruption events of an audio capturer.
This function is similar to OH_AudioStreamBuilder_SetCapturerCallback. If both the functions are used, only the last callback takes effect.
Since: 20
Parameters
| Name | Description |
|---|---|
| OH_AudioStreamBuilder* builder | Pointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create. |
| OH_AudioCapturer_OnInterruptCallback callback | Callback used to receive interruption events. |
| void* userData | Pointer to the application data struct that will be passed to the callback. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: A parameter is invalid. For example, the builder parameter is nullptr. |
OH_AudioStreamBuilder_SetCapturerErrorCallback()
OH_AudioStream_Result OH_AudioStreamBuilder_SetCapturerErrorCallback(OH_AudioStreamBuilder* builder,OH_AudioCapturer_OnErrorCallback callback, void* userData)
Description
Sets the callback for error events of an audio capturer.
This function is similar to OH_AudioStreamBuilder_SetCapturerCallback. If both the functions are used, only the last callback takes effect.
Since: 20
Parameters
| Name | Description |
|---|---|
| OH_AudioStreamBuilder* builder | Pointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create. |
| OH_AudioCapturer_OnErrorCallback callback | Callback used to receive error events. |
| void* userData | Pointer to the application data struct that will be passed to the callback. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: A parameter is invalid. For example, the builder parameter is nullptr. |
OH_AudioStreamBuilder_SetCapturerWillMuteWhenInterrupted()
OH_AudioStream_Result OH_AudioStreamBuilder_SetCapturerWillMuteWhenInterrupted(OH_AudioStreamBuilder* builder,bool muteWhenInterrupted)
Description
Sets whether to mute the audio input stream when an audio interruption occurs.
Since: 20
Parameters
| Name | Description |
|---|---|
| OH_AudioStreamBuilder* builder | Pointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create. |
| bool muteWhenInterrupted | Whether to mute the audio stream when an audio interruption occurs. true to mute, false otherwise (default interruption mode used). |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: A parameter is invalid. For example, the builder parameter is nullptr. |
OH_AudioStreamBuilder_SetRendererFastStatusChangeCallback()
OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererFastStatusChangeCallback(OH_AudioStreamBuilder* builder,OH_AudioRenderer_OnFastStatusChange callback, void* userData)
Description
Sets a callback for low-latency status changes during audio playback.
Since: 20
Parameters
| Name | Description |
|---|---|
| OH_AudioStreamBuilder* builder | Pointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create. |
| OH_AudioRenderer_OnFastStatusChange callback | Callback invoked for low-latency status changes during audio playback. |
| void* userData | Pointer to the application data struct that will be passed to the callback. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: A parameter is invalid. For example, the builder parameter is nullptr. |
OH_AudioStreamBuilder_SetCapturerFastStatusChangeCallback()
OH_AudioStream_Result OH_AudioStreamBuilder_SetCapturerFastStatusChangeCallback(OH_AudioStreamBuilder* builder,OH_AudioCapturer_OnFastStatusChange callback, void* userData)
Description
Sets a callback for low-latency status changes during audio recording.
Since: 20
Parameters
| Name | Description |
|---|---|
| OH_AudioStreamBuilder* builder | Pointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create. |
| OH_AudioCapturer_OnFastStatusChange callback | Callback invoked for low-latency status changes during audio recording. |
| void* userData | Pointer to the application data struct that will be passed to the callback. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: A parameter is invalid. For example, the builder parameter is nullptr. |
OH_AudioStreamBuilder_SetPlaybackCaptureMode()
OH_AudioStream_Result OH_AudioStreamBuilder_SetPlaybackCaptureMode(OH_AudioStreamBuilder* builder, uint32_t mode)
Description
Sets the audio modes for internal audio recording (capturing sound from the applications on the device). The modes determine the types of audio streams to be recorded. This function applies only to AudioStream_Type_Capturer. This API is currently not available for public use.
Since: 23
Parameters
| Name | Description |
|---|---|
| OH_AudioStreamBuilder* builder | Pointer to a builder instance created by OH_AudioStreamBuilder_Create. |
| uint32_t mode | Internal audio recording modes to be set. The value can be a combination of multiple values in OH_AudioStream_PlaybackCaptureMode. |
Returns
| Type | Description |
|---|---|
| OH_AudioStream_Result | AUDIOSTREAM_SUCCESS: The function is executed successfully. AUDIOSTREAM_ERROR_INVALID_PARAM: Invalid parameters. For example, builder or mode is nullptr. |
你可能感兴趣的鸿蒙文章
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
openharmony 鸿蒙 capi-ohaudio-oh-audiostreaminfo