From 43e2896ed14b0d6f376e937a06220d743f9e505e Mon Sep 17 00:00:00 2001 From: Geevarghese V K Date: Thu, 3 Feb 2022 00:44:13 +0530 Subject: [PATCH] js api usage doc update based on new d.ts Signed-off-by: Geevarghese V K --- en/application-dev/media/audio-management.md | 27 +- en/application-dev/media/audio-renderer.md | 78 ++-- .../reference/apis/js-apis-audio.md | 387 +++++++++--------- 3 files changed, 242 insertions(+), 250 deletions(-) diff --git a/en/application-dev/media/audio-management.md b/en/application-dev/media/audio-management.md index 65bfb215f2..0f4dc93fa3 100644 --- a/en/application-dev/media/audio-management.md +++ b/en/application-dev/media/audio-management.md @@ -146,7 +146,13 @@ You use audio management APIs to set and obtain volume, and get information abou -

MEDIA = 1

+ +

VOICE_CALL = 0

+ +

Audio streams for voice calls

+ + +

MEDIA = 1

Audio streams for media purpose

@@ -154,6 +160,11 @@ You use audio management APIs to set and obtain volume, and get information abou

RINGTONE = 2

Audio streams for ring tones

+

VOICE_ASSISTANT = 9

+ +

Audio streams for voice assistant

+ + @@ -222,27 +233,27 @@ You use audio management APIs to set and obtain volume, and get information abou

Invalid device

-

SPEAKER = 1

+

SPEAKER = 2

Speaker

-

WIRED_HEADSET = 2

+

WIRED_HEADSET = 3

Wired headset

-

BLUETOOTH_SCO = 3

+

BLUETOOTH_SCO = 7

-

Bluetooth device using the synchronous connection oriented link (SCO)

+

Bluetooth device using the synchronous connection oriented (SCO) link

-

BLUETOOTH_A2DP = 4

+

BLUETOOTH_A2DP = 8

Bluetooth device using advanced audio distribution profile (A2DP)

-

MIC = 5

+

MIC = 15

Microphone

