openharmony 鸿蒙 capi-native-audiostreambuilder-h

2026-08-25 浏览 (1)

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

NameDescription
OH_AudioStream_Result OH_AudioStreamBuilder_Create(OH_AudioStreamBuilder** builder, OH_AudioStream_Type type)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.
OH_AudioStream_Result OH_AudioStreamBuilder_Destroy(OH_AudioStreamBuilder* builder)Destroys an audio stream builder.
You need to call this function to destroy the builder when it is no longer required.
OH_AudioStream_Result OH_AudioStreamBuilder_SetSamplingRate(OH_AudioStreamBuilder* builder, int32_t rate)Sets the sampling rate of an audio stream.
OH_AudioStream_Result OH_AudioStreamBuilder_SetChannelCount(OH_AudioStreamBuilder* builder, int32_t channelCount)Sets the number of channels for an audio stream.
OH_AudioStream_Result OH_AudioStreamBuilder_SetSampleFormat(OH_AudioStreamBuilder* builder, OH_AudioStream_SampleFormat format)Sets the sampling format of an audio stream.
OH_AudioStream_Result OH_AudioStreamBuilder_SetEncodingType(OH_AudioStreamBuilder* builder, OH_AudioStream_EncodingType encodingType)Sets the encoding type of an audio stream.
OH_AudioStream_Result OH_AudioStreamBuilder_SetLatencyMode(OH_AudioStreamBuilder* builder, OH_AudioStream_LatencyMode latencyMode)Sets the latency mode of an audio stream.
OH_AudioStream_Result OH_AudioStreamBuilder_SetChannelLayout(OH_AudioStreamBuilder* builder, OH_AudioChannelLayout channelLayout)Sets the channel layout for an audio stream.
OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererInfo(OH_AudioStreamBuilder* builder, OH_AudioStream_Usage usage)Sets the usage scenario of an audio renderer.
OH_AudioStream_Result OH_AudioStreamBuilder_SetVolumeMode(OH_AudioStreamBuilder* builder, OH_AudioStream_VolumeMode volumeMode)Sets the volume mode for an audio stream.
OH_AudioStream_Result OH_AudioStreamBuilder_SetCapturerInfo(OH_AudioStreamBuilder* builder, OH_AudioStream_SourceType sourceType)Sets the usage scenario of an audio capturer.
OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererCallback(OH_AudioStreamBuilder* builder, OH_AudioRenderer_Callbacks callbacks, void* userData)Sets callbacks for an audio renderer.
OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererOutputDeviceChangeCallback(OH_AudioStreamBuilder* builder, OH_AudioRenderer_OutputDeviceChangeCallback callback, void* userData)Sets the callback for audio renderer device change events.
OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererPrivacy(OH_AudioStreamBuilder* builder, OH_AudioStream_PrivacyType privacy)Sets the privacy type for the audio stream being played. The privacy type specifies whether the audio stream can be recorded by other applications.
OH_AudioStream_Result OH_AudioStreamBuilder_SetCapturerCallback(OH_AudioStreamBuilder* builder, OH_AudioCapturer_Callbacks callbacks, void* userData)Sets callbacks for an audio capturer.
OH_AudioStream_Result OH_AudioStreamBuilder_SetWriteDataWithMetadataCallback(OH_AudioStreamBuilder* builder, OH_AudioRenderer_WriteDataWithMetadataCallback callback, void* userData)Sets the callback used to write both audio data and metadata.
OH_AudioStream_Result OH_AudioStreamBuilder_GenerateRenderer(OH_AudioStreamBuilder* builder, OH_AudioRenderer** audioRenderer)Creates an audio renderer instance.
OH_AudioStream_Result OH_AudioStreamBuilder_GenerateCapturer(OH_AudioStreamBuilder* builder, OH_AudioCapturer** audioCapturer)Creates an audio capturer instance.
OH_AudioStream_Result OH_AudioStreamBuilder_SetFrameSizeInCallback(OH_AudioStreamBuilder* builder, int32_t frameSize)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.
OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererInterruptMode(OH_AudioStreamBuilder* builder, OH_AudioInterrupt_Mode mode)Sets the interrupt mode of the stream client.
OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererWriteDataCallback(OH_AudioStreamBuilder* builder, OH_AudioRenderer_OnWriteDataCallback callback, void* userData)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.
OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererWriteDataCallbackAdvanced(OH_AudioStreamBuilder* builder, OH_AudioRenderer_OnWriteDataCallbackAdvanced callback, void* userData)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.
OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererInterruptCallback(OH_AudioStreamBuilder* builder, OH_AudioRenderer_OnInterruptCallback callback, void* userData)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.
OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererErrorCallback(OH_AudioStreamBuilder* builder, OH_AudioRenderer_OnErrorCallback callback, void* userData)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.
OH_AudioStream_Result OH_AudioStreamBuilder_SetCapturerReadDataCallback(OH_AudioStreamBuilder* builder, OH_AudioCapturer_OnReadDataCallback callback, void* userData)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.
OH_AudioStream_Result OH_AudioStreamBuilder_SetCapturerDeviceChangeCallback(OH_AudioStreamBuilder* builder, OH_AudioCapturer_OnDeviceChangeCallback callback, void* userData)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.
OH_AudioStream_Result OH_AudioStreamBuilder_SetCapturerInterruptCallback(OH_AudioStreamBuilder* builder, OH_AudioCapturer_OnInterruptCallback callback, void* userData)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.
OH_AudioStream_Result OH_AudioStreamBuilder_SetCapturerErrorCallback(OH_AudioStreamBuilder* builder, OH_AudioCapturer_OnErrorCallback callback, void* userData)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.
OH_AudioStream_Result OH_AudioStreamBuilder_SetCapturerWillMuteWhenInterrupted(OH_AudioStreamBuilder* builder, bool muteWhenInterrupted)Sets whether to mute the audio input stream when an audio interruption occurs.
OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererFastStatusChangeCallback(OH_AudioStreamBuilder* builder, OH_AudioRenderer_OnFastStatusChange callback, void* userData)Sets a callback for low-latency status changes during audio playback.
OH_AudioStream_Result OH_AudioStreamBuilder_SetCapturerFastStatusChangeCallback(OH_AudioStreamBuilder* builder, OH_AudioCapturer_OnFastStatusChange callback, void* userData)Sets a callback for low-latency status changes during audio recording.
OH_AudioStream_Result OH_AudioStreamBuilder_SetPlaybackCaptureMode(OH_AudioStreamBuilder* builder, uint32_t mode)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.

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

