diff --git a/en/application-dev/media/audio/audio-call-development.md b/en/application-dev/media/audio/audio-call-development.md index aacbc12e9177e510e90a8fe35847b34b79382a87..b420b602972fb4c64b74015d65c0753cda3d0fe6 100644 --- a/en/application-dev/media/audio/audio-call-development.md +++ b/en/application-dev/media/audio/audio-call-development.md @@ -169,8 +169,8 @@ class Options { let bufferSize: number = 0; let audioCapturer: audio.AudioCapturer | undefined = undefined; let audioStreamInfo: audio.AudioStreamInfo = { - samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100, // Sampling rate. - channels: audio.AudioChannel.CHANNEL_1, // Channel. + samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_48000, // Sampling rate. + channels: audio.AudioChannel.CHANNEL_2, // Channel. sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE, // Sampling format. encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW // Encoding format. }; diff --git a/en/application-dev/media/audio/audio-effect-management.md b/en/application-dev/media/audio/audio-effect-management.md index a83753950b2f10878ecf9354b1a48b22053b7644..cfcb31bed8db72d91c4b911939d23dfd93a6a97f 100644 --- a/en/application-dev/media/audio/audio-effect-management.md +++ b/en/application-dev/media/audio/audio-effect-management.md @@ -22,8 +22,8 @@ Before the management, you must call [createAudioRenderer(options: AudioRenderer import { BusinessError } from '@kit.BasicServicesKit'; let audioStreamInfo: audio.AudioStreamInfo = { - samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100, - channels: audio.AudioChannel.CHANNEL_1, + samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_48000, + channels: audio.AudioChannel.CHANNEL_2, sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE, encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW }; diff --git a/en/application-dev/media/audio/audio-playback-concurrency.md b/en/application-dev/media/audio/audio-playback-concurrency.md index 6668c7b17e0d5fd915dfb6cff778580407593fad..ddb9d65b62f26f6bbdb38a1a9d5757d216b1a527 100644 --- a/en/application-dev/media/audio/audio-playback-concurrency.md +++ b/en/application-dev/media/audio/audio-playback-concurrency.md @@ -136,7 +136,7 @@ In an audio focus event, applications should pay attention to two key pieces of - **INTERRUPT_HINT_RESUME**: Audio playback or recording can be resumed. This is received only after a PAUSE message is received. - This operation cannot be forcibly performed by the system, and the corresponding **InterruptForceType** must be **INTERRUPT_SHARE**. + This operation cannot be forcibly performed by the system, and the corresponding **InterruptForceType** must be **INTERRUPT_SHARE**. - **INTERRUPT_HINT_PAUSE**: The audio stream is paused and audio focus is lost temporarily. When focus is available, **INTERRUPT_HINT_RESUME** will be received. - **INTERRUPT_HINT_STOP**: The audio stream stops and audio focus is lost. diff --git a/en/application-dev/media/audio/using-audiorenderer-for-playback.md b/en/application-dev/media/audio/using-audiorenderer-for-playback.md index 5684f182946a613bcada3c92ba1f1a6018ab852d..c1194e41cf92814ddc7e7c387a0cf2ac6127f90d 100644 --- a/en/application-dev/media/audio/using-audiorenderer-for-playback.md +++ b/en/application-dev/media/audio/using-audiorenderer-for-playback.md @@ -61,33 +61,93 @@ During application development, you are advised to use [on('stateChange')](../.. }); ``` -2. Call **on('writeData')** to subscribe to the audio data write callback. - - ```ts - import { BusinessError } from '@kit.BasicServicesKit'; - import { fileIo as fs } from '@kit.CoreFileKit'; - - class Options { - offset?: number; - length?: number; - } - - let bufferSize: number = 0; - let path = getContext().cacheDir; - // Ensure that the resource exists in the path. - let filePath = path + '/StarWars10s-2C-48000-4SW.wav'; - let file: fs.File = fs.openSync(filePath, fs.OpenMode.READ_ONLY); - let writeDataCallback = (buffer: ArrayBuffer) => { - let options: Options = { - offset: bufferSize, - length: buffer.byteLength - }; - fs.readSync(file.fd, buffer, options); - bufferSize += buffer.byteLength; - }; - - audioRenderer.on('writeData', writeDataCallback); - ``` +2. Call **on('writeData')** to subscribe to the callback for audio data writing. You are advised to use this function in API version 12, since it returns a callback result. + + - From API version 12, this function returns a callback result, enabling the system to determine whether to play the data in the callback based on the value returned. + + > **NOTE** + > + > - When the amount of data is sufficient to meet the required buffer length of the callback, you should return **audio.AudioDataCallbackResult.VALID**, and the system uses the entire data buffer for playback. Do not return **audio.AudioDataCallbackResult.VALID** in this case, as this leads to audio artifacts such as noise and playback stuttering. + > + > - When the amount of data is insufficient to meet the required buffer length of the callback, you are advised to return **audio.AudioDataCallbackResult.INVALID**. In this case, the system does not process this portion of audio data but requests data from the application again. Once the buffer is adequately filled, you can return **audio.AudioDataCallbackResult.VALID**. + > + > - Once the callback function finishes its execution, the audio service queues the data in the buffer for playback. Therefore, do not change the buffered data outside the callback. Regarding the last frame, if there is insufficient data to completely fill the buffer, you must concatenate the available data with padding to ensure that the buffer is full. This prevents any residual dirty data in the buffer from adversely affecting the playback effect. + + ```ts + import { audio } from '@kit.AudioKit'; + import { BusinessError } from '@kit.BasicServicesKit'; + import { fileIo as fs } from '@kit.CoreFileKit'; + + class Options { + offset?: number; + length?: number; + } + + let bufferSize: number = 0; + let path = getContext().cacheDir; + // Ensure that the resource exists in the path. + let filePath = path + '/StarWars10s-2C-48000-4SW.wav'; + let file: fs.File = fs.openSync(filePath, fs.OpenMode.READ_ONLY); + + let writeDataCallback = (buffer: ArrayBuffer) => { + let options: Options = { + offset: bufferSize, + length: buffer.byteLength + }; + + try { + fs.readSync(file.fd, buffer, options); + bufferSize += buffer.byteLength; + // The system determines that the buffer is valid and plays the data normally. + return audio.AudioDataCallbackResult.VALID; + } catch (error) { + console.error('Error reading file:', error); + // The system determines that the buffer is invalid and does not play the data. + return audio.AudioDataCallbackResult.INVALID; + } + }; + + audioRenderer.on('writeData', writeDataCallback); + ``` + + - In API version 11, this function does not return a callback result, and the system treats all data in the callback as valid by default. + + > **NOTE** + > + > - Ensure that the callback's data buffer is completely filled to the necessary length to prevent issues such as audio noise and playback stuttering. + > + > - If the amount of data is insufficient to fill the data buffer, you are advised to temporarily halt data writing (without pausing the audio stream), block the callback function, and wait until enough data accumulates before resuming writing, thereby ensuring that the buffer is fully filled. If you need to call AudioRenderer APIs after the callback function is blocked, unblock the callback function first. + > + > - If you do not want to play the audio data in this callback function, you can nullify the data block in the callback function. (Once nullified, the system still regards this as part of the written data, leading to silent frames during playback). + > + > - Once the callback function finishes its execution, the audio service queues the data in the buffer for playback. Therefore, do not change the buffered data outside the callback. Regarding the last frame, if there is insufficient data to completely fill the buffer, you must concatenate the available data with padding to ensure that the buffer is full. This prevents any residual dirty data in the buffer from adversely affecting the playback effect. + + ```ts + import { BusinessError } from '@kit.BasicServicesKit'; + import { fileIo as fs } from '@kit.CoreFileKit'; + + class Options { + offset?: number; + length?: number; + } + + let bufferSize: number = 0; + let path = getContext().cacheDir; + // Ensure that the resource exists in the path. + let filePath = path + '/StarWars10s-2C-48000-4SW.wav'; + let file: fs.File = fs.openSync(filePath, fs.OpenMode.READ_ONLY); + let writeDataCallback = (buffer: ArrayBuffer) => { + // If you do not want to play a particular portion of the buffer, you can add a check and clear that specific section of the buffer. + let options: Options = { + offset: bufferSize, + length: buffer.byteLength + }; + fs.readSync(file.fd, buffer, options); + bufferSize += buffer.byteLength; + }; + + audioRenderer.on('writeData', writeDataCallback); + ``` 3. Call **start()** to switch the AudioRenderer to the **running** state and start rendering. @@ -183,8 +243,17 @@ let writeDataCallback = (buffer: ArrayBuffer) => { offset: bufferSize, length: buffer.byteLength }; - fs.readSync(file.fd, buffer, options); - bufferSize += buffer.byteLength; + + try { + fs.readSync(file.fd, buffer, options); + bufferSize += buffer.byteLength; + // This function does not return a callback result in API version 11, but does so in API version 12 and later versions. + return audio.AudioDataCallbackResult.VALID; + } catch (error) { + console.error('Error reading file:', error); + // This function does not return a callback result in API version 11, but does so in API version 12 and later versions. + return audio.AudioDataCallbackResult.INVALID; + } }; // Create an AudioRenderer instance, and set the events to listen for. diff --git a/en/application-dev/media/audio/using-ohaudio-for-playback.md b/en/application-dev/media/audio/using-ohaudio-for-playback.md index f2271d849b0f6403ebb98c8029ba96a3f4533842..d5e35fc1cfe1c22fdeaa82826dcd78cf36acc5a1 100644 --- a/en/application-dev/media/audio/using-ohaudio-for-playback.md +++ b/en/application-dev/media/audio/using-ohaudio-for-playback.md @@ -1,6 +1,6 @@ # Using OHAudio for Audio Playback (C/C++) -**OHAudio** is a set of C APIs introduced in API version 10. These APIs are normalized in design and support both common and low-latency audio channels. They support the PCM format only. They are suitable for playback applications that implement audio output at the native layer. +**OHAudio** is a set of C APIs introduced in API version 10. These APIs are normalized in design and support both common and low-latency audio channels. They support the PCM format only and are suitable for playback applications that implement audio output at the native layer. OHAudio audio playback state transition @@ -79,95 +79,215 @@ The following walks you through how to implement simple playback: Note that the audio data to play is written through callbacks. You must call **OH_AudioStreamBuilder_SetRendererCallback** to implement the callbacks. For details about the declaration of the callback functions, see [OH_AudioRenderer_Callbacks](../../reference/apis-audio-kit/_o_h_audio.md#oh_audiorenderer_callbacks). - 3. Set the callback functions. For details about concurrent processing of multiple audio streams, see [Processing Audio Interruption Events](audio-playback-concurrency.md). The procedure is similar, and the only difference is the API programming language in use. - ```c++ - // Customize a data writing function. - int32_t MyOnWriteData( - OH_AudioRenderer* renderer, - void* userData, - void* buffer, - int32_t length) - { - // Write the data to be played to the buffer by length. - return 0; - } - // Customize an audio stream event function. - int32_t MyOnStreamEvent( - OH_AudioRenderer* renderer, - void* userData, - OH_AudioStream_Event event) - { - // Update the player status and UI based on the audio stream event information indicated by the event. - return 0; - } - // Customize an audio interruption event function. - int32_t MyOnInterruptEvent( - OH_AudioRenderer* renderer, - void* userData, - OH_AudioInterrupt_ForceType type, - OH_AudioInterrupt_Hint hint) - { - // Update the player status and UI based on the audio interruption information indicated by type and hint. - return 0; - } - // Customize an exception callback function. - int32_t MyOnError( - OH_AudioRenderer* renderer, - void* userData, - OH_AudioStream_Result error) - { - // Perform operations based on the audio exception information indicated by error. - return 0; - } - - OH_AudioRenderer_Callbacks callbacks; - // Set the callbacks. - callbacks.OH_AudioRenderer_OnWriteData = MyOnWriteData; - callbacks.OH_AudioRenderer_OnStreamEvent = MyOnStreamEvent; - callbacks.OH_AudioRenderer_OnInterruptEvent = MyOnInterruptEvent; - callbacks.OH_AudioRenderer_OnError = MyOnError; - - // Set callbacks for the audio renderer. - OH_AudioStreamBuilder_SetRendererCallback(builder, callbacks, nullptr); - ``` - - To avoid unexpected behavior, ensure that each callback of [OH_AudioRenderer_Callbacks](../../reference/apis-audio-kit/_o_h_audio.md#oh_audiorenderer_callbacks) is initialized by a custom callback method or null pointer when being set. - - ```c++ - // Customize a data writing function. - int32_t MyOnWriteData( - OH_AudioRenderer* renderer, - void* userData, - void* buffer, - int32_t length) - { - // Write the data to be played to the buffer by length. - return 0; - } - // Customize an audio interruption event function. - int32_t MyOnInterruptEvent( - OH_AudioRenderer* renderer, - void* userData, - OH_AudioInterrupt_ForceType type, - OH_AudioInterrupt_Hint hint) - { - // Update the player status and UI based on the audio interruption information indicated by type and hint. - return 0; - } - OH_AudioRenderer_Callbacks callbacks; - - // Configure a callback function. If listening is required, assign a value. - callbacks.OH_AudioRenderer_OnWriteData = MyOnWriteData; - callbacks.OH_AudioRenderer_OnInterruptEvent = MyOnInterruptEvent; - - // (Mandatory) If listening is not required, use a null pointer for initialization. - callbacks.OH_AudioRenderer_OnStreamEvent = nullptr; - callbacks.OH_AudioRenderer_OnError = nullptr; - ``` + The callback function [OH_AudioRenderer_OnWriteDataCallback](../../reference/apis-audio-kit/_o_h_audio.md#oh_audiorenderer_onwritedatacallback) is introduced in API version 12 for writing audio data. + + - Since API version 12, you are advised to use [OH_AudioRenderer_OnWriteDataCallback](../../reference/apis-audio-kit/_o_h_audio.md#oh_audiorenderer_onwritedatacallback) instead of [OH_AudioRenderer_Callbacks_Struct.OH_AudioRenderer_OnWriteData](../../reference/apis-audio-kit/_o_h___audio_renderer___callbacks___struct.md#oh_audiorenderer_onwritedata) to write audio data. + + > **NOTE** + > + > - When the amount of data is sufficient to meet the required buffer length of the callback, you should return **AUDIO_DATA_CALLBACK_RESULT_VALID**, and the system uses the entire data buffer for playback. Do not return **AUDIO_DATA_CALLBACK_RESULT_VALID** in this case, as this leads to audio artifacts such as noise and playback stuttering. + > + > - When the amount of data is insufficient to meet the required buffer length of the callback, you are advised to return **AUDIO_DATA_CALLBACK_RESULT_INVALID**. In this case, the system does not process this portion of audio data but requests data from the application again. Once the buffer is adequately filled, you can return **AUDIO_DATA_CALLBACK_RESULT_VALID**. + > + > - Once the callback function finishes its execution, the audio service queues the data in the buffer for playback. Therefore, do not change the buffered data outside the callback. Regarding the last frame, if there is insufficient data to completely fill the buffer, you must concatenate the available data with padding to ensure that the buffer is full. This prevents any residual dirty data in the buffer from adversely affecting the playback effect. + + - Since API version 12, you can call [OH_AudioStreamBuilder_SetFrameSizeInCallback](../../reference/apis-audio-kit/_o_h_audio.md#oh_audiostreambuilder_setframesizeincallback) to set **audioDataSize**. + + ```c++ + // Customize a data writing function. + static OH_AudioData_Callback_Result NewAudioRendererOnWriteData( + OH_AudioRenderer* renderer, + void* userData, + void* audioData, + int32_t audioDataSize) + { + // Write the data to be played to audioData by audioDataSize. + // If you do not want to play a segment of audioData, return AUDIO_DATA_CALLBACK_RESULT_INVALID. + return AUDIO_DATA_CALLBACK_RESULT_VALID; + } + // Customize an audio stream event function. + int32_t MyOnStreamEvent( + OH_AudioRenderer* renderer, + void* userData, + OH_AudioStream_Event event) + { + // Update the player status and UI based on the audio stream event information indicated by the event. + return 0; + } + // Customize an audio interruption event function. + int32_t MyOnInterruptEvent( + OH_AudioRenderer* renderer, + void* userData, + OH_AudioInterrupt_ForceType type, + OH_AudioInterrupt_Hint hint) + { + // Update the player status and UI based on the audio interruption information indicated by type and hint. + return 0; + } + // Customize an exception callback function. + int32_t MyOnError( + OH_AudioRenderer* renderer, + void* userData, + OH_AudioStream_Result error) + { + // Perform operations based on the audio exception information indicated by error. + return 0; + } + + OH_AudioRenderer_Callbacks callbacks; + + // Set the callbacks. + callbacks.OH_AudioRenderer_OnStreamEvent = MyOnStreamEvent; + callbacks.OH_AudioRenderer_OnInterruptEvent = MyOnInterruptEvent; + callbacks.OH_AudioRenderer_OnError = MyOnError; + callbacks.OH_AudioRenderer_OnWriteData = nullptr; + + // Set callbacks for the audio renderer. + OH_AudioStreamBuilder_SetRendererCallback(builder, callbacks, nullptr); + + // Configure the callback function for writing audio data. + OH_AudioRenderer_OnWriteDataCallback writeDataCb = NewAudioRendererOnWriteData; + OH_AudioStreamBuilder_SetRendererWriteDataCallback(builder, writeDataCb, nullptr); + ``` + + - In API version 11, you can use the callback function [OH_AudioRenderer_Callbacks_Struct.OH_AudioRenderer_OnWriteData](../../reference/apis-audio-kit/_o_h___audio_renderer___callbacks___struct.md#oh_audiorenderer_onwritedata) to write audio data. + + > **NOTE** + > + > - This callback function does not return a callback result, and the system treats all data in the callback as valid by default. Ensure that the callback's data buffer is completely filled to the necessary length to prevent issues such as audio noise and playback stuttering. + > + > - If the amount of data is insufficient to fill the data buffer, you are advised to temporarily halt data writing (without pausing the audio stream), block the callback function, and wait until enough data accumulates before resuming writing, thereby ensuring that the buffer is fully filled. If you need to call AudioRenderer APIs after the callback function is blocked, unblock the callback function first. + > + > - If you do not want to play the audio data in this callback function, you can nullify the data block in the callback function. (Once nullified, the system still regards this as part of the written data, leading to silent frames during playback). + > + > - Once the callback function finishes its execution, the audio service queues the data in the buffer for playback. Therefore, do not change the buffered data outside the callback. Regarding the last frame, if there is insufficient data to completely fill the buffer, you must concatenate the available data with padding to ensure that the buffer is full. This prevents any residual dirty data in the buffer from adversely affecting the playback effect. + + ```c++ + // Customize a data writing function. + int32_t MyOnWriteData( + OH_AudioRenderer* renderer, + void* userData, + void* buffer, + int32_t length) + { + // Write the data to be played to the buffer by length. + // If you do not want to play a particular portion of the buffer, you can clear that specific section of the buffer. + return 0; + } + // Customize an audio stream event function. + int32_t MyOnStreamEvent( + OH_AudioRenderer* renderer, + void* userData, + OH_AudioStream_Event event) + { + // Update the player status and UI based on the audio stream event information indicated by the event. + return 0; + } + // Customize an audio interruption event function. + int32_t MyOnInterruptEvent( + OH_AudioRenderer* renderer, + void* userData, + OH_AudioInterrupt_ForceType type, + OH_AudioInterrupt_Hint hint) + { + // Update the player status and UI based on the audio interruption information indicated by type and hint. + return 0; + } + // Customize an exception callback function. + int32_t MyOnError( + OH_AudioRenderer* renderer, + void* userData, + OH_AudioStream_Result error) + { + // Perform operations based on the audio exception information indicated by error. + return 0; + } + + OH_AudioRenderer_Callbacks callbacks; + + // Set the callbacks. + callbacks.OH_AudioRenderer_OnWriteData = MyOnWriteData; + callbacks.OH_AudioRenderer_OnStreamEvent = MyOnStreamEvent; + callbacks.OH_AudioRenderer_OnInterruptEvent = MyOnInterruptEvent; + callbacks.OH_AudioRenderer_OnError = MyOnError; + + // Set callbacks for the audio renderer. + OH_AudioStreamBuilder_SetRendererCallback(builder, callbacks, nullptr); + ``` + + To avoid unexpected behavior, you can set the audio callback functions in either of the following ways: + + - Initialize each callback in [OH_AudioRenderer_Callbacks](../../reference/apis-audio-kit/_o_h_audio.md#oh_audiorenderer_callbacks) by a custom callback method or a null pointer. + + ```c++ + // Customize a data writing function. + int32_t MyOnWriteData( + OH_AudioRenderer* renderer, + void* userData, + void* buffer, + int32_t length) + { + // Write the data to be played to the buffer by length. + return 0; + } + // Customize an audio interruption event function. + int32_t MyOnInterruptEvent( + OH_AudioRenderer* renderer, + void* userData, + OH_AudioInterrupt_ForceType type, + OH_AudioInterrupt_Hint hint) + { + // Update the player status and UI based on the audio interruption information indicated by type and hint. + return 0; + } + + OH_AudioRenderer_Callbacks callbacks; + + // Configure a callback function. If listening is required, assign a value. + callbacks.OH_AudioRenderer_OnWriteData = MyOnWriteData; + callbacks.OH_AudioRenderer_OnInterruptEvent = MyOnInterruptEvent; + + // (Mandatory) If listening is not required, use a null pointer for initialization. + callbacks.OH_AudioRenderer_OnStreamEvent = nullptr; + callbacks.OH_AudioRenderer_OnError = nullptr; + ``` + + - Initialize and clear the struct before using it. + + ```c++ + // Customize a data writing function. + int32_t MyOnWriteData( + OH_AudioRenderer* renderer, + void* userData, + void* buffer, + int32_t length) + { + // Write the data to be played to the buffer by length. + return 0; + } + // Customize an audio interruption event function. + int32_t MyOnInterruptEvent( + OH_AudioRenderer* renderer, + void* userData, + OH_AudioInterrupt_ForceType type, + OH_AudioInterrupt_Hint hint) + { + // Update the player status and UI based on the audio interruption information indicated by type and hint. + return 0; + } + OH_AudioRenderer_Callbacks callbacks; + + // Initialize and clear the struct before using it. + memset(&callbacks, 0, sizeof(OH_AudioRenderer_Callbacks)); + + // Configure the required callback functions. + callbacks.OH_AudioRenderer_OnWriteData = MyOnWriteData; + callbacks.OH_AudioRenderer_OnInterruptEvent = MyOnInterruptEvent; + ``` 4. Create an audio renderer instance. @@ -202,6 +322,10 @@ If the device supports the low-latency channel, you can use the low-latency mode The development process is similar to that in the common playback scenario. The only difference is that you need to set the low delay mode by calling [OH_AudioStreamBuilder_SetLatencyMode()](../../reference/apis-audio-kit/_o_h_audio.md#oh_audiostreambuilder_setlatencymode) when creating an audio stream builder. +> **NOTE** +> +> In audio recording scenarios, if [OH_AudioStream_Usage](../../reference/apis-audio-kit/_o_h_audio.md#oh_audiostream_usage) is set to **AUDIOSTREAM_USAGE_VOICE_COMMUNICATION** or **AUDIOSTREAM_USAGE_VIDEO_COMMUNICATION**, the low-latency mode cannot be set. The system determines the output audio channel based on the device capability. + The code snippet is as follows: ```C diff --git a/en/application-dev/media/audio/using-ohaudio-for-recording.md b/en/application-dev/media/audio/using-ohaudio-for-recording.md index 73f114390810dfc1505616ba3b03ecec9c38ff4a..eb1ae6d94800d84bc1da39c333fc002a3866a655 100644 --- a/en/application-dev/media/audio/using-ohaudio-for-recording.md +++ b/en/application-dev/media/audio/using-ohaudio-for-recording.md @@ -75,14 +75,14 @@ The following walks you through how to implement simple recording: OH_AudioStreamBuilder_SetCapturerInfo(builder, AUDIOSTREAM_SOURCE_TYPE_MIC); ``` - Note that the audio data to record is written through callbacks. You must call **OH_AudioStreamBuilder_SetCapturerCallback** to implement the callbacks. For details about the declaration of the callback functions, see [OH_AudioCapturer_Callbacks](../../reference/apis-audio-kit/_o_h_audio.md#oh_audiocapturer_callbacks). + Note that the audio data captured is read through callbacks. You must call **OH_AudioStreamBuilder_SetCapturerCallback** to implement the callbacks. For details about the declaration of the callback functions, see [OH_AudioCapturer_Callbacks](../../reference/apis-audio-kit/_o_h_audio.md#oh_audiocapturer_callbacks). 3. Set the callback functions. For details about concurrent processing of multiple audio streams, see [Processing Audio Interruption Events](audio-playback-concurrency.md). The procedure is similar, and the only difference is the API programming language in use. ```c++ - // Customize a data writing function. + // Customize a data reading function. int32_t MyOnReadData( OH_AudioCapturer* capturer, void* userData, @@ -122,6 +122,7 @@ The following walks you through how to implement simple recording: } OH_AudioCapturer_Callbacks callbacks; + // Set the callbacks. callbacks.OH_AudioCapturer_OnReadData = MyOnReadData; callbacks.OH_AudioCapturer_OnStreamEvent = MyOnStreamEvent; @@ -132,39 +133,74 @@ The following walks you through how to implement simple recording: OH_AudioStreamBuilder_SetCapturerCallback(builder, callbacks, nullptr); ``` - To avoid unexpected behavior, ensure that each callback of [OH_AudioCapturer_Callbacks](../../reference/apis-audio-kit/_o_h_audio.md#oh_audiocapturer_callbacks) is initialized by a custom callback method or null pointer when being set. - - ```c++ - // Customize a data writing function. - int32_t MyOnReadData( - OH_AudioCapturer* capturer, - void* userData, - void* buffer, - int32_t length) - { - // Obtain the recording data of the specified length from the buffer. - return 0; - } - // Customize an audio interruption event function. - int32_t MyOnInterruptEvent( - OH_AudioCapturer* capturer, - void* userData, - OH_AudioInterrupt_ForceType type, - OH_AudioInterrupt_Hint hint) - { - // Update the capturer status and UI based on the audio interruption information indicated by type and hint. - return 0; - } - OH_AudioCapturer_Callbacks callbacks; - - // Configure a callback function. If listening is required, assign a value. - callbacks.OH_AudioCapturer_OnReadData = MyOnReadData; - callbacks.OH_AudioCapturer_OnInterruptEvent = MyOnInterruptEvent; - - // (Mandatory) If listening is not required, use a null pointer for initialization. - callbacks.OH_AudioCapturer_OnStreamEvent = nullptr; - callbacks.OH_AudioCapturer_OnError = nullptr; - ``` + To avoid unexpected behavior, you can set the audio callback functions in either of the following ways: + + - Initialize each callback in [OH_AudioCapturer_Callbacks](../../reference/apis-audio-kit/_o_h_audio.md#oh_audiocapturer_callbacks) by a custom callback method or a null pointer. + + ```c++ + // Customize a data reading function. + int32_t MyOnReadData( + OH_AudioCapturer* capturer, + void* userData, + void* buffer, + int32_t length) + { + // Obtain the recording data of the specified length from the buffer. + return 0; + } + // Customize an audio interruption event function. + int32_t MyOnInterruptEvent( + OH_AudioCapturer* capturer, + void* userData, + OH_AudioInterrupt_ForceType type, + OH_AudioInterrupt_Hint hint) + { + // Update the capturer status and UI based on the audio interruption information indicated by type and hint. + return 0; + } + OH_AudioCapturer_Callbacks callbacks; + + // Configure a callback function. If listening is required, assign a value. + callbacks.OH_AudioCapturer_OnReadData = MyOnReadData; + callbacks.OH_AudioCapturer_OnInterruptEvent = MyOnInterruptEvent; + + // (Mandatory) If listening is not required, use a null pointer for initialization. + callbacks.OH_AudioCapturer_OnStreamEvent = nullptr; + callbacks.OH_AudioCapturer_OnError = nullptr; + ``` + + - Initialize and clear the struct before using it. + + ```c++ + // Customize a data reading function. + int32_t MyOnReadData( + OH_AudioCapturer* capturer, + void* userData, + void* buffer, + int32_t length) + { + // Obtain the recording data of the specified length from the buffer. + return 0; + } + // Customize an audio interruption event function. + int32_t MyOnInterruptEvent( + OH_AudioCapturer* capturer, + void* userData, + OH_AudioInterrupt_ForceType type, + OH_AudioInterrupt_Hint hint) + { + // Update the capturer status and UI based on the audio interruption information indicated by type and hint. + return 0; + } + OH_AudioCapturer_Callbacks callbacks; + + // Initialize and clear the struct before using it. + memset(&callbacks, 0, sizeof(OH_AudioCapturer_Callbacks)); + + // Configure the required callback functions. + callbacks.OH_AudioCapturer_OnReadData = MyOnReadData; + callbacks.OH_AudioCapturer_OnInterruptEvent = MyOnInterruptEvent; + ``` 4. Create an audio capturer instance. @@ -199,6 +235,10 @@ If the device supports the low-latency channel, you can use the low-latency mode The development process is similar to that in the common recording scenario. The only difference is that you need to set the low delay mode by calling [OH_AudioStreamBuilder_SetLatencyMode()](../../reference/apis-audio-kit/_o_h_audio.md#oh_audiostreambuilder_setlatencymode) when creating an audio stream builder. +> **NOTE** +> +> In audio recording scenarios, if [OH_AudioStream_SourceType](../../reference/apis-audio-kit/_o_h_audio.md#oh_audiostream_sourcetype) is set to **AUDIOSTREAM_SOURCE_TYPE_VOICE_COMMUNICATION**, the low-latency mode cannot be set. The system determines the output audio channel based on the device capability. + Code snippet: ```C diff --git a/en/application-dev/media/audio/using-right-streamusage-and-sourcetype.md b/en/application-dev/media/audio/using-right-streamusage-and-sourcetype.md index fe6b8470e488415ef2316070f04496fabbf635bd..1d8adcc25a67af8eb6110a6d9b7c822ea22db3c7 100644 --- a/en/application-dev/media/audio/using-right-streamusage-and-sourcetype.md +++ b/en/application-dev/media/audio/using-right-streamusage-and-sourcetype.md @@ -17,7 +17,7 @@ The following table describes the typical stream types used for audio playback. | STREAM_USAGE_MUSIC | Music playback and other media scenarios, for example, using [SoundPool](../media/using-soundpool-for-playback.md) to play short sounds.| | STREAM_USAGE_MOVIE | Playing various video content such as short videos, movies, and TV series.| | STREAM_USAGE_AUDIOBOOK | Playing audiobooks, news, and podcasts.| -| STREAM_USAGE_GAME | In-game background scores and character dubbing, ensuring uninterrupted background music. It is recommended that you use **VOICE_COMMUNICATION** for in-game voice.| +| STREAM_USAGE_GAME | In-game background scores and character dubbing, ensuring uninterrupted background music. It is recommended that you use **STREAM_USAGE_VOICE_COMMUNICATION** for in-game voice.| | STREAM_USAGE_NAVIGATION | Voice broadcast in navigation scenarios.| | STREAM_USAGE_VOICE_MESSAGE | Playing voice short messages.| | STREAM_USAGE_VOICE_COMMUNICATION | VoIP voice calls.| @@ -108,9 +108,9 @@ Common methods for setting the audio playback stream type are as follows: > > The **audioRendererInfo** property of the AVPlayer can be set only in the initialized state. > -> If the application does not set this property, the AVPlayer performs default processing. If the media source contains videos, the default value of **usage** is **STREAM_USAGE_MOVIE**. Otherwise, the default value of **usage** is **STREAM_USAGE_MUSIC**. + > If the application does not set this property, the AVPlayer performs default processing. If the media source contains videos, the default value of **usage** is **STREAM_USAGE_MOVIE**. Otherwise, the default value of **usage** is **STREAM_USAGE_MUSIC**. -- **[Using AVPlayer for Audio Playback (C/C++)](../media/using-ndk-avplayer-for-playerback.md)** +- **[Using AVPlayer for Audio Playback (C/C++)](../media/using-ndk-avplayer-for-playback.md)** Pass [OH_AudioStream_Usage](../../reference/apis-audio-kit/_o_h_audio.md#oh_audiostream_usage) in [OH_AVPlayer_SetAudioRendererInfo](../../reference/apis-media-kit/_a_v_player.md#oh_avplayer_setaudiorendererinfo) to specify the stream type. diff --git a/en/application-dev/reference/apis-audio-kit/_o_h___audio_capturer___callbacks___struct.md b/en/application-dev/reference/apis-audio-kit/_o_h___audio_capturer___callbacks___struct.md index 22a1304b3159cbf80ac9cc67d14821963d3bbe84..8679a5500dfea52ce4918829ed5d18c1d7eea173 100644 --- a/en/application-dev/reference/apis-audio-kit/_o_h___audio_capturer___callbacks___struct.md +++ b/en/application-dev/reference/apis-audio-kit/_o_h___audio_capturer___callbacks___struct.md @@ -82,13 +82,15 @@ int32_t (*OH_AudioCapturer_Callbacks_Struct::OH_AudioCapturer_OnReadData)(OH_Aud Defines a function pointer to the callback function used to read audio data. +The callback function is used only to read audio data. Do not call AudioCapturer APIs in it. + **Parameters** | Name| Description| | -------- | -------- | | capturer | Pointer to an audio capturer instance, which is created by calling [OH_AudioStreamBuilder_GenerateCapturer](_o_h_audio.md#oh_audiostreambuilder_generatecapturer).| | userData | Pointer to the data storage area customized by the application.| -| buffer | Pointer to the playback data storage area, which is used by the application to fill in playback data.| +| buffer | Pointer to the captured data storage area, which is used by the application to fill in captured data.| | length | Length of the buffer.| diff --git a/en/application-dev/reference/apis-audio-kit/_o_h___audio_renderer___callbacks___struct.md b/en/application-dev/reference/apis-audio-kit/_o_h___audio_renderer___callbacks___struct.md index 6eea9dcca08295f312a073161f89f5aa1edc4178..44c6a2dad51e3e28f02bd59fc0b838ea57b0b910 100644 --- a/en/application-dev/reference/apis-audio-kit/_o_h___audio_renderer___callbacks___struct.md +++ b/en/application-dev/reference/apis-audio-kit/_o_h___audio_renderer___callbacks___struct.md @@ -102,6 +102,8 @@ int32_t (*OH_AudioRenderer_Callbacks_Struct::OH_AudioRenderer_OnWriteData)(OH_Au Defines a function pointer to the callback function used to write audio data. +The callback function is used only to write audio data. Do not call AudioRenderer APIs in it. + Once 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. **Parameters** diff --git a/en/application-dev/reference/apis-audio-kit/_o_h_audio.md b/en/application-dev/reference/apis-audio-kit/_o_h_audio.md index 1603c14e9c6160c5afa78856a5c3f595c8ec88d9..db361906b00fce69d3e3e312535ebafd83f7c908 100644 --- a/en/application-dev/reference/apis-audio-kit/_o_h_audio.md +++ b/en/application-dev/reference/apis-audio-kit/_o_h_audio.md @@ -5,6 +5,12 @@ The **OHAudio** module provides C APIs of the audio module. +You can refer to the corresponding development guide and samples based on your development requirements. + +- [Using OHAudio for Audio Playback](../../media/audio/using-ohaudio-for-playback.md) +- [Using OHAudio for Audio Recording](../../media/audio/using-ohaudio-for-recording.md) +- [Using AudioSession to Manage Audio Focus](../../media/audio/using-ohaudio-for-session.md) + **System capability**: SystemCapability.Multimedia.Audio.Core **Since**: 10 @@ -47,21 +53,21 @@ The **OHAudio** module provides C APIs of the audio module. | typedef struct [OH_AudioDeviceDescriptorArray](_o_h___audio_device_descriptor_array.md) [OH_AudioDeviceDescriptorArray](#oh_audiodevicedescriptorarray) | Defines a struct for an array of audio device descriptors. | | typedef struct [OH_AudioManager](#oh_audiomanager) [OH_AudioManager](#oh_audiomanager) | Defines a struct for an audio manager. | | typedef struct [OH_AudioRoutingManager](#oh_audioroutingmanager) [OH_AudioRoutingManager](#oh_audioroutingmanager) | Defines a struct for an audio routing manager, which is used for routing and device-related functions. | -| typedef int32_t(\* [OH_AudioRoutingManager_OnDeviceChangedCallback](#oh_audioroutingmanager_ondevicechangedcallback))([OH_AudioDevice_ChangeType](#oh_audiodevice_changetype) type, [OH_AudioDeviceDescriptorArray](_o_h___audio_device_descriptor_array.md) \*audioDeviceDescriptorArray) | Defines a pointer to the callback function that returns the changed audio device descriptor (possibly multiple descriptors). | -| typedef void(\* [OH_AudioRoutingManager_OnDeviceBlockStatusCallback](#oh_audioroutingmanager_ondeviceblockstatuscallback)) ([OH_AudioDeviceDescriptorArray](_o_h___audio_device_descriptor_array.md) \*audioDeviceDescriptorArray, [OH_AudioDevice_BlockStatus](#oh_audiodevice_blockstatus) status, void \*userData) | Defines a pointer to the callback function that returns the blocked status of one or more audio devices. | +| typedef int32_t (\*[OH_AudioRoutingManager_OnDeviceChangedCallback](#oh_audioroutingmanager_ondevicechangedcallback))([OH_AudioDevice_ChangeType](#oh_audiodevice_changetype) type, [OH_AudioDeviceDescriptorArray](_o_h___audio_device_descriptor_array.md) \*audioDeviceDescriptorArray) | Defines a pointer to the callback function that returns the changed audio device descriptor (possibly multiple descriptors). | +| typedef void (\*[OH_AudioRoutingManager_OnDeviceBlockStatusCallback](#oh_audioroutingmanager_ondeviceblockstatuscallback)) ([OH_AudioDeviceDescriptorArray](_o_h___audio_device_descriptor_array.md) \*audioDeviceDescriptorArray, [OH_AudioDevice_BlockStatus](#oh_audiodevice_blockstatus) status, void \*userData) | Defines a pointer to the callback function that returns the blocked status of one or more audio devices. | | typedef struct [OH_AudioSessionManager](#oh_audiosessionmanager) [OH_AudioSessionManager](#oh_audiosessionmanager) | Defines a struct for an audio session manager. | | typedef struct [OH_AudioSession_Strategy](_o_h___audio_session___strategy.md) [OH_AudioSession_Strategy](#oh_audiosession_strategy) | Defines a struct for an audio session strategy. | | typedef struct [OH_AudioSession_DeactivatedEvent](_o_h___audio_session___deactivated_event.md) [OH_AudioSession_DeactivatedEvent](#oh_audiosession_deactivatedevent) | Defines a struct for the event indicating that an audio session is deactivated. | -| typedef int32_t(\* [OH_AudioSession_DeactivatedCallback](#oh_audiosession_deactivatedcallback))([OH_AudioSession_DeactivatedEvent](_o_h___audio_session___deactivated_event.md) event) | Defines a function pointer to the callback function used to listen for audio session deactivation events. | +| typedef int32_t (\*[OH_AudioSession_DeactivatedCallback](#oh_audiosession_deactivatedcallback))([OH_AudioSession_DeactivatedEvent](_o_h___audio_session___deactivated_event.md) event) | Defines a function pointer to the callback function used to listen for audio session deactivation events. | | typedef struct OH_AudioStreamBuilderStruct [OH_AudioStreamBuilder](#oh_audiostreambuilder) | Defines a struct for an audio stream builder. | | typedef struct OH_AudioRendererStruct [OH_AudioRenderer](#oh_audiorenderer) | Defines a struct for an audio renderer. | | typedef struct OH_AudioCapturerStruct [OH_AudioCapturer](#oh_audiocapturer) | Defines a struct for an audio capturer. | | typedef struct [OH_AudioRenderer_Callbacks_Struct](_o_h___audio_renderer___callbacks___struct.md) [OH_AudioRenderer_Callbacks](#oh_audiorenderer_callbacks) | Defines a pointer to the callback functions related to an audio renderer. | | typedef struct [OH_AudioCapturer_Callbacks_Struct](_o_h___audio_capturer___callbacks___struct.md) [OH_AudioCapturer_Callbacks](#oh_audiocapturer_callbacks) | Defines a pointer to the callback functions related to an audio capturer. | -| typedef void(\* [OH_AudioRenderer_OutputDeviceChangeCallback](#oh_audiorenderer_outputdevicechangecallback))([OH_AudioRenderer](#oh_audiorenderer) \*renderer, void \*userData, [OH_AudioStream_DeviceChangeReason](#oh_audiostream_devicechangereason) reason) | Defines a pointer to the callback invoked when the audio stream device changes. | -| typedef void(\* [OH_AudioRenderer_OnMarkReachedCallback](#oh_audiorenderer_onmarkreachedcallback))([OH_AudioRenderer](#oh_audiorenderer) \*renderer, uint32_t samplePos, void \*userData) | Defines a pointer to the callback invoked when the mark position is reached. | -| typedef int32_t(\* [OH_AudioRenderer_WriteDataWithMetadataCallback](#oh_audiorenderer_writedatawithmetadatacallback))([OH_AudioRenderer](#oh_audiorenderer) \*renderer, void \*userData, void \*audioData, int32_t audioDataSize, void \*metadata, int32_t metadataSize) | Defines a function pointer to the callback function used to write audio data and metadata. | -| typedef [OH_AudioData_Callback_Result](#oh_audiodata_callback_result)(\* [OH_AudioRenderer_OnWriteDataCallback](#oh_audiorenderer_onwritedatacallback))([OH_AudioRenderer](#oh_audiorenderer) \*renderer, void \*userData, void \*audioData, int32_t audioDataSize) | Defines a function pointer to the callback function used to write audio data. | +| typedef void (\*[OH_AudioRenderer_OutputDeviceChangeCallback](#oh_audiorenderer_outputdevicechangecallback))([OH_AudioRenderer](#oh_audiorenderer) \*renderer, void \*userData, [OH_AudioStream_DeviceChangeReason](#oh_audiostream_devicechangereason) reason) | Defines a pointer to the callback invoked when the audio stream device changes. | +| typedef void (\*[OH_AudioRenderer_OnMarkReachedCallback](#oh_audiorenderer_onmarkreachedcallback))([OH_AudioRenderer](#oh_audiorenderer) \*renderer, uint32_t samplePos, void \*userData) | Defines a pointer to the callback invoked when the mark position is reached. | +| typedef int32_t (\*[OH_AudioRenderer_WriteDataWithMetadataCallback](#oh_audiorenderer_writedatawithmetadatacallback))([OH_AudioRenderer](#oh_audiorenderer) \*renderer, void \*userData, void \*audioData, int32_t audioDataSize, void \*metadata, int32_t metadataSize) | Defines a function pointer to the callback function used to write audio data and metadata. | +| typedef [OH_AudioData_Callback_Result](#oh_audiodata_callback_result) (\*[OH_AudioRenderer_OnWriteDataCallback](#oh_audiorenderer_onwritedatacallback))([OH_AudioRenderer](#oh_audiorenderer) \*renderer, void \*userData, void \*audioData, int32_t audioDataSize) | Defines a function pointer to the callback function used to write audio data. | ### Enums @@ -119,8 +125,8 @@ The **OHAudio** module provides C APIs of the audio module. | [OH_AudioCommon_Result](#oh_audiocommon_result) [OH_AudioRoutingManager_RegisterDeviceChangeCallback](#oh_audioroutingmanager_registerdevicechangecallback)([OH_AudioRoutingManager](#oh_audioroutingmanager) \*audioRoutingManager, [OH_AudioDevice_Flag](#oh_audiodevice_flag) deviceFlag, [OH_AudioRoutingManager_OnDeviceChangedCallback](#oh_audioroutingmanager_ondevicechangedcallback) callback) | Registers a callback to listen for device changes of an audio routing manager. | | [OH_AudioCommon_Result](#oh_audiocommon_result) [OH_AudioRoutingManager_UnregisterDeviceChangeCallback](#oh_audioroutingmanager_unregisterdevicechangecallback)([OH_AudioRoutingManager](#oh_audioroutingmanager) \*audioRoutingManager, [OH_AudioRoutingManager_OnDeviceChangedCallback](#oh_audioroutingmanager_ondevicechangedcallback) callback) | Unregisters the callback used to listen for device changes of an audio routing manager. | | [OH_AudioCommon_Result](#oh_audiocommon_result) [OH_AudioRoutingManager_ReleaseDevices](#oh_audioroutingmanager_releasedevices)([OH_AudioRoutingManager](#oh_audioroutingmanager) \*audioRoutingManager, [OH_AudioDeviceDescriptorArray](_o_h___audio_device_descriptor_array.md) \*audioDeviceDescriptorArray) | Releases audio devices available for an audio routing manager. | -| [OH_AudioCommon_Result](#oh_audiocommon_result) [OH_AudioRoutingManager_IsMicBlockDetectionSupported](#oh_audioroutingmanager_ismicblockdetectionsupported) ([OH_AudioRoutingManager](#oh_audioroutingmanager) \*audioRoutingManager, bool \*supported) | Checks whether the current device supports microphone blocking detection. | -| [OH_AudioCommon_Result](#oh_audiocommon_result) [OH_AudioRoutingManager_SetMicBlockStatusCallback](#oh_audioroutingmanager_setmicblockstatuscallback) ([OH_AudioRoutingManager](#oh_audioroutingmanager) \*audioRoutingManager, [OH_AudioRoutingManager_OnDeviceBlockStatusCallback](#oh_audioroutingmanager_ondeviceblockstatuscallback) callback, void \*userData) | Sets a callback function to be invoked when the microphone's blocked status is changed. Before using this function, check whether the current device supports microphone blocking detection. The application receives a callback only when the microphone is used for recording and the microphone's blocked status changes. Currently, this function takes effect only for the microphone on the local device. | +| [OH_AudioCommon_Result](#oh_audiocommon_result) [OH_AudioRoutingManager_IsMicBlockDetectionSupported](#oh_audioroutingmanager_ismicblockdetectionsupported)([OH_AudioRoutingManager](#oh_audioroutingmanager) \*audioRoutingManager, bool \*supported) | Checks whether the current device supports microphone blocking detection. | +| [OH_AudioCommon_Result](#oh_audiocommon_result) [OH_AudioRoutingManager_SetMicBlockStatusCallback](#oh_audioroutingmanager_setmicblockstatuscallback)([OH_AudioRoutingManager](#oh_audioroutingmanager) \*audioRoutingManager, [OH_AudioRoutingManager_OnDeviceBlockStatusCallback](#oh_audioroutingmanager_ondeviceblockstatuscallback) callback, void \*userData) | Sets a callback function to be invoked when the microphone's blocked status is changed. Before using this function, check whether the current device supports microphone blocking detection. The application receives a callback only when the microphone is used for recording and the microphone's blocked status changes. Currently, this function takes effect only for the microphone on the local device. | | [OH_AudioCommon_Result](#oh_audiocommon_result) [OH_AudioManager_GetAudioSessionManager](#oh_audiomanager_getaudiosessionmanager)([OH_AudioSessionManager](#oh_audiosessionmanager) \*\*audioSessionManager) | Obtains an **OH_AudioSessionManager** instance. | | [OH_AudioCommon_Result](#oh_audiocommon_result) [OH_AudioSessionManager_ActivateAudioSession](#oh_audiosessionmanager_activateaudiosession)([OH_AudioSessionManager](#oh_audiosessionmanager) \*audioSessionManager, const [OH_AudioSession_Strategy](_o_h___audio_session___strategy.md) \*strategy) | Activates an audio session. | | [OH_AudioCommon_Result](#oh_audiocommon_result) [OH_AudioSessionManager_DeactivateAudioSession](#oh_audiosessionmanager_deactivateaudiosession)([OH_AudioSessionManager](#oh_audiosessionmanager) \*audioSessionManager) | Deactivates an audio session. | @@ -310,7 +316,7 @@ Defines a pointer to the callback functions related to an audio renderer. ### OH_AudioRenderer_OnMarkReachedCallback ``` -typedef void(* OH_AudioRenderer_OnMarkReachedCallback)(OH_AudioRenderer *renderer, uint32_t samplePos, void *userData) +typedef void (*OH_AudioRenderer_OnMarkReachedCallback)(OH_AudioRenderer *renderer, uint32_t samplePos, void *userData) ``` **Description** @@ -337,6 +343,7 @@ typedef OH_AudioData_Callback_Result(* OH_AudioRenderer_OnWriteDataCallback)(OH_ **Description** Defines a function pointer to the callback function used to write audio data. +The callback function is used only to write audio data. Do not call AudioRenderer APIs in it. This function is similar to the function pointer [OH_AudioRenderer_Callbacks_Struct.OH_AudioRenderer_OnWriteData](_o_h___audio_renderer___callbacks___struct.md#oh_audiorenderer_onwritedata). However, this function has a return value to identify the audio data callback result. The return result indicates whether the data filled in the buffer is valid. If the data is invalid, the data entered by the user will not be played. Once the callback function finishes its execution, the audio service queues the data pointed to by **audioData** for playback. Therefore, do not change the data outside the callback. It is crucial to fill **audioData** with the exact length (specified by **audioDataSize**) of data designated for playback; otherwise, noises may occur during playback. The **audioDataSize** parameter can be set by using [OH_AudioStreamBuilder_SetFrameSizeInCallBack()](#OH_AudioStreamBuilder_SetFrameSizeInCallback). @@ -355,7 +362,11 @@ This function is similar to the function pointer [OH_AudioRenderer_Callbacks_Str **Returns** -Audio data callback result. +Returns one of the result codes defined in [OH_AudioData_Callback_Result](#oh_audiodata_callback_result): + +**AUDIO_DATA_CALLBACK_RESULT_INVALID**: The audio data callback result is invalid, and the audio data will not be played. + +**AUDIO_DATA_CALLBACK_RESULT_VALID**: The audio data callback result is valid, and the audio data will be played. **See** @@ -365,7 +376,7 @@ Audio data callback result. ### OH_AudioRenderer_OutputDeviceChangeCallback ``` -typedef void(* OH_AudioRenderer_OutputDeviceChangeCallback) (OH_AudioRenderer *renderer, void *userData, OH_AudioStream_DeviceChangeReason reason) +typedef void (*OH_AudioRenderer_OutputDeviceChangeCallback)(OH_AudioRenderer *renderer, void *userData, OH_AudioStream_DeviceChangeReason reason) ``` **Description** @@ -388,7 +399,7 @@ Defines a pointer to the callback invoked when the audio stream device changes. ### OH_AudioRenderer_WriteDataWithMetadataCallback ``` -typedef int32_t(* OH_AudioRenderer_WriteDataWithMetadataCallback)(OH_AudioRenderer *renderer, void *userData, void *audioData, int32_t audioDataSize, void *metadata, int32_t metadataSize) +typedef int32_t (*OH_AudioRenderer_WriteDataWithMetadataCallback)(OH_AudioRenderer *renderer, void *userData, void *audioData, int32_t audioDataSize, void *metadata, int32_t metadataSize) ``` **Description** @@ -452,7 +463,7 @@ Defines a pointer to the callback function that returns the blocked status of on ### OH_AudioRoutingManager_OnDeviceChangedCallback ``` -typedef int32_t(* OH_AudioRoutingManager_OnDeviceChangedCallback) (OH_AudioDevice_ChangeType type, OH_AudioDeviceDescriptorArray *audioDeviceDescriptorArray) +typedef int32_t (*OH_AudioRoutingManager_OnDeviceChangedCallback)(OH_AudioDevice_ChangeType type, OH_AudioDeviceDescriptorArray *audioDeviceDescriptorArray) ``` **Description** @@ -472,7 +483,7 @@ Defines a pointer to the callback function that returns the changed audio device ### OH_AudioSession_DeactivatedCallback ``` -typedef int32_t(* OH_AudioSession_DeactivatedCallback)(OH_AudioSession_DeactivatedEvent event) +typedef int32_t (*OH_AudioSession_DeactivatedCallback)(OH_AudioSession_DeactivatedEvent event) ``` **Description** @@ -589,8 +600,8 @@ Enumerates the audio data callback results. | Value| Description| | -------- | -------- | -| AUDIO_DATA_CALLBACK_RESULT_INVALID | The data is invalid. | -| AUDIO_DATA_CALLBACK_RESULT_VALID | The data is valid. | +| AUDIO_DATA_CALLBACK_RESULT_INVALID | The audio data callback result is invalid, and the audio data will not be played. | +| AUDIO_DATA_CALLBACK_RESULT_VALID | The audio data callback result is valid, and the audio data will be played. | ### OH_AudioDevice_BlockStatus @@ -960,7 +971,7 @@ enum OH_AudioStream_PrivacyType Enumerates the privacy types of an audio stream. The privacy type specifies whether the audio stream can be recorded by other applications. -**System capability**: SystemCapability.Multimedia.Audio.PlaybackCapture +**System capability**: SystemCapability.Multimedia.Audio.Core **Since**: 12 @@ -1303,7 +1314,7 @@ Returns a result code defined in [OH_AudioStream_Result](#oh_audiostream_result) ### OH_AudioCapturer_GetFramesRead() ``` -OH_AudioStream_Result OH_AudioCapturer_GetFramesRead (OH_AudioCapturer *capturer, int64_t *frames) +OH_AudioStream_Result OH_AudioCapturer_GetFramesRead(OH_AudioCapturer *capturer, int64_t *frames) ``` **Description** @@ -1363,7 +1374,7 @@ Returns a result code defined in [OH_AudioStream_Result](#oh_audiostream_result) ### OH_AudioCapturer_GetOverflowCount() ``` -OH_AudioStream_Result OH_AudioCapturer_GetOverflowCount (OH_AudioCapturer *capturer, uint32_t *count) +OH_AudioStream_Result OH_AudioCapturer_GetOverflowCount(OH_AudioCapturer *capturer, uint32_t *count) ``` **Description** @@ -1660,7 +1671,7 @@ Returns a result code defined in [OH_AudioStream_Result](#oh_audiostream_result) ### OH_AudioDeviceDescriptor_GetDeviceAddress() ``` -OH_AudioCommon_Result OH_AudioDeviceDescriptor_GetDeviceAddress (OH_AudioDeviceDescriptor *audioDeviceDescriptor, char **address) +OH_AudioCommon_Result OH_AudioDeviceDescriptor_GetDeviceAddress(OH_AudioDeviceDescriptor *audioDeviceDescriptor, char **address) ``` **Description** @@ -1684,7 +1695,7 @@ Returns **AUDIOCOMMON_RESULT_SUCCESS** if the operation is successful; returns * ### OH_AudioDeviceDescriptor_GetDeviceChannelCounts() ``` -OH_AudioCommon_Result OH_AudioDeviceDescriptor_GetDeviceChannelCounts (OH_AudioDeviceDescriptor *audioDeviceDescriptor, uint32_t **channelCounts, uint32_t *size) +OH_AudioCommon_Result OH_AudioDeviceDescriptor_GetDeviceChannelCounts(OH_AudioDeviceDescriptor *audioDeviceDescriptor, uint32_t **channelCounts, uint32_t *size) ``` **Description** @@ -1709,7 +1720,7 @@ Returns **AUDIOCOMMON_RESULT_SUCCESS** if the operation is successful; returns * ### OH_AudioDeviceDescriptor_GetDeviceDisplayName() ``` -OH_AudioCommon_Result OH_AudioDeviceDescriptor_GetDeviceDisplayName (OH_AudioDeviceDescriptor *audioDeviceDescriptor, char **displayName) +OH_AudioCommon_Result OH_AudioDeviceDescriptor_GetDeviceDisplayName(OH_AudioDeviceDescriptor *audioDeviceDescriptor, char **displayName) ``` **Description** @@ -1733,7 +1744,7 @@ Returns **AUDIOCOMMON_RESULT_SUCCESS** if the operation is successful; returns * ### OH_AudioDeviceDescriptor_GetDeviceEncodingTypes() ``` -OH_AudioCommon_Result OH_AudioDeviceDescriptor_GetDeviceEncodingTypes (OH_AudioDeviceDescriptor *audioDeviceDescriptor, OH_AudioStream_EncodingType **encodingTypes, uint32_t *size) +OH_AudioCommon_Result OH_AudioDeviceDescriptor_GetDeviceEncodingTypes(OH_AudioDeviceDescriptor *audioDeviceDescriptor, OH_AudioStream_EncodingType **encodingTypes, uint32_t *size) ``` **Description** @@ -1758,7 +1769,7 @@ Returns **AUDIOCOMMON_RESULT_SUCCESS** if the operation is successful; returns * ### OH_AudioDeviceDescriptor_GetDeviceId() ``` -OH_AudioCommon_Result OH_AudioDeviceDescriptor_GetDeviceId (OH_AudioDeviceDescriptor *audioDeviceDescriptor, uint32_t *id) +OH_AudioCommon_Result OH_AudioDeviceDescriptor_GetDeviceId(OH_AudioDeviceDescriptor *audioDeviceDescriptor, uint32_t *id) ``` **Description** @@ -1782,7 +1793,7 @@ Returns **AUDIODEVICE_SUCCESS** if the operation is successful; returns **AUDIOC ### OH_AudioDeviceDescriptor_GetDeviceName() ``` -OH_AudioCommon_Result OH_AudioDeviceDescriptor_GetDeviceName (OH_AudioDeviceDescriptor *audioDeviceDescriptor, char **name ) +OH_AudioCommon_Result OH_AudioDeviceDescriptor_GetDeviceName(OH_AudioDeviceDescriptor *audioDeviceDescriptor, char **name) ``` **Description** @@ -1806,7 +1817,7 @@ Returns **AUDIOCOMMON_RESULT_SUCCESS** if the operation is successful; returns * ### OH_AudioDeviceDescriptor_GetDeviceRole() ``` -OH_AudioCommon_Result OH_AudioDeviceDescriptor_GetDeviceRole (OH_AudioDeviceDescriptor *audioDeviceDescriptor, OH_AudioDevice_Role *deviceRole) +OH_AudioCommon_Result OH_AudioDeviceDescriptor_GetDeviceRole(OH_AudioDeviceDescriptor *audioDeviceDescriptor, OH_AudioDevice_Role *deviceRole) ``` **Description** @@ -1830,7 +1841,7 @@ Returns **AUDIOCOMMON_RESULT_SUCCESS** if the operation is successful; returns * ### OH_AudioDeviceDescriptor_GetDeviceSampleRates() ``` -OH_AudioCommon_Result OH_AudioDeviceDescriptor_GetDeviceSampleRates (OH_AudioDeviceDescriptor *audioDeviceDescriptor, uint32_t **sampleRates, uint32_t *size) +OH_AudioCommon_Result OH_AudioDeviceDescriptor_GetDeviceSampleRates(OH_AudioDeviceDescriptor *audioDeviceDescriptor, uint32_t **sampleRates, uint32_t *size) ``` **Description** @@ -1855,7 +1866,7 @@ Returns **AUDIOCOMMON_RESULT_SUCCESS** if the operation is successful; returns * ### OH_AudioDeviceDescriptor_GetDeviceType() ``` -OH_AudioCommon_Result OH_AudioDeviceDescriptor_GetDeviceType (OH_AudioDeviceDescriptor *audioDeviceDescriptor, OH_AudioDevice_Type *deviceType) +OH_AudioCommon_Result OH_AudioDeviceDescriptor_GetDeviceType(OH_AudioDeviceDescriptor *audioDeviceDescriptor, OH_AudioDevice_Type *deviceType) ``` **Description** @@ -1879,7 +1890,7 @@ Returns **AUDIOCOMMON_RESULT_SUCCESS** if the operation is successful; returns * ### OH_AudioManager_GetAudioRoutingManager() ``` -OH_AudioCommon_Result OH_AudioManager_GetAudioRoutingManager (OH_AudioRoutingManager **audioRoutingManager) +OH_AudioCommon_Result OH_AudioManager_GetAudioRoutingManager(OH_AudioRoutingManager **audioRoutingManager) ``` **Description** @@ -1904,7 +1915,7 @@ Returns a result code defined in [OH_AudioCommon_Result](#oh_audiocommon_result) ### OH_AudioManager_GetAudioSessionManager() ``` -OH_AudioCommon_Result OH_AudioManager_GetAudioSessionManager (OH_AudioSessionManager **audioSessionManager) +OH_AudioCommon_Result OH_AudioManager_GetAudioSessionManager(OH_AudioSessionManager **audioSessionManager) ``` **Description** @@ -1931,7 +1942,7 @@ Returns a result code defined in [OH_AudioCommon_Result](#oh_audiocommon_result) ### OH_AudioRenderer_CancelMark() ``` -OH_AudioStream_Result OH_AudioRenderer_CancelMark (OH_AudioRenderer *renderer) +OH_AudioStream_Result OH_AudioRenderer_CancelMark(OH_AudioRenderer *renderer) ``` **Description** @@ -2021,7 +2032,7 @@ Returns a result code defined in [OH_AudioStream_Result](#oh_audiostream_result) ### OH_AudioRenderer_GetChannelLayout() ``` -OH_AudioStream_Result OH_AudioRenderer_GetChannelLayout (OH_AudioRenderer *renderer, OH_AudioChannelLayout *channelLayout) +OH_AudioStream_Result OH_AudioRenderer_GetChannelLayout(OH_AudioRenderer *renderer, OH_AudioChannelLayout *channelLayout) ``` **Description** @@ -2081,7 +2092,7 @@ Returns a result code defined in [OH_AudioStream_Result](#oh_audiostream_result) ### OH_AudioRenderer_GetEffectMode() ``` -OH_AudioStream_Result OH_AudioRenderer_GetEffectMode (OH_AudioRenderer *renderer, OH_AudioStream_AudioEffectMode *effectMode) +OH_AudioStream_Result OH_AudioRenderer_GetEffectMode(OH_AudioRenderer *renderer, OH_AudioStream_AudioEffectMode *effectMode) ``` **Description** @@ -2261,7 +2272,7 @@ Returns a result code defined in [OH_AudioStream_Result](#oh_audiostream_result) ### OH_AudioRenderer_GetRendererPrivacy() ``` -OH_AudioStream_Result OH_AudioRenderer_GetRendererPrivacy (OH_AudioRenderer *renderer, OH_AudioStream_PrivacyType *privacy) +OH_AudioStream_Result OH_AudioRenderer_GetRendererPrivacy(OH_AudioRenderer *renderer, OH_AudioStream_PrivacyType *privacy) ``` **Description** @@ -2270,7 +2281,7 @@ Checks whether the audio stream being played can be recorded by other applicatio **Since**: 12 -**System capability**: SystemCapability.Multimedia.Audio.PlaybackCapture +**System capability**: SystemCapability.Multimedia.Audio.Core **Parameters** @@ -2382,7 +2393,7 @@ Returns a result code defined in [OH_AudioStream_Result](#oh_audiostream_result) ### OH_AudioRenderer_GetSpeed() ``` -OH_AudioStream_Result OH_AudioRenderer_GetSpeed (OH_AudioRenderer * renderer, float * speed ) +OH_AudioStream_Result OH_AudioRenderer_GetSpeed(OH_AudioRenderer * renderer, float * speed) ``` **Description** @@ -2483,7 +2494,7 @@ Returns a result code defined in [OH_AudioStream_Result](#oh_audiostream_result) ### OH_AudioRenderer_GetUnderflowCount() ``` -OH_AudioStream_Result OH_AudioRenderer_GetUnderflowCount (OH_AudioRenderer *renderer, uint32_t *count) +OH_AudioStream_Result OH_AudioRenderer_GetUnderflowCount(OH_AudioRenderer *renderer, uint32_t *count) ``` **Description** @@ -2514,7 +2525,7 @@ Returns a result code defined in [OH_AudioStream_Result](#oh_audiostream_result) ### OH_AudioRenderer_GetVolume() ``` -OH_AudioStream_Result OH_AudioRenderer_GetVolume (OH_AudioRenderer *renderer, float *volume) +OH_AudioStream_Result OH_AudioRenderer_GetVolume(OH_AudioRenderer *renderer, float *volume) ``` **Description** @@ -2609,7 +2620,7 @@ Returns a result code defined in [OH_AudioStream_Result](#oh_audiostream_result) ### OH_AudioRenderer_SetDefaultOutputDevice() ``` -OH_AudioStream_Result OH_AudioRenderer_SetDefaultOutputDevice (OH_AudioRenderer* renderer, OH_AudioDevice_Type deviceType) +OH_AudioStream_Result OH_AudioRenderer_SetDefaultOutputDevice(OH_AudioRenderer* renderer, OH_AudioDevice_Type deviceType) ``` **Description** @@ -2652,7 +2663,7 @@ AUDIOSTREAM_ERROR_INVALID_PARAM: ### OH_AudioRenderer_SetEffectMode() ``` -OH_AudioStream_Result OH_AudioRenderer_SetEffectMode (OH_AudioRenderer *renderer, OH_AudioStream_AudioEffectMode effectMode) +OH_AudioStream_Result OH_AudioRenderer_SetEffectMode(OH_AudioRenderer *renderer, OH_AudioStream_AudioEffectMode effectMode) ``` **Description** @@ -2682,7 +2693,7 @@ Returns a result code defined in [OH_AudioStream_Result](#oh_audiostream_result) ### OH_AudioRenderer_SetMarkPosition() ``` -OH_AudioStream_Result OH_AudioRenderer_SetMarkPosition (OH_AudioRenderer *renderer, uint32_t samplePos, OH_AudioRenderer_OnMarkReachedCallback callback, void *userData) +OH_AudioStream_Result OH_AudioRenderer_SetMarkPosition(OH_AudioRenderer *renderer, uint32_t samplePos, OH_AudioRenderer_OnMarkReachedCallback callback, void *userData) ``` **Description** @@ -2721,7 +2732,7 @@ Returns a result code defined in [OH_AudioStream_Result](#oh_audiostream_result) ### OH_AudioRenderer_SetSilentModeAndMixWithOthers() ``` -OH_AudioStream_Result OH_AudioRenderer_SetSilentModeAndMixWithOthers (OH_AudioRenderer *renderer, bool on) +OH_AudioStream_Result OH_AudioRenderer_SetSilentModeAndMixWithOthers(OH_AudioRenderer *renderer, bool on) ``` **Description** @@ -2751,7 +2762,7 @@ Returns a result code defined in [OH_AudioStream_Result](#oh_audiostream_result) ### OH_AudioRenderer_SetSpeed() ``` -OH_AudioStream_Result OH_AudioRenderer_SetSpeed (OH_AudioRenderer *renderer, float speed) +OH_AudioStream_Result OH_AudioRenderer_SetSpeed(OH_AudioRenderer *renderer, float speed) ``` **Description** @@ -2781,7 +2792,7 @@ Returns a result code defined in [OH_AudioStream_Result](#oh_audiostream_result) ### OH_AudioRenderer_SetVolume() ``` -OH_AudioStream_Result OH_AudioRenderer_SetVolume (OH_AudioRenderer *renderer, float volume) +OH_AudioStream_Result OH_AudioRenderer_SetVolume(OH_AudioRenderer *renderer, float volume) ``` **Description** @@ -2818,7 +2829,7 @@ Returns a result code defined in [OH_AudioStream_Result](#oh_audiostream_result) ### OH_AudioRenderer_SetVolumeWithRamp() ``` -OH_AudioStream_Result OH_AudioRenderer_SetVolumeWithRamp (OH_AudioRenderer *renderer, float volume, int32_t durationMs) +OH_AudioStream_Result OH_AudioRenderer_SetVolumeWithRamp(OH_AudioRenderer *renderer, float volume, int32_t durationMs) ``` **Description** @@ -2918,7 +2929,7 @@ Returns a result code defined in [OH_AudioStream_Result](#oh_audiostream_result) ### OH_AudioRoutingManager_GetAvailableDevices() ``` -OH_AudioCommon_Result OH_AudioRoutingManager_GetAvailableDevices (OH_AudioRoutingManager *audioRoutingManager, OH_AudioDevice_Usage deviceUsage, OH_AudioDeviceDescriptorArray **audioDeviceDescriptorArray) +OH_AudioCommon_Result OH_AudioRoutingManager_GetAvailableDevices(OH_AudioRoutingManager *audioRoutingManager, OH_AudioDevice_Usage deviceUsage, OH_AudioDeviceDescriptorArray **audioDeviceDescriptorArray) ``` **Description** @@ -2952,7 +2963,7 @@ Returns a result code defined in [OH_AudioCommon_Result](#oh_audiocommon_result) ### OH_AudioRoutingManager_GetDevices() ``` -OH_AudioCommon_Result OH_AudioRoutingManager_GetDevices (OH_AudioRoutingManager *audioRoutingManager, OH_AudioDevice_Flag deviceFlag, OH_AudioDeviceDescriptorArray **audioDeviceDescriptorArray) +OH_AudioCommon_Result OH_AudioRoutingManager_GetDevices(OH_AudioRoutingManager *audioRoutingManager, OH_AudioDevice_Flag deviceFlag, OH_AudioDeviceDescriptorArray **audioDeviceDescriptorArray) ``` **Description** @@ -2965,7 +2976,7 @@ Obtains available devices based on the device flag. | Name| Description| | -------- | -------- | -| audioRoutingManager | Pointer to an [OH_AudioRoutingManager](#oh_audioroutingmanager) object. which is obtained by calling [OH_AudioManager_GetAudioRoutingManager](#oh_audiomanager_getaudioroutingmanager).| +| audioRoutingManager | Pointer to an [OH_AudioRoutingManager](#oh_audioroutingmanager) object, which is obtained by calling [OH_AudioManager_GetAudioRoutingManager](#oh_audiomanager_getaudioroutingmanager).| | deviceFlag | Device flag, which is used to filter the target device. For details about the available options, see [OH_AudioDevice_Flag](#oh_audiodevice_flag).| | audioDeviceDescriptorArray | Pointer to the audio device descriptor array, which is [OH_AudioDeviceDescriptorArray](_o_h___audio_device_descriptor_array.md). Do not release the pointer to the **audioDeviceDescriptorArray** struct separately. Instead, call [OH_AudioRoutingManager_ReleaseDevices](#oh_audioroutingmanager_releasedevices) to release the **DeviceDescriptor** array.| @@ -2986,7 +2997,7 @@ Returns a result code defined in [OH_AudioCommon_Result](#oh_audiocommon_result) ### OH_AudioRoutingManager_GetPreferredInputDevice() ``` -OH_AudioCommon_Result OH_AudioRoutingManager_GetPreferredInputDevice (OH_AudioRoutingManager *audioRoutingManager, OH_AudioStream_SourceType sourceType, OH_AudioDeviceDescriptorArray **audioDeviceDescriptorArray ) +OH_AudioCommon_Result OH_AudioRoutingManager_GetPreferredInputDevice(OH_AudioRoutingManager *audioRoutingManager, OH_AudioStream_SourceType sourceType, OH_AudioDeviceDescriptorArray **audioDeviceDescriptorArray) ``` **Description** @@ -3021,7 +3032,7 @@ Returns a result code defined in [OH_AudioCommon_Result](#oh_audiocommon_result) ### OH_AudioRoutingManager_GetPreferredOutputDevice() ``` -OH_AudioCommon_Result OH_AudioRoutingManager_GetPreferredOutputDevice (OH_AudioRoutingManager *audioRoutingManager, OH_AudioStream_Usage streamUsage, OH_AudioDeviceDescriptorArray **audioDeviceDescriptorArray ) +OH_AudioCommon_Result OH_AudioRoutingManager_GetPreferredOutputDevice(OH_AudioRoutingManager *audioRoutingManager, OH_AudioStream_Usage streamUsage, OH_AudioDeviceDescriptorArray **audioDeviceDescriptorArray) ``` **Description** @@ -3087,7 +3098,7 @@ Returns a result code defined in [OH_AudioCommon_Result](#oh_audiocommon_result) ### OH_AudioRoutingManager_RegisterDeviceChangeCallback() ``` -OH_AudioCommon_Result OH_AudioRoutingManager_RegisterDeviceChangeCallback (OH_AudioRoutingManager *audioRoutingManager, OH_AudioDevice_Flag deviceFlag, OH_AudioRoutingManager_OnDeviceChangedCallback callback) +OH_AudioCommon_Result OH_AudioRoutingManager_RegisterDeviceChangeCallback(OH_AudioRoutingManager *audioRoutingManager, OH_AudioDevice_Flag deviceFlag, OH_AudioRoutingManager_OnDeviceChangedCallback callback) ``` @@ -3101,7 +3112,7 @@ Registers a callback to listen for device changes of an audio routing manager. | Name| Description| | -------- | -------- | -| audioRoutingManager | Pointer to an [OH_AudioRoutingManager](#oh_audioroutingmanager) object. which is obtained by calling [OH_AudioManager_GetAudioRoutingManager](#oh_audiomanager_getaudioroutingmanager).| +| audioRoutingManager | Pointer to an [OH_AudioRoutingManager](#oh_audioroutingmanager) object, which is obtained by calling [OH_AudioManager_GetAudioRoutingManager](#oh_audiomanager_getaudioroutingmanager).| | deviceFlag | Device flag. For details about the available options, see [OH_AudioDevice_Flag](#oh_audiodevice_flag).| | callback | Callback function used to return the changed audio device descriptor. For details, see [OH_AudioRoutingManager_OnDeviceChangedCallback](#oh_audioroutingmanager_ondevicechangedcallback).| @@ -3121,7 +3132,7 @@ Returns a result code defined in [OH_AudioCommon_Result](#oh_audiocommon_result) ### OH_AudioRoutingManager_ReleaseDevices() ``` -OH_AudioCommon_Result OH_AudioRoutingManager_ReleaseDevices (OH_AudioRoutingManager *audioRoutingManager, OH_AudioDeviceDescriptorArray *audioDeviceDescriptorArray) +OH_AudioCommon_Result OH_AudioRoutingManager_ReleaseDevices(OH_AudioRoutingManager *audioRoutingManager, OH_AudioDeviceDescriptorArray *audioDeviceDescriptorArray) ``` **Description** @@ -3134,7 +3145,7 @@ Releases audio devices available for an audio routing manager. | Name| Description| | -------- | -------- | -| audioRoutingManager | Pointer to an [OH_AudioRoutingManager](#oh_audioroutingmanager) object. which is obtained by calling [OH_AudioManager_GetAudioRoutingManager](#oh_audiomanager_getaudioroutingmanager).| +| audioRoutingManager | Pointer to an [OH_AudioRoutingManager](#oh_audioroutingmanager) object, which is obtained by calling [OH_AudioManager_GetAudioRoutingManager](#oh_audiomanager_getaudioroutingmanager).| | audioDeviceDescriptorArray | Pointer to the array of audio devices, which are obtained by calling [OH_AudioRoutingManager_GetDevices](#oh_audioroutingmanager_getdevices).| **Returns** @@ -3167,7 +3178,7 @@ Before using this function, check whether the current device supports microphone | Name| Description| | -------- | -------- | -| audioRoutingManager | Pointer to an [OH_AudioRoutingManager](#oh_audioroutingmanager) object. which is obtained by using [OH_AudioManager_GetAudioRoutingManager](#oh_audiomanager_getaudioroutingmanager). | +| audioRoutingManager | Pointer to an [OH_AudioRoutingManager](#oh_audioroutingmanager) object, which is obtained by using [OH_AudioManager_GetAudioRoutingManager](#oh_audiomanager_getaudioroutingmanager). | | callback | Pointer to the [OH_AudioRoutingManager_OnDeviceBlockStatusCallback](#oh_audioroutingmanager_ondeviceblockstatuscallback) callback, which is used to return the blocked status.| | userData | Pointer to user data. | @@ -3186,7 +3197,7 @@ Returns a result code defined in [OH_AudioCommon_Result](#oh_audiocommon_result) ### OH_AudioRoutingManager_UnregisterDeviceChangeCallback() ``` -OH_AudioCommon_Result OH_AudioRoutingManager_UnregisterDeviceChangeCallback (OH_AudioRoutingManager *audioRoutingManager, OH_AudioRoutingManager_OnDeviceChangedCallback callback) +OH_AudioCommon_Result OH_AudioRoutingManager_UnregisterDeviceChangeCallback(OH_AudioRoutingManager *audioRoutingManager, OH_AudioRoutingManager_OnDeviceChangedCallback callback) ``` **Description** @@ -3199,7 +3210,7 @@ Unregisters the callback used to listen for device changes of an audio routing m | Name| Description| | -------- | -------- | -| audioRoutingManager | Pointer to an [OH_AudioRoutingManager](#oh_audioroutingmanager) object. which is obtained by calling [OH_AudioManager_GetAudioRoutingManager](#oh_audiomanager_getaudioroutingmanager).| +| audioRoutingManager | Pointer to an [OH_AudioRoutingManager](#oh_audioroutingmanager) object, which is obtained by calling [OH_AudioManager_GetAudioRoutingManager](#oh_audiomanager_getaudioroutingmanager).| | callback | Callback function used to return the changed audio device descriptor. For details, see [OH_AudioRoutingManager_OnDeviceChangedCallback](#oh_audioroutingmanager_ondevicechangedcallback).| **Returns** @@ -3217,7 +3228,7 @@ Returns a result code defined in [OH_AudioCommon_Result](#oh_audiocommon_result) ### OH_AudioSessionManager_ActivateAudioSession() ``` -OH_AudioCommon_Result OH_AudioSessionManager_ActivateAudioSession (OH_AudioSessionManager *audioSessionManager, const OH_AudioSession_Strategy *strategy ) +OH_AudioCommon_Result OH_AudioSessionManager_ActivateAudioSession(OH_AudioSessionManager *audioSessionManager, const OH_AudioSession_Strategy *strategy) ``` **Description** @@ -3248,7 +3259,7 @@ Returns a result code defined in [OH_AudioCommon_Result](#oh_audiocommon_result) ### OH_AudioSessionManager_DeactivateAudioSession() ``` -OH_AudioCommon_Result OH_AudioSessionManager_DeactivateAudioSession (OH_AudioSessionManager *audioSessionManager) +OH_AudioCommon_Result OH_AudioSessionManager_DeactivateAudioSession(OH_AudioSessionManager *audioSessionManager) ``` **Description** @@ -3277,7 +3288,7 @@ Returns a result code defined in [OH_AudioCommon_Result](#oh_audiocommon_result) ### OH_AudioSessionManager_IsAudioSessionActivated() ``` -bool OH_AudioSessionManager_IsAudioSessionActivated (OH_AudioSessionManager *audioSessionManager) +bool OH_AudioSessionManager_IsAudioSessionActivated(OH_AudioSessionManager *audioSessionManager) ``` **Description** @@ -3300,7 +3311,7 @@ Returns **true** if the audio session is activated; returns **false** otherwise. ### OH_AudioSessionManager_RegisterSessionDeactivatedCallback() ``` -OH_AudioCommon_Result OH_AudioSessionManager_RegisterSessionDeactivatedCallback (OH_AudioSessionManager *audioSessionManager, OH_AudioSession_DeactivatedCallback callback) +OH_AudioCommon_Result OH_AudioSessionManager_RegisterSessionDeactivatedCallback(OH_AudioSessionManager *audioSessionManager, OH_AudioSession_DeactivatedCallback callback) ``` **Description** @@ -3331,7 +3342,7 @@ Returns a result code defined in [OH_AudioCommon_Result](#oh_audiocommon_result) ### OH_AudioSessionManager_UnregisterSessionDeactivatedCallback() ``` -OH_AudioCommon_Result OH_AudioSessionManager_UnregisterSessionDeactivatedCallback (OH_AudioSessionManager *audioSessionManager, OH_AudioSession_DeactivatedCallback callback) +OH_AudioCommon_Result OH_AudioSessionManager_UnregisterSessionDeactivatedCallback(OH_AudioSessionManager *audioSessionManager, OH_AudioSession_DeactivatedCallback callback) ``` **Description** @@ -3455,7 +3466,7 @@ Returns a result code defined in [OH_AudioStream_Result](#oh_audiostream_result) 1. The **builder** parameter is set to a null pointer. 2. The **StreamType** parameter is set to an invalid value. - 3. The **OHAudioRenderer** instance fails to be created. + 3. The **OHAudioCapturer** instance fails to be created. ### OH_AudioStreamBuilder_GenerateRenderer() @@ -3595,7 +3606,7 @@ Returns a result code defined in [OH_AudioStream_Result](#oh_audiostream_result) ### OH_AudioStreamBuilder_SetChannelLayout() ``` -OH_AudioStream_Result OH_AudioStreamBuilder_SetChannelLayout (OH_AudioStreamBuilder *builder, OH_AudioChannelLayout channelLayout) +OH_AudioStream_Result OH_AudioStreamBuilder_SetChannelLayout(OH_AudioStreamBuilder *builder, OH_AudioChannelLayout channelLayout) ``` **Description** @@ -3784,7 +3795,7 @@ Returns a result code defined in [OH_AudioStream_Result](#oh_audiostream_result) ### OH_AudioStreamBuilder_SetRendererInterruptMode() ``` -OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererInterruptMode (OH_AudioStreamBuilder *builder, OH_AudioInterrupt_Mode mode) +OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererInterruptMode(OH_AudioStreamBuilder *builder, OH_AudioInterrupt_Mode mode) ``` **Description** @@ -3818,7 +3829,7 @@ Returns a result code defined in [OH_AudioStream_Result](#oh_audiostream_result) ### OH_AudioStreamBuilder_SetRendererOutputDeviceChangeCallback() ``` -OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererOutputDeviceChangeCallback (OH_AudioStreamBuilder * builder, OH_AudioRenderer_OutputDeviceChangeCallback callback, void * userData ) +OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererOutputDeviceChangeCallback(OH_AudioStreamBuilder * builder, OH_AudioRenderer_OutputDeviceChangeCallback callback, void * userData) ``` **Description** @@ -3852,7 +3863,7 @@ Returns a result code defined in [OH_AudioStream_Result](#oh_audiostream_result) ### OH_AudioStreamBuilder_SetRendererPrivacy() ``` -OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererPrivacy (OH_AudioStreamBuilder * builder, OH_AudioStream_PrivacyType privacy) +OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererPrivacy(OH_AudioStreamBuilder * builder, OH_AudioStream_PrivacyType privacy) ``` **Description** @@ -3861,7 +3872,7 @@ Sets the privacy type for the audio stream being played. The privacy type specif **Since**: 12 -**System capability**: SystemCapability.Multimedia.Audio.PlaybackCapture +**System capability**: SystemCapability.Multimedia.Audio.Core **Parameters** @@ -3885,7 +3896,7 @@ Returns a result code defined in [OH_AudioStream_Result](#oh_audiostream_result) ### OH_AudioStreamBuilder_SetRendererWriteDataCallback() ``` -OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererWriteDataCallback (OH_AudioStreamBuilder *builder, OH_AudioRenderer_OnWriteDataCallback callback, void *userData) +OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererWriteDataCallback(OH_AudioStreamBuilder *builder, OH_AudioRenderer_OnWriteDataCallback callback, void *userData) ``` **Description** @@ -3984,7 +3995,7 @@ Returns a result code defined in [OH_AudioStream_Result](#oh_audiostream_result) ### OH_AudioStreamBuilder_SetWriteDataWithMetadataCallback() ``` -OH_AudioStream_Result OH_AudioStreamBuilder_SetWriteDataWithMetadataCallback (OH_AudioStreamBuilder *builder, OH_AudioRenderer_WriteDataWithMetadataCallback callback, void *userData) +OH_AudioStream_Result OH_AudioStreamBuilder_SetWriteDataWithMetadataCallback(OH_AudioStreamBuilder *builder, OH_AudioRenderer_WriteDataWithMetadataCallback callback, void *userData) ``` **Description** @@ -4018,7 +4029,7 @@ Returns a result code defined in [OH_AudioStream_Result](#oh_audiostream_result) ### OH_GetAudioManager() ``` -OH_AudioCommon_Result OH_GetAudioManager (OH_AudioManager ** audioManager) +OH_AudioCommon_Result OH_GetAudioManager(OH_AudioManager ** audioManager) ``` **Description** @@ -4047,7 +4058,7 @@ Returns a result code defined in [OH_AudioCommon_Result](#oh_audiocommon_result) ### OH_GetAudioScene() ``` -OH_AudioCommon_Result OH_GetAudioScene (OH_AudioManager * manager, OH_AudioScene * scene ) +OH_AudioCommon_Result OH_GetAudioScene(OH_AudioManager * manager, OH_AudioScene * scene) ``` **Description** diff --git a/en/application-dev/reference/apis-audio-kit/js-apis-audio-sys.md b/en/application-dev/reference/apis-audio-kit/js-apis-audio-sys.md index ec8b041d3fdf39c8754a1f6d7024c7c74a5b857b..1421ce71e316ac70ec34c49c796f1689c7a822e2 100644 --- a/en/application-dev/reference/apis-audio-kit/js-apis-audio-sys.md +++ b/en/application-dev/reference/apis-audio-kit/js-apis-audio-sys.md @@ -133,7 +133,7 @@ For details about the error codes, see [Audio Error Codes](errorcode-audio.md). import { audio } from '@kit.AudioKit'; let audioStreamInfo: audio.AudioStreamInfo = { - samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100, + samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_48000, channels: audio.AudioChannel.CHANNEL_2, sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE, encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW @@ -198,6 +198,32 @@ Enumerates the audio device flags. | DISTRIBUTED_INPUT_DEVICES_FLAG9+ | 8 | Distributed input device.
This is a system API. | | ALL_DISTRIBUTED_DEVICES_FLAG9+ | 12 | Distributed input and output device.
This is a system API.| +## EffectFlag15+ + +Enumerates the audio effect flags. + +**System API**: This is a system API. + +**System capability**: SystemCapability.Multimedia.Audio.Core + +| Name | Value | Description | +| ------------------------------- | ------ |------------------------------| +| RENDER_EFFECT_FLAG | 0 | Rendered audio effect flag. | +| CAPTURE_EFFECT_FLAG | 1 | Captured audio effect flag. | + +## AudioEffectProperty15+ + +Describes the audio effect properties. + +**System API**: This is a system API. + +**System capability**: SystemCapability.Multimedia.Audio.Core + +| Name | Type| Mandatory| Description | +| ------------------ | ---- | ---- | --------- | +| name | string | Yes| Audio effect name.| +| category | string | Yes| Audio effect category.| +| flag | [EffectFlag](#effectflag15) | Yes| Audio effect flag.| ## StreamUsage @@ -378,6 +404,7 @@ Enumerates the audio source types. | :------------------------------------------- | :----- | :--------------------- | | SOURCE_TYPE_WAKEUP 10+ | 3 | Audio recording source in voice wake-up scenarios.
**System capability**: SystemCapability.Multimedia.Audio.Core
**Required permissions**: ohos.permission.MANAGE_INTELLIGENT_VOICE
This is a system API.| | SOURCE_TYPE_VOICE_CALL11+ | 4 | Audio source in voice calls.
**System capability**: SystemCapability.Multimedia.Audio.Core
**Required permissions**: ohos.permission.RECORD_VOICE_CALL
This is a system API.| +| SOURCE_TYPE_VOICE_TRANSCRIPTION15+ | 12 | Audio source for speech-to-text conversion.
**System capability**: SystemCapability.Multimedia.Audio.Core
This is a system API.| ## VolumeAdjustType10+ @@ -560,6 +587,38 @@ audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL).then(() => { }); ``` +### getEffectManager15+ + +getEffectManager(): AudioEffectManager + +Obtains an **AudioEffectManager** instance. + +**System API**: This is a system API. + +**System capability**: SystemCapability.Multimedia.Audio.Core + +**Return value** + +| Type | Description | +|----------------------------------------------| ----------------------------- | +| [AudioEffectManager](#audioeffectmanager15) | **AudioEffectManager** instance.| + +**Error codes** + +For details about the error codes, see [Audio Error Codes](errorcode-audio.md). + +| ID| Error Message| +| ------- | --------------------------------------------| +| 202 | Not system App. | + +**Example** + +```ts +import { audio } from '@kit.AudioKit'; + +let audioEffectManager: audio.AudioEffectManager = audioManager.getEffectManager(); +``` + ### getSpatializationManager11+ getSpatializationManager(): AudioSpatializationManager @@ -1281,7 +1340,7 @@ This permission is required only for muting or unmuting the ringer when **volume For details about the error codes, see [Audio Error Codes](errorcode-audio.md). | ID| Error Message| -| ------- | --------------------------------------------| +| -------- | --------------------------------------------| | 201 | Permission denied. | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | | 6800101 | Parameter verification failed. Return by promise. | @@ -1298,6 +1357,139 @@ audioVolumeGroupManager.adjustSystemVolumeByStep(audio.AudioVolumeType.MEDIA, au console.error('Fail to adjust the system volume by step.'); }); ``` +## AudioEffectManager15+ + +Manages audio effects. Before calling an API in **AudioEffectManager**, you must use [getEffectManager](geteffectmanager15) to obtain an **AudioEffectManager** instance. + + +### getSupportedAudioEffectProperty15+ + +getSupportedAudioEffectProperty(): Array\ + +Obtains the supported audio effects. This API returns the result synchronously. + +**Required permissions**: ohos.permission.MANAGE_SYSTEM_AUDIO_EFFECTS + +**System API**: This is a system API. + +**System capability**: SystemCapability.Multimedia.Audio.Core + +**Return value** + +| Type | Description | +| --------------------------------------------------------------------------| --------------------------------------- | +| Array\<[AudioEffectProperty](#audioeffectproperty15)> | Properties of the audio effects supported. | + +**Error codes** + +For details about the error codes, see [Audio Error Codes](errorcode-audio.md). + +| ID| Error Message| +| ------- | --------------------------------------------| +| 201 | Permission denied. | +| 202 | Caller is not a system application. | +| 6800301 | System error. Return by callback. | + +**Example** + +```ts +import { BusinessError } from '@kit.BasicServicesKit'; + +try { + let propertyArray: Array = audioStreamManager.getSupportedAudioEffectProperty(); + console.info(`The effect modes are: ${propertyArray}`); +} catch (err) { + let error = err as BusinessError; + console.error(`getSupportedAudioEffectProperty ERROR: ${error}`); +} +``` + + +### getAudioEffectProperty15+ + +getAudioEffectProperty(): Array\ + +Obtains the audio effect in use. This API returns the result synchronously. + +**Required permissions**: ohos.permission.MANAGE_SYSTEM_AUDIO_EFFECTS + +**System API**: This is a system API. + +**System capability**: SystemCapability.Multimedia.Audio.Core + +**Return value** + +| Type | Description | +| --------------------------------------------------------------------------| --------------------------------------- | +| Array\<[AudioEffectProperty](#audioeffectproperty15)> | Audio effect in use. | + +**Error codes** + +For details about the error codes, see [Audio Error Codes](errorcode-audio.md). + +| ID| Error Message| +| ------- | --------------------------------------------| +| 201 | Permission denied. | +| 202 | Caller is not a system application. | +| 6800301 | System error. Return by callback. | + +**Example** + +```ts +import { BusinessError } from '@kit.BasicServicesKit'; + +try { + let propertyArray: Array = audioStreamManager.getAudioEffectProperty(); + console.info(`The effect modes are: ${propertyArray}`); +} catch (err) { + let error = err as BusinessError; + console.error(`getAudioEffectProperty ERROR: ${error}`); +} +``` + +### setAudioEffectProperty15+ + +setAudioEffectProperty(propertyArray: Array\): void + +Sets an audio effect in use. This API returns the result synchronously. + +**Required permissions**: ohos.permission.MANAGE_SYSTEM_AUDIO_EFFECTS + +**System API**: This is a system API. + +**System capability**: SystemCapability.Multimedia.Audio.core + +**Parameters** +| Name | Type | Mandatory | Description | +| ------------- | ----------------------------------------------------- | -------- | ---------------------------- | +| propertyArray | Array\<[AudioEffectProperty](#audioeffectproperty15)> | Yes | Property of the audio effect. | + +**Error codes** + +For details about the error codes, see [Audio Error Codes](errorcode-audio.md). + +| ID| Error Message| +| ------- | --------------------------------------------| +| 201 | Permission denied. | +| 202 | Caller is not a system application. | +| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | +| 6800101 | Parameter verification failed. Possible causes: 1.more than one enhanceProps of the same enhanceClass in input Array; 2.input audioEnhanceProperties are not supported by current device. 3.names of enhanceProp or enhanceClass are incorrect.| +| 6800301 | System error. Return by callback. | + +**Example** + +```ts +import { BusinessError } from '@kit.BasicServicesKit'; + +try { + let propertyArray: Array = audioEffectManager.getAudioEffectProperty(); + console.info(`The effect modes are: ${propertyArray}`); + audioEffectManager.setAudioEffectProperty(propertyArray); +} catch (err) { + let error = err as BusinessError; + console.error(`setAudioEffectProperty ERROR: ${error}`); +} +``` ## AudioRoutingManager9+ @@ -1621,6 +1813,215 @@ async function selectOutputDeviceByFilter(){ } ``` +### selectInputDeviceByFilter14+ + +selectInputDeviceByFilter(filter: AudioCapturerFilter, inputAudioDeviceDescriptor: AudioDeviceDescriptors, callback: AsyncCallback<void>): void + +Selects an audio input device based on the filter criteria. Currently, only one input device can be selected. This API uses an asynchronous callback to return the result. + +**System API**: This is a system API. + +**System capability**: SystemCapability.Multimedia.Audio.Device + +**Parameters** + +| Name | Type | Mandatory| Description | +|-----------------------------|-------------------------------------------------------------------| ---- |-----------------------------------------| +| filter | [AudioCapturerFilter](#audiocapturerfilter14) | Yes | Filter criteria. | +| outputAudioDeviceDescriptor | [AudioDeviceDescriptors](js-apis-audio.md#audiodevicedescriptors) | Yes | Input device. | +| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| + +**Example** +```ts +import { audio } from '@kit.AudioKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +let inputAudioCapturerFilter: audio.AudioCapturerFilter = { + uid : 20010041, + capturerInfo : { + source: audio.SourceType.SOURCE_TYPE_MIC, + capturerFlags: 0 + } +}; + +let inputAudioDeviceDescriptor: audio.AudioDeviceDescriptors = [{ + deviceRole : audio.DeviceRole.INPUT_DEVICE, + deviceType : audio.DeviceType.MIC, + id : 1, + name : "", + address : "", + sampleRates : [44100], + channelCounts : [2], + channelMasks : [0], + networkId : audio.LOCAL_NETWORK_ID, + interruptGroupId : 1, + volumeGroupId : 1, + displayName : "", +}]; + +async function selectInputDeviceByFilter() { + let audioManager = audio.getAudioManager(); // Create an AudioManager instance. + let audioRoutingManager = audioManager.getRoutingManager(); // Call an API of AudioManager to create an AudioRoutingManager instance. + audioRoutingManager.selectInputDeviceByFilter(inputAudioCapturerFilter, inputAudioDeviceDescriptor, (err: BusinessError) => { + if (err) { + console.error(`Result ERROR: ${err}`); + } else { + console.info('Select input devices by filter result callback: SUCCESS'); } + }); +} +``` + +### selectInputDeviceByFilter14+ + +selectInputDeviceByFilter(filter: AudioCapturerFilter, outputAudioDevices: AudioDeviceDescriptors): Promise<void> + +Selects an audio input device based on the filter criteria. Currently, only one input device can be selected. This API uses a promise to return the result. + +**System API**: This is a system API. + +**System capability**: SystemCapability.Multimedia.Audio.Device + +**Parameters** + +| Name | Type | Mandatory| Description | +| ----------------------| ------------------------------------------------------------ | ---- |--------| +| filter | [AudioCapturerFilter](#audiocapturerfilter14) | Yes | Filter criteria.| +| outputAudioDeviceDescriptor | [AudioDeviceDescriptors](js-apis-audio.md#audiodevicedescriptors) | Yes | Input device.| + +**Return value** + +| Type | Description | +| --------------------- | --------------------------- | +| Promise<void> | Promise that returns no value.| + +**Example** + +```ts +import { audio } from '@kit.AudioKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +let inputAudioCapturerFilter: audio.AudioCapturerFilter = { + uid : 20010041, + capturerInfo : { + source: audio.SourceType.SOURCE_TYPE_MIC, + capturerFlags: 0 + } +}; + +let inputAudioDeviceDescriptor: audio.AudioDeviceDescriptors = [{ + deviceRole : audio.DeviceRole.INPUT_DEVICE, + deviceType : audio.DeviceType.MIC, + id : 1, + name : "", + address : "", + sampleRates : [44100], + channelCounts : [2], + channelMasks : [0], + networkId : audio.LOCAL_NETWORK_ID, + interruptGroupId : 1, + volumeGroupId : 1, + displayName : "", +}]; + +async function selectInputDeviceByFilter(){ + let audioManager = audio.getAudioManager(); // Create an AudioManager instance. + let audioRoutingManager = audioManager.getRoutingManager(); // Call an API of AudioManager to create an AudioRoutingManager instance. + audioRoutingManager.selectInputDeviceByFilter(inputAudioCapturerFilter, inputAudioDeviceDescriptor).then(() => { + console.info('Select input devices by filter result promise: SUCCESS'); + }).catch((err: BusinessError) => { + console.error(`Result ERROR: ${err}`); + }) +} +``` + +### getPreferredOutputDeviceByFilter14+ + +getPreferredOutputDeviceByFilter(filter: AudioRendererFilter): AudioDeviceDescriptors + +Obtains an audio output device based on the filter criteria. + +**System API**: This is a system API. + +**System capability**: SystemCapability.Multimedia.Audio.Device + +**Parameters** + +| Name | Type | Mandatory| Description | +| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- | +| filter | [AudioRendererFilter](#audiorendererfilter9) | Yes | Filter criteria. | + +**Return value** + +| Type | Description | +| --------------------- | --------------------------- | +| [AudioDeviceDescriptors](js-apis-audio.md#audiodevicedescriptors)| return the device list. | + +**Example** +```ts +import { audio } from '@kit.AudioKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +let outputAudioRendererFilter: audio.AudioRendererFilter = { + uid : 20010041, + rendererInfo : { + usage : audio.StreamUsage.STREAM_USAGE_MUSIC, + rendererFlags : 0 + }, + rendererId : 0 +}; + +async function selectOutputDeviceByFilter(){ + let audioManager = audio.getAudioManager(); // Create an AudioManager instance. + let audioRoutingManager = audioManager.getRoutingManager(); // Call an API of AudioManager to create an AudioRoutingManager instance. + let desc : audio.AudioDeviceDescriptors = audioRoutingManager.getPreferredOutputDeviceByFilter(outputAudioRendererFilter); + console.info(`device descriptor: ${desc}`); +} +``` + +### getPreferredInputDeviceByFilter14+ + +getPreferredInputDeviceByFilter(filter: AudioRendererFilter): AudioDeviceDescriptors + +Obtains an audio input device based on the filter criteria. Currently, only one input device can be acquired. + +**System API**: This is a system API. + +**System capability**: SystemCapability.Multimedia.Audio.Device + +**Parameters** + +| Name | Type | Mandatory| Description | +|---------------------| ------------------------------------------------------------ | ---- | ------------------------- | +| filter | [AudioCapturerFilter](#audiocapturerfilter14) | Yes | Filter criteria.| + +**Return value** + +| Type | Description | +| --------------------- | --------------------------- | +| [AudioDeviceDescriptors](js-apis-audio.md#audiodevicedescriptors) | return the device list. | + +**Example** + +```ts +import { audio } from '@kit.AudioKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +let inputAudioCapturerFilter: audio.AudioCapturerFilter = { + uid : 20010041, + capturerInfo : { + source: audio.SourceType.SOURCE_TYPE_MIC, + capturerFlags: 0 + } +}; + +async function getPreferredInputDeviceByFilter(){ + let audioManager = audio.getAudioManager(); // Create an AudioManager instance. + let audioRoutingManager = audioManager.getRoutingManager(); // Call an API of AudioManager to create an AudioRoutingManager instance. + let desc: audio.AudioDeviceDescriptors = audioRoutingManager.getPreferredInputDeviceByFilter(inputAudioCapturerFilter); + console.info(`device descriptor: ${desc}`); +} +``` + ## AudioRendererChangeInfo9+ Describes the audio renderer change event. @@ -1679,6 +2080,30 @@ let outputAudioRendererFilter: audio.AudioRendererFilter = { rendererId : 0 }; ``` +## AudioCapturerFilter14+ + +Filter criteria. Before calling **selectOutputDeviceByFilter**, you must obtain an **AudioCapturerFilter** instance. + +**System API**: This is a system API. + +| Name | Type | Mandatory| Description | +| -------------| ---------------------------------------- | ---- | -------------- | +| uid | number | No | Application ID.
**System capability**: SystemCapability.Multimedia.Audio.Core| +| capturerInfo | [AudioCapturerInfo](js-apis-audio.md#audiocapturerinfo8) | No | Audio capturer information.
**System capability**: SystemCapability.Multimedia.Audio.Capturer| + +**Example** + +```ts +import { audio } from '@kit.AudioKit'; + +let inputAudioCapturerFilter: audio.AudioCapturerFilter = { + uid : 20010041, + capturerInfo : { + source: audio.SourceType.SOURCE_TYPE_MIC, + capturerFlags: 0 + } +}; +``` ## AudioSpatialEnabledStateForDevice12+ diff --git a/en/application-dev/reference/apis-audio-kit/js-apis-audio.md b/en/application-dev/reference/apis-audio-kit/js-apis-audio.md index d3731e384ce50c177a5edb691f0ee81abd567063..a48974f4fac5115b0cfcb12c8f82e8d274920f11 100644 --- a/en/application-dev/reference/apis-audio-kit/js-apis-audio.md +++ b/en/application-dev/reference/apis-audio-kit/js-apis-audio.md @@ -76,8 +76,8 @@ Creates an **AudioRenderer** instance. This API uses an asynchronous callback to import { audio } from '@kit.AudioKit'; let audioStreamInfo: audio.AudioStreamInfo = { - samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100, - channels: audio.AudioChannel.CHANNEL_1, + samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_48000, + channels: audio.AudioChannel.CHANNEL_2, sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE, encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW }; @@ -129,8 +129,8 @@ import { audio } from '@kit.AudioKit'; import { BusinessError } from '@kit.BasicServicesKit'; let audioStreamInfo: audio.AudioStreamInfo = { - samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100, - channels: audio.AudioChannel.CHANNEL_1, + samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_48000, + channels: audio.AudioChannel.CHANNEL_2, sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE, encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW }; @@ -180,7 +180,7 @@ This permission is required when [SourceType](#sourcetype8) is set to **SOURCE_T import { audio } from '@kit.AudioKit'; let audioStreamInfo: audio.AudioStreamInfo = { - samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100, + samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_48000, channels: audio.AudioChannel.CHANNEL_2, sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE, encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW @@ -237,7 +237,7 @@ import { audio } from '@kit.AudioKit'; import { BusinessError } from '@kit.BasicServicesKit'; let audioStreamInfo: audio.AudioStreamInfo = { - samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100, + samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_48000, channels: audio.AudioChannel.CHANNEL_2, sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE, encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW @@ -415,8 +415,8 @@ Enumerates the audio channels. | Name | Value | Description | | --------- | -------- |------| -| CHANNEL_1 | 0x1 << 0 | One audio channel (mono).| -| CHANNEL_2 | 0x1 << 1 | Two audio channels (stereo).| +| CHANNEL_1 | 1 | One audio channel (mono).| +| CHANNEL_2 | 2 | Two audio channels (stereo).| | CHANNEL_311+ | 3 | Three audio channels.| | CHANNEL_411+ | 4 | Four audio channels.| | CHANNEL_511+ | 5 | Five audio channels.| @@ -763,7 +763,7 @@ Describes the audio device blocked status and device information. | Name | Type | Mandatory| Description | | :---------------- | :------------------------------------------------ | :--- | :----------------- | | blockStatus | [DeviceBlockStatus](#deviceblockstatus13) | Yes | Blocked status of the audio device.| -| deviceDescriptors | [AudioDeviceDescriptors](#audiodevicedescriptors) | Yes | Device information. | +| devices | [AudioDeviceDescriptors](#audiodevicedescriptors) | Yes | Device information. | ## ChannelBlendMode11+ @@ -5368,10 +5368,16 @@ audioSessionManager.off('audioSessionDeactivated', audioSessionDeactivatedCallba ## AudioRendererChangeInfoArray9+ +type AudioRendererChangeInfoArray = Array<Readonly<AudioRendererChangeInfo>> + Defines an **AudioRenderChangeInfo** array, which is read-only. **System capability**: SystemCapability.Multimedia.Audio.Renderer +| Type | Description | +|---------|---------------------------------------------------------------| +| Array<Readonly<AudioRendererChangeInfo>> | Defines an [AudioRenderChangeInfo](#audiorendererchangeinfo9) array, which is read-only.| + ## AudioRendererChangeInfo9+ Describes the audio renderer change event. @@ -5417,10 +5423,16 @@ audioStreamManager.on('audioRendererChange', (AudioRendererChangeInfoArray) => ## AudioCapturerChangeInfoArray9+ +type AudioCapturerChangeInfoArray = Array<Readonly<AudioCapturerChangeInfo>> + Defines an **AudioCapturerChangeInfo** array, which is read-only. **System capability**: SystemCapability.Multimedia.Audio.Capturer +| Type | Description | +|---------|-----------------------------------------------------------------| +| Array<Readonly<AudioCapturerChangeInfo>> | An [AudioCapturerChangeInfo](#audiocapturerchangeinfo9) array, which is read-only.| + ## AudioCapturerChangeInfo9+ Describes the audio capturer change event. @@ -5465,14 +5477,30 @@ audioStreamManager.on('audioCapturerChange', (AudioCapturerChangeInfoArray) => ## AudioEffectInfoArray10+ +type AudioEffectInfoArray = Array<Readonly<AudioEffectMode>> + Defines an array that contains the audio effect mode corresponding to a specific audio content type (specified by **ContentType**) and audio stream usage (specified by **StreamUsage**). The [AudioEffectMode](#audioeffectmode10) array is read-only. +**System capability**: SystemCapability.Multimedia.Audio.Renderer + +| Type | Description | +|---------|---------------------------------------------------------------| +| Array<Readonly<AudioEffectMode>> | Defines an array that contains the audio effect mode corresponding to a specific audio content type (specified by **ContentType**) and audio stream usage (specified by **StreamUsage**). The [AudioEffectMode](#audioeffectmode10) array is read-only.| + ## AudioDeviceDescriptors +type AudioDeviceDescriptors = Array<Readonly<AudioDeviceDescriptor>> + Defines an [AudioDeviceDescriptor](#audiodevicedescriptor) array, which is read-only. **Atomic service API**: This API can be used in atomic services since API version 12. +**System capability**: SystemCapability.Multimedia.Audio.Device + +| Type | Description | +|---------|---------------------------------------------------------------| +| Array<Readonly<AudioDeviceDescriptor>> | Defines an [AudioDeviceDescriptor](#audiodevicedescriptor) array, which is read-only.| + ## AudioDeviceDescriptor Describes an audio device. @@ -5541,9 +5569,9 @@ Defines the callback function used to write data to the audio renderer. Once the **Return value** -| Type | Description| -|--------------------------------------------------------------| ------- | -| [AudioDataCallbackResult](#audiodatacallbackresult12) \| void | If **void** or **AudioDataCallbackResult.VALID** is returned, the data is valid and will be played. If **AudioDataCallbackResult.INVALID** is returned, the data is invalid and will not be played.| +| Type | Description | +|--------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------| +| [AudioDataCallbackResult](#audiodatacallbackresult12) \| void | If **void** or **AudioDataCallbackResult.VALID** is returned, the data is valid and the audio data is played. If **AudioDataCallbackResult.INVALID** is returned, the data is invalid and the audio data is not played.| ## AudioRenderer8+ @@ -7824,6 +7852,8 @@ on(type: 'writeData', callback: AudioRendererWriteDataCallback): void Subscribes to the audio data write event, which is triggered when audio data needs to be written. This API uses an asynchronous callback to return the result. +The callback function is used only to write audio data. Do not call AudioRenderer APIs in it. + **System capability**: SystemCapability.Multimedia.Audio.Renderer **Parameters** @@ -9093,6 +9123,8 @@ on(type: 'readData', callback: Callback\): void Subscribes to the audio data read event, which is triggered when audio stream data needs to be read. This API uses an asynchronous callback to return the result. +The callback function is used only to read audio data. Do not call AudioCapturer APIs in it. + **System capability**: SystemCapability.Multimedia.Audio.Capturer **Parameters** diff --git a/en/application-dev/reference/apis-audio-kit/js-apis-systemSoundManager-sys.md b/en/application-dev/reference/apis-audio-kit/js-apis-systemSoundManager-sys.md index 1a2ed0a67af8ff8c9894b16beb8b75638eb5e99e..e4c531543f1733cf25522666950f0b71a332179a 100644 --- a/en/application-dev/reference/apis-audio-kit/js-apis-systemSoundManager-sys.md +++ b/en/application-dev/reference/apis-audio-kit/js-apis-systemSoundManager-sys.md @@ -361,9 +361,7 @@ Enumerates the haptics styles for system ringtones. | STANDARD| 0 | Standard haptics style.| | GENTLE | 1 | Gentle haptics style.| -## ToneHapticsType13+ - -type ToneHapticsType = RingtoneType | SystemToneType +## ToneHapticsType14+ Enumerates the haptics types for system ringtones. @@ -371,12 +369,15 @@ Enumerates the haptics types for system ringtones. **System capability**: SystemCapability.Multimedia.SystemSound.Core -| Name | Description | -| ------------------------------------|------------| -| [RingtoneType](#ringtonetype) | Ringtone type.| -| [SystemToneType](#systemtonetype11) | System alert tone type.| +| Name | Value| Description | +| ------------------------|----|--------| +| CALL_SIM_CARD_0 | 0 | Haptic feedback with the ringtone for an incoming call on SIM card 1.| +| CALL_SIM_CARD_1 | 1 | Haptic feedback with the ringtone for an incoming call on SIM card 2.| +| TEXT_MESSAGE_SIM_CARD_0 | 20 | Haptic feedback with the ringtone for an incoming message on SIM card 1.| +| TEXT_MESSAGE_SIM_CARD_1 | 21 | Haptic feedback with the ringtone for an incoming message on SIM card 2.| +| NOTIFICATION | 40 | Haptic feedback with the notification tone.| -## ToneHapticsMode13+ +## ToneHapticsMode14+ Enumerates the haptics modes in system ringtone scenarios. @@ -390,7 +391,7 @@ Enumerates the haptics modes in system ringtone scenarios. | SYNC | 1 | Sync mode, where the haptic feedback is aligned with the system ringtone.| | NON_SYNC | 2 | Non-sync mode, where the haptic feedback is not aligned with the system ringtone.| -## ToneHapticsSettings13+ +## ToneHapticsSettings14+ Describes the haptics settings of a system ringtone. @@ -400,14 +401,14 @@ Describes the haptics settings of a system ringtone. | Name | Type| Read-Only| Optional| Description | | ------------ | -- | -- | -- | -------------------- | -| mode | [ToneHapticsMode](#tonehapticsmode13) | No| No| Haptics mode.| -| hapticsUri | string | No| Yes| URI of the haptics resource. The URI, obtained by calling [getToneHapticsList](#gettonehapticslist13), is valid only in the non-sync mode and should be ignored in other haptics modes.| +| mode | [ToneHapticsMode](#tonehapticsmode14) | No| No| Haptics mode.| +| hapticsUri | string | No| Yes| URI of the haptics resource. The URI, obtained by calling [getToneHapticsList](#gettonehapticslist14), is valid only in the non-sync mode and should be ignored in other haptics modes.| -## ToneHapticsAttrs13+ +## ToneHapticsAttrs14+ -Manages haptics attributes of system ringtones. Before calling any API in **ToneHapticsAttrs13+**, you must call [getToneHapticsList](#gettonehapticslist13) or [getHapticsAttrsSyncedWithTone](#gethapticsattrssyncedwithtone13) to obtain an instance. +Manages haptics attributes of system ringtones. Before calling any API in **ToneHapticsAttrs14+**, you must call [getToneHapticsList](#gettonehapticslist14) or [getHapticsAttrsSyncedWithTone](#gethapticsattrssyncedwithtone14) to obtain an instance. -### getUri13+ +### getUri14+ getUri(): string @@ -435,7 +436,7 @@ Obtains the URI of this haptics resource. toneHapticsAttrs.getUri(); ``` -### getTitle13+ +### getTitle14+ getTitle(): string @@ -463,7 +464,7 @@ Obtains the title of this haptics resource. toneHapticsAttrs.getTitle(); ``` -### getFileName13+ +### getFileName14+ getFileName(): string @@ -491,7 +492,7 @@ Obtains the file name of this haptics resource. toneHapticsAttrs.getFileName(); ``` -## ToneHapticsAttrsArray13+ +## ToneHapticsAttrsArray14+ type ToneHapticsAttrsArray = Array<ToneHapticsAttrs> @@ -501,7 +502,7 @@ Describes the haptics attribute array of a system ringtone. | Type | Description | |----------------------------------------|---------| -| Array<[ToneHapticsAttrs](#tonehapticsattrs13)> | Array of haptics attributes.| +| Array<[ToneHapticsAttrs](#tonehapticsattrs14)> | Array of haptics attributes.| ## systemSoundManager.getSystemSoundManager @@ -547,7 +548,7 @@ Sets a URI for a system ringtone. This API uses an asynchronous callback to retu | Name | Type | Mandatory| Description | | -------- | ---------------------------------------- | ---- | ------------------------ | | context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Application context. | -| uri | string | Yes | URI of the system ringtone. For details, see [media.AVPlayer](../apis-media-kit/js-apis-media.md#avplayer9).| +| uri | string | Yes | URI of the system ringtone. For details about supported resources, see [media.AVPlayer](../apis-media-kit/js-apis-media.md#avplayer9).| | type | [RingtoneType](#ringtonetype) | Yes | Type of the system ringtone. | | callback | AsyncCallback<void> | Yes | Callback used to return the result. | @@ -590,7 +591,7 @@ Sets a URI for a system ringtone. This API uses a promise to return the result. | Name | Type | Mandatory| Description | | -------- | ---------------------------------------- | ---- | ------------------------ | | context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Application context. | -| uri | string | Yes | URI of the system ringtone. For details, see [media.AVPlayer](../apis-media-kit/js-apis-media.md#avplayer9).| +| uri | string | Yes | URI of the system ringtone. For details about supported resources, see [media.AVPlayer](../apis-media-kit/js-apis-media.md#avplayer9).| | type | [RingtoneType](#ringtonetype) | Yes | Type of the system ringtone. | **Return value** @@ -806,7 +807,7 @@ Sets a URI for a system ringtone. This API uses a promise to return the result. | Name | Type | Mandatory| Description | | -------- |-------------------------------| ---- | ------------------------ | | context | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | Yes | Application context. | -| uri | string | Yes | URI of the system ringtone. For details, see [media.AVPlayer](../apis-media-kit/js-apis-media.md#avplayer9).| +| uri | string | Yes | URI of the system ringtone. For details about supported resources, see [media.AVPlayer](../apis-media-kit/js-apis-media.md#avplayer9).| | type | [RingtoneType](#ringtonetype) | Yes | Type of the system ringtone. | **Return value** @@ -959,7 +960,7 @@ Sets a URI for a system alert tone. This API uses a promise to return the result | Name | Type | Mandatory| Description | | -------- |-------------------------------------| ---- | ------------------------ | | context | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | Yes | Application context. | -| uri | string | Yes | URI of the system alert tone. For details, see [media.AVPlayer](../apis-media-kit/js-apis-media.md#avplayer9).| +| uri | string | Yes | URI of the system alert tone. For details about supported resources, see [media.AVPlayer](../apis-media-kit/js-apis-media.md#avplayer9).| | type | [SystemToneType](#systemtonetype11) | Yes | Type of the system alert tone. | **Return value** @@ -1118,7 +1119,7 @@ Obtains the attributes of the default system ringtone. This API uses a promise t | Type | Description | |------------------------------------------|---------------------| -| Promise<[ToneAttrs](#toneattrs12)> | Promise used to return the attributes of the default system ringtone.| +| Promise<[ToneAttrs](#toneattrs12)> | Promise used to return the attributes of the default system ringtone.| **Error codes** @@ -1168,7 +1169,7 @@ Obtains the list of attributes of the default system ringtone. This API uses a p | Type | Description | |----------------------------------------------------|-----------------------| -| Promise<[ToneAttrsArray](#toneattrsarray12)> | Promise used to return an array of the attributes of the default system ringtone.| +| Promise<[ToneAttrsArray](#toneattrsarray12)> | Promise used to return an array of the attributes of the default system ringtone.| **Error codes** @@ -1218,7 +1219,7 @@ Obtains the attributes of the default system alert tone. This API uses a promise | Type | Description | |-----------------------------------------|----------------------| -| Promise<[ToneAttrs](#toneattrs12)> | Promise used to return the attributes of the default system alert tone.| +| Promise<[ToneAttrs](#toneattrs12)> | Promise used to return the attributes of the default system alert tone.| **Error codes** @@ -1268,7 +1269,7 @@ Obtains the list of attributes of the default system alert tone. This API uses a | Type | Description | |---------------------------------------------------|------------------------| -| Promise<[ToneAttrsArray](#toneattrsarray12)> | Promise used to return an array of the attributes of the default system alert tone.| +| Promise<[ToneAttrsArray](#toneattrsarray12)> | Promise used to return an array of the attributes of the default system alert tone.| **Error codes** @@ -1317,7 +1318,7 @@ Obtains the attributes of the default alarm alert tone. This API uses a promise | Type | Description | |-----------------------------------------|---------------------| -| Promise<[ToneAttrs](#toneattrs12)> | Promise used to return the attributes of the default alarm alert tone.| +| Promise<[ToneAttrs](#toneattrs12)> | Promise used to return the attributes of the default alarm alert tone.| **Error codes** @@ -1360,7 +1361,7 @@ Sets a URI for an alarm alert tone. This API uses a promise to return the result | Name | Type | Mandatory| Description | | -------- | --------- | ---- |--------------------------| | context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Application context. | -| uri | string | Yes | URI of the alarm alert tone. For details, see [media.AVPlayer](../apis-media-kit/js-apis-media.md#avplayer9).| +| uri | string | Yes | URI of the alarm alert tone. For details about supported resources, see [media.AVPlayer](../apis-media-kit/js-apis-media.md#avplayer9).| **Return value** @@ -1486,7 +1487,7 @@ Enables an alarm alert tone. This API uses a promise to return the result. | Name | Type | Mandatory| Description | | -------- | ---------| ---- |-------------------------------------------------------------------------------------| | context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Application context. | -| uri | string | Yes | URI of the alarm alert tone. For details, see [media.AVPlayer](../apis-media-kit/js-apis-media.md#avplayer9).| +| uri | string | Yes | URI of the alarm alert tone. For details about supported resources, see [media.AVPlayer](../apis-media-kit/js-apis-media.md#avplayer9).| **Return value** @@ -1751,7 +1752,7 @@ systemSoundManagerInstance.removeCustomizedTone(context, uri).then(() => { }); ``` -### getToneHapticsSettings13+ +### getToneHapticsSettings14+ getToneHapticsSettings(context: BaseContext, type: ToneHapticsType): Promise<ToneHapticsSettings> @@ -1766,13 +1767,13 @@ Obtains the haptics settings of the system ringtone. This API uses a promise to | Name| Type | Mandatory| Description | |-----|-----------| ---- |----------------------------------------------------------------------------------| | context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Application context. | -| type | [ToneHapticsType](#tonehapticstype13) | Yes | Haptics type of the system ringtone.| +| type | [ToneHapticsType](#tonehapticstype14) | Yes | Haptics type of the system ringtone.| **Return value** | Type | Description | |---------------------|-----------------------| -| Promise<[ToneHapticsSettings](#tonehapticssettings13)> | Promise used to return the haptics settings.| +| Promise<[ToneHapticsSettings](#tonehapticssettings14)> | Promise used to return the haptics settings.| **Error codes** @@ -1792,7 +1793,7 @@ import { BusinessError } from '@kit.BasicServicesKit'; import { common } from '@kit.AbilityKit'; let context: common.BaseContext = getContext(this); -let type: systemSoundManager.ToneHapticsType = systemSoundManager.RingtoneType.RINGTONE_TYPE_SIM_CARD_0; +let type: systemSoundManager.ToneHapticsType = systemSoundManager.ToneHapticsType.CALL_SIM_CARD_0; let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager(); systemSoundManagerInstance.getToneHapticsSettings(context, type).then((value: systemSoundManager.ToneHapticsSettings) => { @@ -1802,7 +1803,7 @@ systemSoundManagerInstance.getToneHapticsSettings(context, type).then((value: sy }); ``` -### setToneHapticsSettings13+ +### setToneHapticsSettings14+ setToneHapticsSettings(context: BaseContext, type: ToneHapticsType, settings: ToneHapticsSettings): Promise<void> @@ -1817,8 +1818,8 @@ Sets the haptics settings for the system ringtone. This API uses a promise to re | Name| Type | Mandatory| Description | |-----|-----------| ---- |----------------------------------------------------------------------------------| | context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Application context. | -| type | [ToneHapticsType](#tonehapticstype13) | Yes | Haptics type of the system ringtone.| -| settings | [ToneHapticsSettings](#tonehapticssettings13) | Yes | Haptics settings of the system ringtone.| +| type | [ToneHapticsType](#tonehapticstype14) | Yes | Haptics type of the system ringtone.| +| settings | [ToneHapticsSettings](#tonehapticssettings14) | Yes | Haptics settings of the system ringtone.| **Return value** @@ -1845,7 +1846,7 @@ import { BusinessError } from '@kit.BasicServicesKit'; import { common } from '@kit.AbilityKit'; let context: common.BaseContext = getContext(this); -let type: systemSoundManager.ToneHapticsType = systemSoundManager.RingtoneType.RINGTONE_TYPE_SIM_CARD_0; +let type: systemSoundManager.ToneHapticsType = systemSoundManager.ToneHapticsType.CALL_SIM_CARD_0; let toneHapticsSettings: systemSoundManager.ToneHapticsSettings = { mode: systemSoundManager.ToneHapticsMode.NON_SYNC, hapticsUri: '/data/storage/el2/base/haptics/synchronized/alarms/test.json', // Use the URI obtained through getToneHapticsList. @@ -1859,7 +1860,7 @@ systemSoundManagerInstance.setToneHapticsSettings(context, type, toneHapticsSett }); ``` -### getToneHapticsList13+ +### getToneHapticsList14+ getToneHapticsList(context: BaseContext, isSynced: boolean): Promise<ToneHapticsAttrsArray> @@ -1880,7 +1881,7 @@ Obtains the haptics attributes of the system ringtone in sync or non-sync mode. | Type | Description | |---------------------|-----------------------| -| Promise<[ToneHapticsAttrsArray](#tonehapticsattrsarray13)> | Promise used to return the haptics attributes.| +| Promise<[ToneHapticsAttrsArray](#tonehapticsattrsarray14)> | Promise used to return the haptics attributes.| **Error codes** @@ -1909,7 +1910,7 @@ systemSoundManagerInstance.getToneHapticsList(context, false).then((value: syste }); ``` -### getHapticsAttrsSyncedWithTone13+ +### getHapticsAttrsSyncedWithTone14+ getHapticsAttrsSyncedWithTone(context: BaseContext, toneUri: string): Promise<ToneHapticsAttrs> @@ -1930,7 +1931,7 @@ Obtains the attributes of the haptics feedback synchronized with the system ring | Type | Description | |---------------------|-----------------------| -| Promise<[ToneHapticsAttrs](#tonehapticsattrs13)> | Promise used to return the haptics attributes.| +| Promise<[ToneHapticsAttrs](#tonehapticsattrs14)> | Promise used to return the haptics attributes.| **Error codes** @@ -1961,7 +1962,7 @@ systemSoundManagerInstance.getHapticsAttrsSyncedWithTone(context, toneUri).then( }); ``` -### openToneHaptics13+ +### openToneHaptics14+ openToneHaptics(context: Context, hapticsUri: string): Promise<number> diff --git a/en/application-dev/reference/apis-audio-kit/native__audio__device__base_8h.md b/en/application-dev/reference/apis-audio-kit/native__audio__device__base_8h.md index 2a7416bda88393848cc4913ae4127f06727a5e83..e8f0daf0213fa12eb665ab46f0ff8f15aa52d3b5 100644 --- a/en/application-dev/reference/apis-audio-kit/native__audio__device__base_8h.md +++ b/en/application-dev/reference/apis-audio-kit/native__audio__device__base_8h.md @@ -50,12 +50,12 @@ The **native_audio_device_base.h** file declares the types of audio device param | Name| Description| | -------- | -------- | -| [OH_AudioCommon_Result](_o_h_audio.md#oh_audiocommon_result) [OH_AudioDeviceDescriptor_GetDeviceRole](_o_h_audio.md#oh_audiodevicedescriptor_getdevicerole) ([OH_AudioDeviceDescriptor](_o_h_audio.md#oh_audiodevicedescriptor) \*audioDeviceDescriptor, [OH_AudioDevice_Role](_o_h_audio.md#oh_audiodevice_role) \*deviceRole) | Obtains the device role based on an audio device descriptor.| -| [OH_AudioCommon_Result](_o_h_audio.md#oh_audiocommon_result) [OH_AudioDeviceDescriptor_GetDeviceType](_o_h_audio.md#oh_audiodevicedescriptor_getdevicetype) ([OH_AudioDeviceDescriptor](_o_h_audio.md#oh_audiodevicedescriptor) \*audioDeviceDescriptor, [OH_AudioDevice_Type](_o_h_audio.md#oh_audiodevice_type) \*deviceType) | Obtains the device type based on an audio device descriptor.| -| [OH_AudioCommon_Result](_o_h_audio.md#oh_audiocommon_result) [OH_AudioDeviceDescriptor_GetDeviceId](_o_h_audio.md#oh_audiodevicedescriptor_getdeviceid) ([OH_AudioDeviceDescriptor](_o_h_audio.md#oh_audiodevicedescriptor) \*audioDeviceDescriptor, uint32_t \*id) | Obtains the device ID based on an audio device descriptor.| -| [OH_AudioCommon_Result](_o_h_audio.md#oh_audiocommon_result) [OH_AudioDeviceDescriptor_GetDeviceName](_o_h_audio.md#oh_audiodevicedescriptor_getdevicename) ([OH_AudioDeviceDescriptor](_o_h_audio.md#oh_audiodevicedescriptor) \*audioDeviceDescriptor, char \*\*name) | Obtains the device name based on an audio device descriptor.| -| [OH_AudioCommon_Result](_o_h_audio.md#oh_audiocommon_result) [OH_AudioDeviceDescriptor_GetDeviceAddress](_o_h_audio.md#oh_audiodevicedescriptor_getdeviceaddress) ([OH_AudioDeviceDescriptor](_o_h_audio.md#oh_audiodevicedescriptor) \*audioDeviceDescriptor, char \*\*address) | Obtains the device address based on an audio device descriptor.| -| [OH_AudioCommon_Result](_o_h_audio.md#oh_audiocommon_result) [OH_AudioDeviceDescriptor_GetDeviceSampleRates](_o_h_audio.md#oh_audiodevicedescriptor_getdevicesamplerates) ([OH_AudioDeviceDescriptor](_o_h_audio.md#oh_audiodevicedescriptor) \*audioDeviceDescriptor, uint32_t \*\*sampleRates, uint32_t \*size) | Obtains the sample rates based on an audio device descriptor.| -| [OH_AudioCommon_Result](_o_h_audio.md#oh_audiocommon_result) [OH_AudioDeviceDescriptor_GetDeviceChannelCounts](_o_h_audio.md#oh_audiodevicedescriptor_getdevicechannelcounts) ([OH_AudioDeviceDescriptor](_o_h_audio.md#oh_audiodevicedescriptor) \*audioDeviceDescriptor, uint32_t \*\*channelCounts, uint32_t \*size) | Obtains an array that holds the number of device channels based on an audio device descriptor.| -| [OH_AudioCommon_Result](_o_h_audio.md#oh_audiocommon_result) [OH_AudioDeviceDescriptor_GetDeviceDisplayName](_o_h_audio.md#oh_audiodevicedescriptor_getdevicedisplayname) ([OH_AudioDeviceDescriptor](_o_h_audio.md#oh_audiodevicedescriptor) \*audioDeviceDescriptor, char \*\*displayName) | Obtains the device display name based on an audio device descriptor.| -| [OH_AudioCommon_Result](_o_h_audio.md#oh_audiocommon_result) [OH_AudioDeviceDescriptor_GetDeviceEncodingTypes](_o_h_audio.md#oh_audiodevicedescriptor_getdeviceencodingtypes) ([OH_AudioDeviceDescriptor](_o_h_audio.md#oh_audiodevicedescriptor) \*audioDeviceDescriptor, [OH_AudioStream_EncodingType](_o_h_audio.md#oh_audiostream_encodingtype) \*\*encodingTypes, uint32_t \*size) | Obtains the device encoding types based on an audio device descriptor.| +| [OH_AudioCommon_Result](_o_h_audio.md#oh_audiocommon_result) [OH_AudioDeviceDescriptor_GetDeviceRole](_o_h_audio.md#oh_audiodevicedescriptor_getdevicerole)([OH_AudioDeviceDescriptor](_o_h_audio.md#oh_audiodevicedescriptor) \*audioDeviceDescriptor, [OH_AudioDevice_Role](_o_h_audio.md#oh_audiodevice_role) \*deviceRole) | Obtains the device role based on an audio device descriptor.| +| [OH_AudioCommon_Result](_o_h_audio.md#oh_audiocommon_result) [OH_AudioDeviceDescriptor_GetDeviceType](_o_h_audio.md#oh_audiodevicedescriptor_getdevicetype)([OH_AudioDeviceDescriptor](_o_h_audio.md#oh_audiodevicedescriptor) \*audioDeviceDescriptor, [OH_AudioDevice_Type](_o_h_audio.md#oh_audiodevice_type) \*deviceType) | Obtains the device type based on an audio device descriptor.| +| [OH_AudioCommon_Result](_o_h_audio.md#oh_audiocommon_result) [OH_AudioDeviceDescriptor_GetDeviceId](_o_h_audio.md#oh_audiodevicedescriptor_getdeviceid)([OH_AudioDeviceDescriptor](_o_h_audio.md#oh_audiodevicedescriptor) \*audioDeviceDescriptor, uint32_t \*id) | Obtains the device ID based on an audio device descriptor.| +| [OH_AudioCommon_Result](_o_h_audio.md#oh_audiocommon_result) [OH_AudioDeviceDescriptor_GetDeviceName](_o_h_audio.md#oh_audiodevicedescriptor_getdevicename)([OH_AudioDeviceDescriptor](_o_h_audio.md#oh_audiodevicedescriptor) \*audioDeviceDescriptor, char \*\*name) | Obtains the device name based on an audio device descriptor.| +| [OH_AudioCommon_Result](_o_h_audio.md#oh_audiocommon_result) [OH_AudioDeviceDescriptor_GetDeviceAddress](_o_h_audio.md#oh_audiodevicedescriptor_getdeviceaddress)([OH_AudioDeviceDescriptor](_o_h_audio.md#oh_audiodevicedescriptor) \*audioDeviceDescriptor, char \*\*address) | Obtains the device address based on an audio device descriptor.| +| [OH_AudioCommon_Result](_o_h_audio.md#oh_audiocommon_result) [OH_AudioDeviceDescriptor_GetDeviceSampleRates](_o_h_audio.md#oh_audiodevicedescriptor_getdevicesamplerates)([OH_AudioDeviceDescriptor](_o_h_audio.md#oh_audiodevicedescriptor) \*audioDeviceDescriptor, uint32_t \*\*sampleRates, uint32_t \*size) | Obtains the sample rates based on an audio device descriptor.| +| [OH_AudioCommon_Result](_o_h_audio.md#oh_audiocommon_result) [OH_AudioDeviceDescriptor_GetDeviceChannelCounts](_o_h_audio.md#oh_audiodevicedescriptor_getdevicechannelcounts)([OH_AudioDeviceDescriptor](_o_h_audio.md#oh_audiodevicedescriptor) \*audioDeviceDescriptor, uint32_t \*\*channelCounts, uint32_t \*size) | Obtains an array that holds the number of device channels based on an audio device descriptor.| +| [OH_AudioCommon_Result](_o_h_audio.md#oh_audiocommon_result) [OH_AudioDeviceDescriptor_GetDeviceDisplayName](_o_h_audio.md#oh_audiodevicedescriptor_getdevicedisplayname)([OH_AudioDeviceDescriptor](_o_h_audio.md#oh_audiodevicedescriptor) \*audioDeviceDescriptor, char \*\*displayName) | Obtains the device display name based on an audio device descriptor.| +| [OH_AudioCommon_Result](_o_h_audio.md#oh_audiocommon_result) [OH_AudioDeviceDescriptor_GetDeviceEncodingTypes](_o_h_audio.md#oh_audiodevicedescriptor_getdeviceencodingtypes)([OH_AudioDeviceDescriptor](_o_h_audio.md#oh_audiodevicedescriptor) \*audioDeviceDescriptor, [OH_AudioStream_EncodingType](_o_h_audio.md#oh_audiostream_encodingtype) \*\*encodingTypes, uint32_t \*size) | Obtains the device encoding types based on an audio device descriptor.| diff --git a/en/application-dev/reference/apis-audio-kit/native__audio__manager_8h.md b/en/application-dev/reference/apis-audio-kit/native__audio__manager_8h.md index adcec0e4859e8339e21c4616a400244476396976..9c22a37039a38ca333d22e70b67e01e2d680ca14 100644 --- a/en/application-dev/reference/apis-audio-kit/native__audio__manager_8h.md +++ b/en/application-dev/reference/apis-audio-kit/native__audio__manager_8h.md @@ -30,5 +30,5 @@ The **native_audio_manager.h** file declares the functions related to an audio m | Name| Description| | -------- | -------- | -| [OH_AudioCommon_Result](_o_h_audio.md#oh_audiocommon_result) [OH_GetAudioManager](_o_h_audio.md#oh_getaudiomanager) ([OH_AudioManager](_o_h_audio.md#oh_audiomanager) \*\*audioManager) | Obtains an **OH_AudioManager** instance. | -| [OH_AudioCommon_Result](_o_h_audio.md#oh_audiocommon_result) [OH_GetAudioScene](_o_h_audio.md#oh_getaudioscene) ([OH_AudioManager](_o_h_audio.md#oh_audiomanager) \*manager, [OH_AudioScene](_o_h_audio.md#oh_audioscene) \*scene) | Obtains the audio scene. | +| [OH_AudioCommon_Result](_o_h_audio.md#oh_audiocommon_result) [OH_GetAudioManager](_o_h_audio.md#oh_getaudiomanager)([OH_AudioManager](_o_h_audio.md#oh_audiomanager) \*\*audioManager) | Obtains an **OH_AudioManager** instance. | +| [OH_AudioCommon_Result](_o_h_audio.md#oh_audiocommon_result) [OH_GetAudioScene](_o_h_audio.md#oh_getaudioscene)([OH_AudioManager](_o_h_audio.md#oh_audiomanager) \*manager, [OH_AudioScene](_o_h_audio.md#oh_audioscene) \*scene) | Obtains the audio scene. | diff --git a/en/application-dev/reference/apis-audio-kit/native__audio__routing__manager_8h.md b/en/application-dev/reference/apis-audio-kit/native__audio__routing__manager_8h.md index aa7434c2c395672c998b11229062e855ea5ce6dd..daa433f3c378e42966efcc818d5a7c5a13f3006f 100644 --- a/en/application-dev/reference/apis-audio-kit/native__audio__routing__manager_8h.md +++ b/en/application-dev/reference/apis-audio-kit/native__audio__routing__manager_8h.md @@ -26,21 +26,21 @@ You can use the functions to create an audio routing manager, register and dereg | Name| Description| | -------- | -------- | | typedef struct [OH_AudioRoutingManager](_o_h_audio.md#oh_audioroutingmanager) [OH_AudioRoutingManager](_o_h_audio.md#oh_audioroutingmanager) | Defines the struct of an audio routing manager, which is used for routing and device-related functions. | -| typedef int32_t(\* [OH_AudioRoutingManager_OnDeviceChangedCallback](_o_h_audio.md#oh_audioroutingmanager_ondevicechangedcallback)) ([OH_AudioDevice_ChangeType](_o_h_audio.md#oh_audiodevice_changetype) type, [OH_AudioDeviceDescriptorArray](_o_h___audio_device_descriptor_array.md) \*audioDeviceDescriptorArray) | Defines a pointer to the callback function that returns the changed audio device descriptor (possibly multiple descriptors). | -| typedef void(\* [OH_AudioRoutingManager_OnDeviceBlockStatusCallback](_o_h_audio.md#oh_audioroutingmanager_ondeviceblockstatuscallback)) ([OH_AudioDeviceDescriptorArray](_o_h___audio_device_descriptor_array.md) \*audioDeviceDescriptorArray, [OH_AudioDevice_BlockStatus](_o_h_audio.md#oh_audiodevice_blockstatus) status, void \*userData) | Defines a pointer to the callback function that returns the blocked status of one or more audio devices. | +| typedef int32_t (\*[OH_AudioRoutingManager_OnDeviceChangedCallback](_o_h_audio.md#oh_audioroutingmanager_ondevicechangedcallback))([OH_AudioDevice_ChangeType](_o_h_audio.md#oh_audiodevice_changetype) type, [OH_AudioDeviceDescriptorArray](_o_h___audio_device_descriptor_array.md) \*audioDeviceDescriptorArray) | Defines a pointer to the callback function that returns the changed audio device descriptor (possibly multiple descriptors). | +| typedef void (\*[OH_AudioRoutingManager_OnDeviceBlockStatusCallback](_o_h_audio.md#oh_audioroutingmanager_ondeviceblockstatuscallback))([OH_AudioDeviceDescriptorArray](_o_h___audio_device_descriptor_array.md) \*audioDeviceDescriptorArray, [OH_AudioDevice_BlockStatus](_o_h_audio.md#oh_audiodevice_blockstatus) status, void \*userData) | Defines a pointer to the callback function that returns the blocked status of one or more audio devices. | ### Functions | Name| Description| | -------- | -------- | -| [OH_AudioCommon_Result](_o_h_audio.md#oh_audiocommon_result) [OH_AudioManager_GetAudioRoutingManager](_o_h_audio.md#oh_audiomanager_getaudioroutingmanager) ([OH_AudioRoutingManager](_o_h_audio.md#oh_audioroutingmanager) \*\*audioRoutingManager) | Obtains the handle to an audio routing manager. The handle should be set as the first parameter in the routing-related functions. | -| [OH_AudioCommon_Result](_o_h_audio.md#oh_audiocommon_result) [OH_AudioRoutingManager_GetDevices](_o_h_audio.md#oh_audioroutingmanager_getdevices) ([OH_AudioRoutingManager](_o_h_audio.md#oh_audioroutingmanager) \*audioRoutingManager, [OH_AudioDevice_Flag](_o_h_audio.md#oh_audiodevice_flag) deviceFlag, [OH_AudioDeviceDescriptorArray](_o_h___audio_device_descriptor_array.md) \*\*audioDeviceDescriptorArray) | Obtains available devices based on the device flag. | -| [OH_AudioCommon_Result](_o_h_audio.md#oh_audiocommon_result) [OH_AudioRoutingManager_GetAvailableDevices](_o_h_audio.md#oh_audioroutingmanager_getavailabledevices) ([OH_AudioRoutingManager](_o_h_audio.md#oh_audioroutingmanager) \*audioRoutingManager, [OH_AudioDevice_Usage](_o_h_audio.md#oh_audiodevice_usage) deviceUsage, [OH_AudioDeviceDescriptorArray](_o_h___audio_device_descriptor_array.md) \*\*audioDeviceDescriptorArray) | Obtains the available audio devices. | -| [OH_AudioCommon_Result](_o_h_audio.md#oh_audiocommon_result) [OH_AudioRoutingManager_GetPreferredOutputDevice](_o_h_audio.md#oh_audioroutingmanager_getpreferredoutputdevice) ([OH_AudioRoutingManager](_o_h_audio.md#oh_audioroutingmanager) \*audioRoutingManager, [OH_AudioStream_Usage](_o_h_audio.md#oh_audiostream_usage) streamUsage, [OH_AudioDeviceDescriptorArray](_o_h___audio_device_descriptor_array.md) \*\*audioDeviceDescriptorArray) | Obtains the output device with the highest priority based on the usage scenario of an audio output stream. | -| [OH_AudioCommon_Result](_o_h_audio.md#oh_audiocommon_result) [OH_AudioRoutingManager_GetPreferredInputDevice](_o_h_audio.md#oh_audioroutingmanager_getpreferredinputdevice) ([OH_AudioRoutingManager](_o_h_audio.md#oh_audioroutingmanager) \*audioRoutingManager, [OH_AudioStream_SourceType](_o_h_audio.md#oh_audiostream_sourcetype) sourceType, [OH_AudioDeviceDescriptorArray](_o_h___audio_device_descriptor_array.md) \*\*audioDeviceDescriptorArray) | Obtains the input device with the highest priority based on the usage scenario of an audio input stream. | -| [OH_AudioCommon_Result](_o_h_audio.md#oh_audiocommon_result) [OH_AudioRoutingManager_RegisterDeviceChangeCallback](_o_h_audio.md#oh_audioroutingmanager_registerdevicechangecallback) ([OH_AudioRoutingManager](_o_h_audio.md#oh_audioroutingmanager) \*audioRoutingManager, [OH_AudioDevice_Flag](_o_h_audio.md#oh_audiodevice_flag) deviceFlag, [OH_AudioRoutingManager_OnDeviceChangedCallback](_o_h_audio.md#oh_audioroutingmanager_ondevicechangedcallback) callback) | Registers a callback to listen for device changes of an audio routing manager. | -| [OH_AudioCommon_Result](_o_h_audio.md#oh_audiocommon_result) [OH_AudioRoutingManager_UnregisterDeviceChangeCallback](_o_h_audio.md#oh_audioroutingmanager_unregisterdevicechangecallback) ([OH_AudioRoutingManager](_o_h_audio.md#oh_audioroutingmanager) \*audioRoutingManager, [OH_AudioRoutingManager_OnDeviceChangedCallback](_o_h_audio.md#oh_audioroutingmanager_ondevicechangedcallback) callback) | Unregisters the callback used to listen for device changes of an audio routing manager. | -| [OH_AudioCommon_Result](_o_h_audio.md#oh_audiocommon_result) [OH_AudioRoutingManager_ReleaseDevices](_o_h_audio.md#oh_audioroutingmanager_releasedevices) ([OH_AudioRoutingManager](_o_h_audio.md#oh_audioroutingmanager) \*audioRoutingManager, [OH_AudioDeviceDescriptorArray](_o_h___audio_device_descriptor_array.md) \*audioDeviceDescriptorArray) | Releases audio devices available for an audio routing manager. | -| [OH_AudioCommon_Result](_o_h_audio.md#oh_audiocommon_result) [OH_AudioRoutingManager_IsMicBlockDetectionSupported](_o_h_audio.md#oh_audioroutingmanager_ismicblockdetectionsupported) ([OH_AudioRoutingManager](_o_h_audio.md#oh_audioroutingmanager) \*audioRoutingManager, bool \*supported) | Checks whether the current device supports microphone blocking detection. | -| [OH_AudioCommon_Result](_o_h_audio.md#oh_audiocommon_result) [OH_AudioRoutingManager_SetMicBlockStatusCallback](_o_h_audio.md#oh_audioroutingmanager_setmicblockstatuscallback) ([OH_AudioRoutingManager](_o_h_audio.md#oh_audioroutingmanager) \*audioRoutingManager, [OH_AudioRoutingManager_OnDeviceBlockStatusCallback](_o_h_audio.md#oh_audioroutingmanager_ondeviceblockstatuscallback) callback, void \*userData) | Sets a callback function to be invoked when the microphone's blocked status is changed. | +| [OH_AudioCommon_Result](_o_h_audio.md#oh_audiocommon_result) [OH_AudioManager_GetAudioRoutingManager](_o_h_audio.md#oh_audiomanager_getaudioroutingmanager)([OH_AudioRoutingManager](_o_h_audio.md#oh_audioroutingmanager) \*\*audioRoutingManager) | Obtains the handle to an audio routing manager. The handle should be set as the first parameter in the routing-related functions. | +| [OH_AudioCommon_Result](_o_h_audio.md#oh_audiocommon_result) [OH_AudioRoutingManager_GetDevices](_o_h_audio.md#oh_audioroutingmanager_getdevices)([OH_AudioRoutingManager](_o_h_audio.md#oh_audioroutingmanager) \*audioRoutingManager, [OH_AudioDevice_Flag](_o_h_audio.md#oh_audiodevice_flag) deviceFlag, [OH_AudioDeviceDescriptorArray](_o_h___audio_device_descriptor_array.md) \*\*audioDeviceDescriptorArray) | Obtains available devices based on the device flag. | +| [OH_AudioCommon_Result](_o_h_audio.md#oh_audiocommon_result) [OH_AudioRoutingManager_GetAvailableDevices](_o_h_audio.md#oh_audioroutingmanager_getavailabledevices)([OH_AudioRoutingManager](_o_h_audio.md#oh_audioroutingmanager) \*audioRoutingManager, [OH_AudioDevice_Usage](_o_h_audio.md#oh_audiodevice_usage) deviceUsage, [OH_AudioDeviceDescriptorArray](_o_h___audio_device_descriptor_array.md) \*\*audioDeviceDescriptorArray) | Obtains the available audio devices. | +| [OH_AudioCommon_Result](_o_h_audio.md#oh_audiocommon_result) [OH_AudioRoutingManager_GetPreferredOutputDevice](_o_h_audio.md#oh_audioroutingmanager_getpreferredoutputdevice)([OH_AudioRoutingManager](_o_h_audio.md#oh_audioroutingmanager) \*audioRoutingManager, [OH_AudioStream_Usage](_o_h_audio.md#oh_audiostream_usage) streamUsage, [OH_AudioDeviceDescriptorArray](_o_h___audio_device_descriptor_array.md) \*\*audioDeviceDescriptorArray) | Obtains the output device with the highest priority based on the usage scenario of an audio output stream. | +| [OH_AudioCommon_Result](_o_h_audio.md#oh_audiocommon_result) [OH_AudioRoutingManager_GetPreferredInputDevice](_o_h_audio.md#oh_audioroutingmanager_getpreferredinputdevice)([OH_AudioRoutingManager](_o_h_audio.md#oh_audioroutingmanager) \*audioRoutingManager, [OH_AudioStream_SourceType](_o_h_audio.md#oh_audiostream_sourcetype) sourceType, [OH_AudioDeviceDescriptorArray](_o_h___audio_device_descriptor_array.md) \*\*audioDeviceDescriptorArray) | Obtains the input device with the highest priority based on the usage scenario of an audio input stream. | +| [OH_AudioCommon_Result](_o_h_audio.md#oh_audiocommon_result) [OH_AudioRoutingManager_RegisterDeviceChangeCallback](_o_h_audio.md#oh_audioroutingmanager_registerdevicechangecallback)([OH_AudioRoutingManager](_o_h_audio.md#oh_audioroutingmanager) \*audioRoutingManager, [OH_AudioDevice_Flag](_o_h_audio.md#oh_audiodevice_flag) deviceFlag, [OH_AudioRoutingManager_OnDeviceChangedCallback](_o_h_audio.md#oh_audioroutingmanager_ondevicechangedcallback) callback) | Registers a callback to listen for device changes of an audio routing manager. | +| [OH_AudioCommon_Result](_o_h_audio.md#oh_audiocommon_result) [OH_AudioRoutingManager_UnregisterDeviceChangeCallback](_o_h_audio.md#oh_audioroutingmanager_unregisterdevicechangecallback)([OH_AudioRoutingManager](_o_h_audio.md#oh_audioroutingmanager) \*audioRoutingManager, [OH_AudioRoutingManager_OnDeviceChangedCallback](_o_h_audio.md#oh_audioroutingmanager_ondevicechangedcallback) callback) | Unregisters the callback used to listen for device changes of an audio routing manager. | +| [OH_AudioCommon_Result](_o_h_audio.md#oh_audiocommon_result) [OH_AudioRoutingManager_ReleaseDevices](_o_h_audio.md#oh_audioroutingmanager_releasedevices)([OH_AudioRoutingManager](_o_h_audio.md#oh_audioroutingmanager) \*audioRoutingManager, [OH_AudioDeviceDescriptorArray](_o_h___audio_device_descriptor_array.md) \*audioDeviceDescriptorArray) | Releases audio devices available for an audio routing manager. | +| [OH_AudioCommon_Result](_o_h_audio.md#oh_audiocommon_result) [OH_AudioRoutingManager_IsMicBlockDetectionSupported](_o_h_audio.md#oh_audioroutingmanager_ismicblockdetectionsupported)([OH_AudioRoutingManager](_o_h_audio.md#oh_audioroutingmanager) \*audioRoutingManager, bool \*supported) | Checks whether the current device supports microphone blocking detection. | +| [OH_AudioCommon_Result](_o_h_audio.md#oh_audiocommon_result) [OH_AudioRoutingManager_SetMicBlockStatusCallback](_o_h_audio.md#oh_audioroutingmanager_setmicblockstatuscallback)([OH_AudioRoutingManager](_o_h_audio.md#oh_audioroutingmanager) \*audioRoutingManager, [OH_AudioRoutingManager_OnDeviceBlockStatusCallback](_o_h_audio.md#oh_audioroutingmanager_ondeviceblockstatuscallback) callback, void \*userData) | Sets a callback function to be invoked when the microphone's blocked status is changed. | diff --git a/en/application-dev/reference/apis-audio-kit/native__audio__session__manager_8h.md b/en/application-dev/reference/apis-audio-kit/native__audio__session__manager_8h.md index d7a851eaee764425043973ac95c362b676d6f094..e86c7d8b8ba65db06ceca25a2831b516917fffa4 100644 --- a/en/application-dev/reference/apis-audio-kit/native__audio__session__manager_8h.md +++ b/en/application-dev/reference/apis-audio-kit/native__audio__session__manager_8h.md @@ -36,7 +36,7 @@ You can call the functions to create an audio session manager, activates or deac | typedef struct [OH_AudioSessionManager](_o_h_audio.md#oh_audiosessionmanager) [OH_AudioSessionManager](_o_h_audio.md#oh_audiosessionmanager) | Defines a struct for the audio session manager. | | typedef struct [OH_AudioSession_Strategy](_o_h___audio_session___strategy.md) [OH_AudioSession_Strategy](_o_h_audio.md#oh_audiosession_strategy) | Defines a struct for the audio session strategy. | | typedef struct [OH_AudioSession_DeactivatedEvent](_o_h___audio_session___deactivated_event.md) [OH_AudioSession_DeactivatedEvent](_o_h_audio.md#oh_audiosession_deactivatedevent) | Defines a struct for the event indicating that an audio session is deactivated. | -| typedef int32_t(\* [OH_AudioSession_DeactivatedCallback](_o_h_audio.md#oh_audiosession_deactivatedcallback))([OH_AudioSession_DeactivatedEvent](_o_h___audio_session___deactivated_event.md) event) | Defines a function pointer to the callback function used to listen for audio session deactivation events. | +| typedef int32_t (\*[OH_AudioSession_DeactivatedCallback](_o_h_audio.md#oh_audiosession_deactivatedcallback))([OH_AudioSession_DeactivatedEvent](_o_h___audio_session___deactivated_event.md) event) | Defines a function pointer to the callback function used to listen for audio session deactivation events. | ### Enums diff --git a/en/application-dev/reference/apis-audio-kit/native__audiocapturer_8h.md b/en/application-dev/reference/apis-audio-kit/native__audiocapturer_8h.md index 31d0a45958469f760efd729aea66950034181c9e..62a6191c0e8a81b93cefe7f53ac0de1798718697 100644 --- a/en/application-dev/reference/apis-audio-kit/native__audiocapturer_8h.md +++ b/en/application-dev/reference/apis-audio-kit/native__audiocapturer_8h.md @@ -21,7 +21,7 @@ The **native_audiocapturer.h** declares the functions related to an audio captur ### Functions -| Name | Description | +| Name | Description| |--------------| -------- | | [OH_AudioStream_Result](_o_h_audio.md#oh_audiostream_result) [OH_AudioCapturer_Release](_o_h_audio.md#oh_audiocapturer_release)([OH_AudioCapturer](_o_h_audio.md#oh_audiocapturer) \*capturer) | Releases an audio capturer. | | [OH_AudioStream_Result](_o_h_audio.md#oh_audiostream_result) [OH_AudioCapturer_Start](_o_h_audio.md#oh_audiocapturer_start)([OH_AudioCapturer](_o_h_audio.md#oh_audiocapturer) \*capturer) | Starts an audio capturer. | @@ -39,4 +39,4 @@ The **native_audiocapturer.h** declares the functions related to an audio captur | [OH_AudioStream_Result](_o_h_audio.md#oh_audiostream_result) [OH_AudioCapturer_GetFrameSizeInCallback](_o_h_audio.md#oh_audiocapturer_getframesizeincallback)([OH_AudioCapturer](_o_h_audio.md#oh_audiocapturer) \*capturer, int32_t \*frameSize) | Obtains the frame size in the callback. | | [OH_AudioStream_Result](_o_h_audio.md#oh_audiostream_result) [OH_AudioCapturer_GetTimestamp](_o_h_audio.md#oh_audiocapturer_gettimestamp)([OH_AudioCapturer](_o_h_audio.md#oh_audiocapturer) \*capturer, clockid_t clockId, int64_t \*framePosition, int64_t \*timestamp) | Obtains the timestamp and position information of an input audio stream. | | [OH_AudioStream_Result](_o_h_audio.md#oh_audiostream_result) [OH_AudioCapturer_GetFramesRead](_o_h_audio.md#oh_audiocapturer_getframesread)([OH_AudioCapturer](_o_h_audio.md#oh_audiocapturer) \*capturer, int64_t \*frames) | Obtains the number of frames that have been read since the stream was created. | -| [OH_AudioStream_Result](_o_h_audio.md#oh_audiostream_result) [OH_AudioCapturer_GetOverflowCount](_o_h_audio.md#oh_audiocapturer_getoverflowcount) ([OH_AudioCapturer](_o_h_audio.md#oh_audiocapturer) \*capturer, uint32_t \*count) | Obtains the number of overloaded audio streams of an audio capturer. | +| [OH_AudioStream_Result](_o_h_audio.md#oh_audiostream_result) [OH_AudioCapturer_GetOverflowCount](_o_h_audio.md#oh_audiocapturer_getoverflowcount)([OH_AudioCapturer](_o_h_audio.md#oh_audiocapturer) \*capturer, uint32_t \*count) | Obtains the number of overloaded audio streams of an audio capturer. | diff --git a/en/application-dev/reference/apis-audio-kit/native__audiostream__base_8h.md b/en/application-dev/reference/apis-audio-kit/native__audiostream__base_8h.md index 466db7312a94eb919069562d924eee80582dfa24..feeb08ec03847f5f2d80b5a88805d9b1e0f482df 100644 --- a/en/application-dev/reference/apis-audio-kit/native__audiostream__base_8h.md +++ b/en/application-dev/reference/apis-audio-kit/native__audiostream__base_8h.md @@ -36,9 +36,9 @@ The **native_audiostream_base.h** file declares the basic data structure of **OH | typedef struct OH_AudioCapturerStruct [OH_AudioCapturer](_o_h_audio.md#oh_audiocapturer) | Defines an audio capturer. | | typedef struct [OH_AudioRenderer_Callbacks_Struct](_o_h___audio_renderer___callbacks___struct.md) [OH_AudioRenderer_Callbacks](_o_h_audio.md#oh_audiorenderer_callbacks) | Defines a pointer to the callback functions related to an audio renderer. | | typedef struct [OH_AudioCapturer_Callbacks_Struct](_o_h___audio_capturer___callbacks___struct.md) [OH_AudioCapturer_Callbacks](_o_h_audio.md#oh_audiocapturer_callbacks) | Defines a pointer to the callback functions related to an audio capturer. | -| typedef void(\* [OH_AudioRenderer_OutputDeviceChangeCallback](_o_h_audio.md#oh_audiorenderer_outputdevicechangecallback))([OH_AudioRenderer](_o_h_audio.md#oh_audiorenderer) \*renderer, void \*userData, [OH_AudioStream_DeviceChangeReason](_o_h_audio.md#oh_audiostream_devicechangereason) reason) | Defines a pointer to the callback invoked when the audio stream device changes. | -| typedef void(\* [OH_AudioRenderer_OnMarkReachedCallback](_o_h_audio.md#oh_audiorenderer_onmarkreachedcallback))([OH_AudioRenderer](_o_h_audio.md#oh_audiorenderer) \*renderer, uint32_t samplePos, void \*userData) | Defines a pointer to the callback invoked when the mark position is reached. | -| typedef int32_t(\* [OH_AudioRenderer_WriteDataWithMetadataCallback](_o_h_audio.md#oh_audiorenderer_writedatawithmetadatacallback))([OH_AudioRenderer](_o_h_audio.md#oh_audiorenderer) \*renderer, void \*userData, void \*audioData, int32_t audioDataSize, void \*metadata, int32_t metadataSize) | Defines a function pointer to the callback function used to write audio data and metadata. | +| typedef void (\*[OH_AudioRenderer_OutputDeviceChangeCallback](_o_h_audio.md#oh_audiorenderer_outputdevicechangecallback))([OH_AudioRenderer](_o_h_audio.md#oh_audiorenderer) \*renderer, void \*userData, [OH_AudioStream_DeviceChangeReason](_o_h_audio.md#oh_audiostream_devicechangereason) reason) | Defines a pointer to the callback invoked when the audio stream device changes. | +| typedef void (\*[OH_AudioRenderer_OnMarkReachedCallback](_o_h_audio.md#oh_audiorenderer_onmarkreachedcallback))([OH_AudioRenderer](_o_h_audio.md#oh_audiorenderer) \*renderer, uint32_t samplePos, void \*userData) | Defines a pointer to the callback invoked when the mark position is reached. | +| typedef int32_t (\*[OH_AudioRenderer_WriteDataWithMetadataCallback](_o_h_audio.md#oh_audiorenderer_writedatawithmetadatacallback))([OH_AudioRenderer](_o_h_audio.md#oh_audiorenderer) \*renderer, void \*userData, void \*audioData, int32_t audioDataSize, void \*metadata, int32_t metadataSize) | Defines a function pointer to the callback function used to write audio data and metadata. | | typedef [OH_AudioData_Callback_Result](_o_h_audio.md#oh_audiodata_callback_result)(\* [OH_AudioRenderer_OnWriteDataCallback](_o_h_audio.md#oh_audiorenderer_onwritedatacallback))([OH_AudioRenderer](_o_h_audio.md#oh_audiorenderer) \*renderer, void \*userData, void \*audioData, int32_t audioDataSize) | Defines a function pointer to the callback function used to write audio data. |