@@ -269,5 +280,3 @@ You use audio management APIs to set and obtain volume, and get information abou console.log(`Media getVolume ${value}`); }); ``` - - diff --git a/en/application-dev/media/audio-renderer.md b/en/application-dev/media/audio-renderer.md index 2132f81570..251b6bf822 100644 --- a/en/application-dev/media/audio-renderer.md +++ b/en/application-dev/media/audio-renderer.md @@ -3,8 +3,6 @@ --- ## ***Note***: 1. This document applies to JavaScript. - 2. Changes to the AudioRenderer interface have been proposed. - When the updated APIs have been integrated, the document will be revised, and apps must adapt to it. --- ## **Summary** This guide will show you how to use AudioRenderer to create an audio player app. @@ -24,11 +22,28 @@ Please see [**js-apis-audio.md**](https://gitee.com/openharmony/docs/blob/master ## **Usage** Here's an example of how to use AudioRenderer to play a raw audio file. -1. Use **createAudioRenderer** to create an AudioRenderer instance for the **AudioVolumeType**.\ +1. Use **createAudioRenderer** to create an AudioRenderer instance. Renderer parameters can be set in **audioRendererOptions**.\ This object can be used to play, control, and obtain the status of the playback, as well as receive callback notifications. ``` - const volType = audio.AudioVolumeType.MEDIA; // For music - const audioRenderer = audio.createAudioRenderer(volType); + var audioStreamInfo = { + samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100, + channels: audio.AudioChannel.CHANNEL_1, + sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE, + encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW + } + + var audioRendererInfo = { + content: audio.ContentType.CONTENT_TYPE_SPEECH, + usage: audio.StreamUsage.STREAM_USAGE_VOICE_COMMUNICATION, + rendererFlags: 1 + } + + var audioRendererOptions = { + streamInfo: audioStreamInfo, + rendererInfo: audioRendererInfo + } + + let audioRenderer = await audio.createAudioRenderer(audioRendererOptions); ``` 2. Subscribe to audio interruption events using the **on** API.\ @@ -118,27 +133,8 @@ Here's an example of how to use AudioRenderer to play a raw audio file. }); ``` -3. Prepare the renderer. Call **SetParams** on the instance. You need to set the renderer parameters based on the audio playback specification. - ``` - async function prepareRenderer() { - // file_example_WAV_2MG.wav - var audioParams = { - format: audio.AudioSampleFormat.SAMPLE_S16LE, - channels: audio.AudioChannel.STEREO, - samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_16000, - encoding: audio.AudioEncodingType.ENCODING_PCM, - }; - - let response = await audioRenderer.setParams(audioParams); - var state = audioRenderer.state; - if (state != audio.AudioState.STATE_PREPARED) { - console.info('Prepare renderer failed'); - return; - } - } - ``` 4. Call the **start()** function on the AudioRenderer instance to start/resume the playback task.\ - The renderer state will be STATE _RUNNING once the start is complete. You can then begin writing buffers. + The renderer state will be STATE_RUNNING once the start is complete. You can then begin writing buffers. ``` async function startRenderer() { var state = audioRenderer.state; @@ -148,13 +144,14 @@ Here's an example of how to use AudioRenderer to play a raw audio file. console.info('Renderer is not in a correct state to start'); return; } - var started = await audioRenderer.start(); - if (started) { - isPlay = true; + + await audioRenderer.start(); + + state = audioRenderer.state; + if (state == audio.AudioState.STATE_RUNNING) { console.info('Renderer started'); } else { console.error('Renderer start failed'); - return; } } @@ -212,8 +209,11 @@ Here's an example of how to use AudioRenderer to play a raw audio file. console.info('Renderer is not running'); return; } - var paused = await audioRenderer.pause(); - if (paused) { + + await audioRenderer.pause(); + + state = audioRenderer.state; + if (state == audio.AudioState.STATE_PAUSED) { console.info('Renderer paused'); } else { console.error('Renderer pause failed'); @@ -226,8 +226,11 @@ Here's an example of how to use AudioRenderer to play a raw audio file. console.info('Renderer is not running or paused'); return; } - var stopped = await audioRenderer.stop(); - if (stopped) { + + await audioRenderer.stop(); + + state = audioRenderer.state; + if (state == audio.AudioState.STATE_STOPPED) { console.info('Renderer stopped'); } else { console.error('Renderer stop failed'); @@ -243,8 +246,11 @@ Here's an example of how to use AudioRenderer to play a raw audio file. console.info('Resourced already released'); return; } - var released = await audioRenderer.release(); - if (released) { + + await audioRenderer.release(); + + state = audioRenderer.state; + if (state == STATE_RELEASED) { console.info('Renderer released'); } else { console.info('Renderer release failed'); @@ -257,7 +263,6 @@ Here's an example of how to use AudioRenderer to play a raw audio file. You should also keep in mind that an AudioRenderer is state-based. That is, the AudioRenderer has an internal state that you must always check when calling playback control APIs, because some operations are only acceptable while the renderer is in a given state.\ The system may throw an error/exception or generate other undefined behaviour if you perform an operation while in the improper state.\ -Before each necessary operation, the example code performs a state check. ## **Asynchronous Operations:** Most of the AudioRenderer calls are asynchronous. As a result, the UI thread will not be blocked.\ @@ -267,4 +272,3 @@ provides reference for both callback and promise. ## **Other APIs:** See [**js-apis-audio.md**](https://gitee.com/openharmony/docs/blob/master/en/application-dev/reference/apis/js-apis-audio.md) for more useful APIs like getAudioTime, drain, and getBufferSize. - diff --git a/en/application-dev/reference/apis/js-apis-audio.md b/en/application-dev/reference/apis/js-apis-audio.md index 98d16f8591..de50ce278c 100644 --- a/en/application-dev/reference/apis/js-apis-audio.md +++ b/en/application-dev/reference/apis/js-apis-audio.md @@ -2,15 +2,6 @@ This module provides the following functions: audio management, audio rendering and system sound management. - ---- -## ***Note:*** - - Changes to the AudioRenderer interface have been proposed. - When the updated APIs have been integrated, the document will be revised, and apps must adapt to it. - ---- - ## Modules to Import ``` @@ -71,8 +62,25 @@ Obtains an **AudioRenderer** instance. **Example** ``` -const volType = audio.AudioVolumeType.MEDIA; -const audioRenderer = audio.createAudioRenderer(volType); +var audioStreamInfo = { + samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100, + channels: audio.AudioChannel.CHANNEL_1, + sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE, + encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW +} + +var audioRendererInfo = { + content: audio.ContentType.CONTENT_TYPE_SPEECH, + usage: audio.StreamUsage.STREAM_USAGE_VOICE_COMMUNICATION, + rendererFlags: 1 +} + +var audioRendererOptions = { + streamInfo: audioStreamInfo, + rendererInfo: audioRendererInfo +} + +let audioRenderer = await audio.createAudioRenderer(audioRendererOptions); ``` @@ -112,7 +120,15 @@ Enumerates audio stream types. -