NameDescription
OH_AudioStreamBuilder** builderDouble pointer to the audio stream builder created.
OH_AudioStream_Type typeType of the audio stream builder, which can be AUDIOSTREAM_TYPE_RENDERER or AUDIOSTREAM_TYPE_CAPTURER.

Returns

TypeDescription
OH_AudioStream_ResultAUDIOSTREAM_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

NameDescription
OH_AudioStreamBuilder* builderPointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create.

Returns

TypeDescription
OH_AudioStream_ResultAUDIOSTREAM_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

NameDescription
OH_AudioStreamBuilder* builderPointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create.
int32_t rateSampling rate.

Returns

TypeDescription
OH_AudioStream_ResultAUDIOSTREAM_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

NameDescription
OH_AudioStreamBuilder* builderPointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create.
int32_t channelCountNumber of channels.

Returns

TypeDescription
OH_AudioStream_ResultAUDIOSTREAM_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

NameDescription
OH_AudioStreamBuilder* builderPointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create.
OH_AudioStream_SampleFormat formatSampling format.

Returns

TypeDescription
OH_AudioStream_ResultAUDIOSTREAM_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

NameDescription
OH_AudioStreamBuilder* builderPointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create.
OH_AudioStream_EncodingType encodingTypeEncoding type.

Returns

TypeDescription
OH_AudioStream_ResultAUDIOSTREAM_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

NameDescription
OH_AudioStreamBuilder* builderPointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create.
OH_AudioStream_LatencyMode latencyModeLatency mode.

Returns

TypeDescription
OH_AudioStream_ResultAUDIOSTREAM_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

NameDescription
OH_AudioStreamBuilder* builderPointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create.
OH_AudioChannelLayout channelLayoutChannel layout.

Returns

TypeDescription
OH_AudioStream_ResultAUDIOSTREAM_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

NameDescription
OH_AudioStreamBuilder* builderPointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create.
OH_AudioStream_Usage usageUsage scenario of the audio renderer.

Returns

TypeDescription
OH_AudioStream_ResultAUDIOSTREAM_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

NameDescription
OH_AudioStreamBuilder* builderPointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create.
OH_AudioStream_VolumeMode volumeModeVolume mode of the audio stream.

Returns

TypeDescription
OH_AudioStream_ResultAUDIOSTREAM_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

NameDescription
OH_AudioStreamBuilder* builderPointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create.
OH_AudioStream_SourceType sourceTypeUsage scenario of the audio capturer.

Returns

TypeDescription
OH_AudioStream_ResultAUDIOSTREAM_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

NameDescription
OH_AudioStreamBuilder* builderPointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create.
OH_AudioRenderer_Callbacks callbacksCallbacks that will be used to process events related to audio output streams.
void* userDataPointer to the application data passed through the callbacks.

Returns

TypeDescription
OH_AudioStream_ResultAUDIOSTREAM_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

NameDescription
OH_AudioStreamBuilder* builderPointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create.
OH_AudioRenderer_OutputDeviceChangeCallback callbackCallback that will be used to process events related to audio renderer device changes.
void* userDataPointer to the application data passed through the callbacks.

Returns

TypeDescription
OH_AudioStream_ResultAUDIOSTREAM_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

NameDescription
OH_AudioStreamBuilder* builderPointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create.
OH_AudioStream_PrivacyType privacyPrivacy type, which specifies whether the audio stream can be recorded by other applications.

Returns

TypeDescription
OH_AudioStream_ResultAUDIOSTREAM_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

NameDescription
OH_AudioStreamBuilder* builderPointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create.
OH_AudioCapturer_Callbacks callbacksCallbacks that will be used to process events related to audio input streams.
void* userDataPointer to the application data passed through the callbacks.

Returns

TypeDescription
OH_AudioStream_ResultAUDIOSTREAM_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

NameDescription
OH_AudioStreamBuilder* builderPointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create.
OH_AudioRenderer_WriteDataWithMetadataCallback callbackCallback used to write both audio data and metadata.
void* userDataPointer to the application data passed through the callbacks.

Returns

TypeDescription
OH_AudioStream_ResultAUDIOSTREAM_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

NameDescription
OH_AudioStreamBuilder* builderPointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create.
OH_AudioRenderer** audioRendererDouble pointer to the audio renderer instance created.

Returns

TypeDescription
OH_AudioStream_ResultAUDIOSTREAM_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

NameDescription
OH_AudioStreamBuilder* builderPointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create.
OH_AudioCapturer** audioCapturerDouble pointer to the audio capturer instance created.

Returns

TypeDescription
OH_AudioStream_ResultAUDIOSTREAM_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

NameDescription
OH_AudioStreamBuilder* builderPointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create.
int32_t frameSizeFrame size.

Returns

TypeDescription
OH_AudioStream_ResultAUDIOSTREAM_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

NameDescription
OH_AudioStreamBuilder* builderPointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create.
OH_AudioInterrupt_Mode modeAudio interruption mode.

Returns

TypeDescription
OH_AudioStream_ResultAUDIOSTREAM_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

NameDescription
OH_AudioStreamBuilder* builderPointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create.
OH_AudioRenderer_OnWriteDataCallback callbackCallback to be used to write audio data.
void* userDataPointer to the application data passed through the callbacks.

Returns

TypeDescription
OH_AudioStream_ResultAUDIOSTREAM_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