RINGTONE

+ +

VOICE_CALL

+ +

0

+ +

Audio stream for voice calls.

+ + +

RINGTONE

2

@@ -126,6 +142,13 @@ Enumerates audio stream types.

Audio stream for media purpose.

+

VOICE_ASSISTANT

+ +

9

+ +

Audio stream for voice assistant.

+ + @@ -221,35 +244,35 @@ Enumerates audio device types.

SPEAKER

-

1

+

2

Speaker.

WIRED_HEADSET

-

2

+

3

Wired headset.

BLUETOOTH_SCO

-

3

+

7

Bluetooth device using the synchronous connection oriented (SCO) link.

BLUETOOTH_A2DP

-

4

+

8

Bluetooth device using the advanced audio distribution profile (A2DP).

MIC

-

5

+

15

Microphone.

@@ -302,19 +325,24 @@ Enumerates the audio sample formats. | Name | Default Value | Description | | :------------ | :------------ | :------------------------------------ | | INVALID_WIDTH | -1 | Invalid format. | -| SAMPLE_U8 | 1 | Unsigned 8 bit integer. | -| SAMPLE_S16LE | 0 | Signed 16 bit integer, little endian. | -| SAMPLE_S24LE | 1 | Signed 24 bit integer, little endian. | -| SAMPLE_S32LE | 2 | Signed 32 bit integer, little endian. | - +| SAMPLE_U8 | 0 | Unsigned 8 bit integer. | +| SAMPLE_S16LE | 1 | Signed 16 bit integer, little endian. | +| SAMPLE_S24LE | 2 | Signed 24 bit integer, little endian. | +| SAMPLE_S32LE | 3 | Signed 32 bit integer, little endian. | ## AudioChannel8+ Enumerates the audio channels. | Name | Default Value | Description | | :----- | :------------ | :--------------- | -| MONO | 1 | Channel count 1. | -| STEREO | 2 | Channel count 2. | +| CHANNEL_1 | 0x1 << 0 | Channel count 1. | +| CHANNEL_2 | 0x1 << 1 | Channel count 2. | +| CHANNEL_3 | 0x1 << 2 | Channel count 3. | +| CHANNEL_4 | 0x1 << 3 | Channel count 4. | +| CHANNEL_5 | 0x1 << 4 | Channel count 5. | +| CHANNEL_6 | 0x1 << 5 | Channel count 6. | +| CHANNEL_7 | 0x1 << 6 | Channel count 7. | +| CHANNEL_8 | 0x1 << 7 | Channel count 8. | ## AudioSamplingRate8+ @@ -338,10 +366,10 @@ Enumerates the audio sampling rates. ## AudioEncodingType8+ Enumerates the audio encoding types. -| Name | Default Value | Description | -| :--------------- | :------------ | :---------- | -| ENCODING_PCM | 0 | PCM. | -| ENCODING_INVALID | 1 | Invalid. | +| Name | Default Value | Description | +| :-------------------- | :------------ | :---------------- | +| ENCODING_TYPE_INVALID | -1 | Invalid. | +| ENCODING_TYPE_RAW | 0 | PCM encoding. | ## ContentType8+ @@ -431,23 +459,17 @@ Enumerates the ringtone types. | RINGTONE_TYPE_DEFAULT | 0 | Default type. | | RINGTONE_TYPE_MULTISIM | 1 | Multi-SIM type. | - -## AudioParameters8+ -Describes audio parameters of playback files. +## AudioStreamInfo8+ +Describes audio stream information. **Parameters** -| Name | Type | Mandatory | Description | -| :----------- | :---------------- | :-------- | :-------------------------------------------- | -| format | AudioSampleFormat | Yes | Sample format of the audio file to be played. | -| channels | AudioChannel | Yes | Channel count of the audio file to be played. | -| samplingRate | AudioSamplingRate | Yes | Sample rate of the audio file to be played. | -| encoding | AudioEncodingType | Yes | Encoding type of the audio file to be played. | -| contentType | ContentType | Yes | Content type. | -| usage | StreamUsage | Yes | Stream usage. | -| deviceRole | DeviceRole | Yes | Device role. | -| deviceType | DeviceType | Yes | Device type. | - +| Name | Type | Mandatory | Description | +| :------------ | :-------------------- | :-------- | :-------------------- | +| samplingRate | AudioSamplingRate | Yes | Sampling rate. | +| channels | AudioChannel | Yes | Audio channels. | +| sampleFormat | AudioSampleFormat | Yes | Audio sample format. | +| encodingType | AudioEncodingType | Yes | Audio encoding type. | ## AudioRendererInfo8+ Describes audio renderer information. @@ -2461,20 +2483,18 @@ Defines the current render state. var state = audioRenderer.state; ``` +## audioRenderer.getRendererInfo -## audioRenderer.setParams - -setParams(params: AudioParameters, callback: AsyncCallback): void8+ +getRendererInfo(callback: AsyncCallback): void8+ -Sets audio parameters for rendering. This method uses an asynchronous callback to return the result. +Gets the renderer information provided while creating a renderer instance. This method uses an asynchronous callback to return the result. **Parameters** -| Name | Type | Mandatory | Description | -| :------- | :------------------- | :-------- | :-------------------------------------- | -| params | AudioParameters | Yes | Audio parameters of the file to be set. | -| callback | AsyncCallback | Yes | Callback used to return the result. | -| | | | | +| Name | Type | Mandatory | Description | +| :------- | :--------------------------------- | :-------- | :------------------------------------------------ | +| callback | AsyncCallback | Yes | Callback used to return the renderer information. | +| | | | | **Return value** @@ -2483,67 +2503,53 @@ None **Example** ``` -var audioParams = { - format: audio.AudioSampleFormat.SAMPLE_S16LE, - channels: audio.AudioChannel.STEREO, - samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_16000, - encoding: audio.AudioEncodingType.ENCODING_PCM, - }; - -audioRenderer.setParams(audioParams, (err)=>{ - if (err) { - console.error('Failed to set params. ${err.message}'); - return; - } - console.log('Callback invoked to indicate a successful params setting.'); +audioRenderer.getRendererInfo((err, rendererInfo)=>{ + console.log('Renderer GetRendererInfo:'); + console.log('Renderer content:' + rendererInfo.content); + console.log('Renderer usage:' + rendererInfo.usage); + console.log('Renderer flags:' + rendererInfo.rendererFlags); }) ``` -## audioRenderer.setParams +## audioRenderer.getRendererInfo -setParams(params: AudioParameters): Promise8+ +getParams(): Promise8+ -Sets audio parameters for rendering. This method uses a promise to return the result. +Gets the renderer information provided while creating a renderer instance. This method uses a promise to return the result. **Parameters** -| Name | Type | Mandatory | Description | -| :----- | :-------------- | :-------- | :-------------------------------------- | -| params | AudioParameters | Yes | Audio parameters of the file to be set. | +None **Return value** -| Type | Description | -| :------------- | :--------------------------------- | -| Promise | Promise used to return the result. | +| Type | Description | +| :---------------------------- | :----------------------------------------------- | +| Promise | Promise used to return the renderer information. | **Example** ``` -var audioParams = { - format: audio.AudioSampleFormat.SAMPLE_S16LE, - channels: audio.AudioChannel.STEREO, - samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_16000, - encoding: audio.AudioEncodingType.ENCODING_PCM, - }; - -await audioRenderer.setParams(audioParams); +let rendererInfo = await audioRenderer.getRendererInfo(); +console.log('Renderer GetRendererInfo:'); +console.log('Renderer content:' + rendererInfo.content); +console.log('Renderer usage:' + rendererInfo.usage); +console.log('Renderer flags:' + rendererInfo.rendererFlags); ``` +## audioRenderer.getStreamInfo -## audioRenderer.getParams - -getParams(callback: AsyncCallback): void8+ +getStreamInfo(callback: AsyncCallback): void8+ -Gets audio parameters of the renderer. This method uses an asynchronous callback to return the result. +Gets the renderer stream information. This method uses an asynchronous callback to return the result. **Parameters** -| Name | Type | Mandatory | Description | -| :------- | :------------------------------ | :-------- | :-------------------------------------------- | -| callback | AsyncCallback | Yes | Callback used to return the audio parameters. | -| | | | | +| Name | Type | Mandatory | Description | +| :------- | :--------------------------------- | :-------- | :---------------------------------------------- | +| callback | AsyncCallback | Yes | Callback used to return the stream information. | +| | | | | **Return value** @@ -2552,21 +2558,20 @@ None **Example** ``` -audioRenderer.getParams((err, audioParams)=>{ - console.log('Renderer GetParams:'); - console.log('Renderer format:' + audioParams.format); - console.log('Renderer samplingRate:' + audioParams.samplingRate); - console.log('Renderer channels:' + audioParams.channels); - console.log('Renderer encoding:' + audioParams.encoding); +audioRenderer.getStreamInfo((err, streamInfo)=>{ + console.log('Renderer GetStreamInfo:'); + console.log('Renderer sampling rate:' + streamInfo.samplingRate); + console.log('Renderer channel:' + streamInfo.AudioChannel); + console.log('Renderer format:' + streamInfo.AudioSampleFormat); + console.log('Renderer encoding type:' + streamInfo.AudioEncodingType); }) ``` +## audioRenderer.getStreamInfo -## audioRenderer.getParams +getStreamInfo(): Promise8+ -getParams(): Promise8+ - -Gets audio parameters of the renderer. This method uses a promise to return the result. +Gets the renderer stream information. This method uses a promise to return the result. **Parameters** @@ -2574,34 +2579,33 @@ None **Return value** -| Type | Description | -| :------------------------ | :------------------------------------------- | -| Promise | Promise used to return the audio parameters. | +| Type | Description | +| :---------------------------- | :----------------------------------------------- | +| Promise | Promise used to return the stream information. | **Example** ``` -let audioParams = await audioRenderer.getParams(); -console.log('Renderer GetParams:'); -console.log('Renderer format:' + audioParams.format); -console.log('Renderer samplingRate:' + audioParams.samplingRate); -console.log('Renderer channels:' + audioParams.channels); -console.log('Renderer encoding:' + audioParams.encoding); +let streamInfo = await audioRenderer.getStreamInfo(); +console.log('Renderer GetStreamInfo:'); +console.log('Renderer sampling rate:' + streamInfo.samplingRate); +console.log('Renderer channel:' + streamInfo.AudioChannel); +console.log('Renderer format:' + streamInfo.AudioSampleFormat); +console.log('Renderer encoding type:' + streamInfo.AudioEncodingType); ``` - ## audioRenderer.start -start(callback: AsyncCallback): void8+ +start(callback: AsyncCallback): void8+ Starts the renderer. This method uses an asynchronous callback to return the result. **Parameters** -| Name | Type | Mandatory | Description | -| :------- | :---------------------- | :-------- | :----------------------------------------------------------------------------- | -| callback | AsyncCallback | Yes | Returns true if the renderer is started successfully; returns false otherwise. | -| | | | | +| Name | Type | Mandatory | Description | +| :------- | :---------------------- | :-------- | :-------------------------------------- | +| callback | AsyncCallback | Yes | Callback used to return the result. | +| | | | | **Return value** @@ -2610,11 +2614,11 @@ None **Example** ``` -audioRenderer.start((err, started)=>{ - if (started) { - console.log('Renderer started.'); +audioRenderer.start((err)=>{ + if (err) { + console.error('Renderer start failed.'); } else { - console.error('Renderer start rejected.'); + console.info('Renderer start success.'); } }) ``` @@ -2622,7 +2626,7 @@ audioRenderer.start((err, started)=>{ ## audioRenderer.start -start(): Promise8+ +start(): Promise8+ Starts the renderer. This method uses a promise to return the result. @@ -2632,34 +2636,29 @@ None **Return value** -| Type | Description | -| :---------------- | :----------------------------------------------------------------------------- | -| Promise | Returns true if the renderer is started successfully; returns false otherwise. | +| Type | Description | +| :------------- | :--------------------------------- | +| Promise | Promise used to return the result. | **Example** ``` -var started = await audioRenderer.start(); -if (started) { - console.log('Renderer started'); -} else { - console.error('Renderer start rejected'); -} +await audioRenderer.start(); ``` ## audioRenderer.pause -pause(callback: AsyncCallback): void8+ +pause(callback: AsyncCallback): void8+ Pauses rendering. This method uses an asynchronous callback to return the result. **Parameters** -| Name | Type | Mandatory | Description | -| :------- | :---------------------- | :-------- | :---------------------------------------------------------------------------- | -| callback | AsyncCallback | Yes | Returns true if the renderer is paused successfully; returns false otherwise. | -| | | | | +| Name | Type | Mandatory | Description | +| :------- | :---------------------- | :-------- | :------------------------------------ | +| callback | AsyncCallback | Yes | Callback used to return the result. | +| | | | | **Return value** @@ -2668,11 +2667,11 @@ None **Example** ``` -audioRenderer.pause((err, paused)=>{ - if (paused) { - console.log('Renderer paused.'); +audioRenderer.pause((err)=>{ + if (err) { + console.error('Renderer pause failed'); } else { - console.error('Renderer pause failed'); + console.log('Renderer paused.'); } }) ``` @@ -2681,7 +2680,7 @@ audioRenderer.pause((err, paused)=>{ ## audioRenderer.pause -pause(): Promise8+ +pause(): Promise8+ Pauses rendering. This method uses a promise to return the result. @@ -2691,35 +2690,30 @@ None **Return value** -| Type | Description | -| :---------------- | :---------------------------------------------------------------------------- | -| Promise | Returns true if the renderer is paused successfully; returns false otherwise. | +| Type | Description | +| :------------- | :--------------------------------- | +| Promise | Promise used to return the result. | **Example** ``` -var paused = await audioRenderer.pause(); -if (paused) { - console.log('Renderer paused'); -} else { - console.error('Renderer pause failed'); -} +await audioRenderer.pause(); ``` ## audioRenderer.drain -drain(callback: AsyncCallback): void8+ +drain(callback: AsyncCallback): void8+ Drains the playback buffer. This method uses an asynchronous callback to return the result. **Parameters** -| Name | Type | Mandatory | Description | -| :------- | :---------------------- | :-------- | :--------------------------------------------------------------------------- | -| callback | AsyncCallback | Yes | Returns true if the buffer is drained successfully; returns false otherwise. | -| | | | | +| Name | Type | Mandatory | Description | +| :------- | :---------------------- | :-------- | :---------------------------------------| +| callback | AsyncCallback | Yes | Callback used to return the result. | +| | | | | **Return value** @@ -2728,11 +2722,11 @@ None **Example** ``` -audioRenderer.drain((err, drained)=>{ - if (drained) { - console.log('Renderer drained.'); +audioRenderer.drain((err)=>{ + if (err) { + console.error('Renderer drain failed'); } else { - console.error('Renderer drain failed'); + console.log('Renderer drained.'); } }) ``` @@ -2740,7 +2734,7 @@ audioRenderer.drain((err, drained)=>{ ## audioRenderer.drain -drain(): Promise8+ +drain(): Promise8+ Drains the playback buffer. This method uses a promise to return the result. @@ -2750,34 +2744,29 @@ None **Return value** -| Type | Description | -| :---------------- | :--------------------------------------------------------------------------- | -| Promise | Returns true if the buffer is drained successfully; returns false otherwise. | +| Type | Description | +| :------------- | :--------------------------------- | +| Promise | Promise used to return the result. | **Example** ``` -var drained = await audioRenderer.drain(); -if (drained) { - console.log('Renderer drained'); -} else { - console.error('Renderer drain failed'); -} +await audioRenderer.drain(); ``` ## audioRenderer.stop -stop(callback: AsyncCallback): void8+ +stop(callback: AsyncCallback): void8+ Stops rendering. This method uses an asynchronous callback to return the result. **Parameters** -| Name | Type | Mandatory | Description | -| :------- | :---------------------- | :-------- | :------------------------------------------------------------------------------ | -| callback | AsyncCallback | Yes | Returns true if the rendering is stopped successfully; returns false otherwise. | -| | | | | +| Name | Type | Mandatory | Description | +| :------- | :---------------------- | :-------- | :------------------------------------- | +| callback | AsyncCallback | Yes | Callback used to return the result. | +| | | | | **Return value** @@ -2786,11 +2775,11 @@ None **Example** ``` -audioRenderer.stop((err, stopped)=>{ - if (stopped) { - console.log('Renderer stopped.'); +audioRenderer.stop((err)=>{ + if (err) { + console.error('Renderer stop failed'); } else { - console.error('Renderer stop failed'); + console.log('Renderer stopped.'); } }) ``` @@ -2798,7 +2787,7 @@ audioRenderer.stop((err, stopped)=>{ ## audioRenderer.stop -stop(): Promise8+ +stop(): Promise8+ Stops rendering. This method uses a promise to return the result. @@ -2808,34 +2797,29 @@ None **Return value** -| Type | Description | -| :---------------- | :------------------------------------------------------------------------------ | -| Promise | Returns true if the rendering is stopped successfully; returns false otherwise. | +| Type | Description | +| :------------- | :--------------------------------- | +| Promise | Promise used to return the result. | **Example** ``` -var stopped = await audioRenderer.stop(); -if (stopped) { - console.log('Renderer stopped'); -} else { - console.error('Renderer stop failed'); -} +await audioRenderer.stop(); ``` ## audioRenderer.release -release(callback: AsyncCallback): void8+ +release(callback: AsyncCallback): void8+ Releases the renderer. This method uses an asynchronous callback to return the result. **Parameters** -| Name | Type | Mandatory | Description | -| :------- | :---------------------- | :-------- | :------------------------------------------------------------------------------ | -| callback | AsyncCallback | Yes | Returns true if the renderer is released successfully; returns false otherwise. | -| | | | | +| Name | Type | Mandatory | Description | +| :------- | :---------------------- | :-------- | :------------------------------------- | +| callback | AsyncCallback | Yes | Callback used to return the result. | +| | | | | **Return value** @@ -2844,11 +2828,11 @@ None **Example** ``` -audioRenderer.release((err, released)=>{ - if (released) { - console.log('Renderer released.'); +audioRenderer.release((err)=>{ + if (err) { + console.error('Renderer release failed'); } else { - console.error('Renderer release failed'); + console.log('Renderer released.'); } }) ``` @@ -2857,7 +2841,7 @@ audioRenderer.release((err, released)=>{ ## audioRenderer.release -release(): Promise8+ +release(): Promise8+ Releases the renderer. This method uses a promise to return the result. @@ -2867,19 +2851,14 @@ None **Return value** -| Type | Description | -| :---------------- | :------------------------------------------------------------------------------ | -| Promise | Returns true if the renderer is released successfully; returns false otherwise. | +| Type | Description | +| :------------- | :--------------------------------- | +| Promise | Promise used to return the result. | **Example** ``` -var released = await audioRenderer.release(); -if (released) { - console.log('Renderer released'); -} else { - console.error('Renderer release failed'); -} +await audioRenderer.release(); ``` -- GitLab