NameDescription
OH_AudioStreamBuilder* builderPointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create.
OH_AudioRenderer_OnWriteDataCallbackAdvanced callbackCallback to be used to write audio data.
void* userDataPointer to the application data passed through the callbacks.

Returns

TypeDescription
OH_AudioStream_ResultAUDIOSTREAM_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

NameDescription
OH_AudioStreamBuilder* builderPointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create.
OH_AudioRenderer_OnInterruptCallback callbackCallback used to receive interruption events.
void* userDataPointer to the application data struct that will be passed to the callback.

Returns

TypeDescription
OH_AudioStream_ResultAUDIOSTREAM_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

NameDescription
OH_AudioStreamBuilder* builderPointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create.
OH_AudioRenderer_OnErrorCallback callbackCallback used to receive error events.
void* userDataPointer to the application data struct that will be passed to the callback.

Returns

TypeDescription
OH_AudioStream_ResultAUDIOSTREAM_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

NameDescription
OH_AudioStreamBuilder* builderPointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create.
OH_AudioCapturer_OnReadDataCallback callbackCallback used to receive data read events.
void* userDataPointer to the application data struct that will be passed to the callback.

Returns

TypeDescription
OH_AudioStream_ResultAUDIOSTREAM_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

NameDescription
OH_AudioStreamBuilder* builderPointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create.
OH_AudioCapturer_OnDeviceChangeCallback callbackCallback used to receive device change events.
void* userDataPointer to the application data struct that will be passed to the callback.

Returns

TypeDescription
OH_AudioStream_ResultAUDIOSTREAM_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

NameDescription
OH_AudioStreamBuilder* builderPointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create.
OH_AudioCapturer_OnInterruptCallback callbackCallback used to receive interruption events.
void* userDataPointer to the application data struct that will be passed to the callback.

Returns

TypeDescription
OH_AudioStream_ResultAUDIOSTREAM_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

NameDescription
OH_AudioStreamBuilder* builderPointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create.
OH_AudioCapturer_OnErrorCallback callbackCallback used to receive error events.
void* userDataPointer to the application data struct that will be passed to the callback.

Returns

TypeDescription
OH_AudioStream_ResultAUDIOSTREAM_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

NameDescription
OH_AudioStreamBuilder* builderPointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create.
bool muteWhenInterruptedWhether to mute the audio stream when an audio interruption occurs. true to mute, false otherwise (default interruption mode used).

Returns

TypeDescription
OH_AudioStream_ResultAUDIOSTREAM_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

NameDescription
OH_AudioStreamBuilder* builderPointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create.
OH_AudioRenderer_OnFastStatusChange callbackCallback invoked for low-latency status changes during audio playback.
void* userDataPointer to the application data struct that will be passed to the callback.

Returns

TypeDescription
OH_AudioStream_ResultAUDIOSTREAM_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

NameDescription
OH_AudioStreamBuilder* builderPointer to an audio stream builder instance, which is created by calling OH_AudioStreamBuilder_Create.
OH_AudioCapturer_OnFastStatusChange callbackCallback invoked for low-latency status changes during audio recording.
void* userDataPointer to the application data struct that will be passed to the callback.

Returns

TypeDescription
OH_AudioStream_ResultAUDIOSTREAM_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

NameDescription
OH_AudioStreamBuilder* builderPointer to a builder instance created by OH_AudioStreamBuilder_Create.
uint32_t modeInternal audio recording modes to be set. The value can be a combination of multiple values in OH_AudioStream_PlaybackCaptureMode.

Returns

TypeDescription
OH_AudioStream_ResultAUDIOSTREAM_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 鸿蒙 capi-ohaudio

openharmony 鸿蒙 capi-ohmidi

openharmony 鸿蒙 arkts-apis-audio-AudioManager

openharmony 鸿蒙 capi-ohaudiosuite-oh-audiosuite-spacerenderpositionparams

openharmony 鸿蒙 capi-ohaudio-oh-audiostreaminfo

openharmony 鸿蒙 errorcode-ringtone

openharmony 鸿蒙 capi-ohmidi-oh-midideviceinformation

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/q8PVs4gP