@@ -2129,10 +2129,6 @@ Subscribes to audio interruption events. When the application's audio is interru
Same as [on('audioInterrupt')](#onaudiointerrupt9), this API is used to listen for focus changes. However, this API is used in scenarios without audio streams (no **AudioRenderer** instance is created), such as frequency modulation (FM) and voice wakeup.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9.
| Promise<[AudioDeviceDescriptors](#audiodevicedescriptors)> | Promise used to return the information about the output device with the highest priority.|
**Error codes**
For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
| callback | Callback<[AudioDeviceDescriptors](#audiodevicedescriptors)\> | Yes | Callback used to return the information about the output device with the highest priority. |
**Error codes**
For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
@@ -4045,6 +4054,14 @@ Unsubscribes from the change of the output device with the highest priority.
| type | string | Yes | Event type. The value **'preferOutputDeviceChangeForRendererInfo'** means the event triggered when the output device with the highest priority changes.|
| callback | Callback<[AudioDeviceDescriptors](#audiodevicedescriptors)> | No | Callback used for unsubscription. |
**Error codes**
For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
Subscribes to audio interruption events. This API uses a callback to get interrupt events.
Subscribes to audio interruption events. This API uses a callback to obtain interrupt events.
Same as [on('interrupt')](#oninterruptdeprecated), this API has obtained the focus before **start**, **pause**, or **stop** of **AudioRenderer** is called. Therefore, you do not need to request the focus.
Same as [on('interrupt')](#oninterrupt), this API is used to listen for focus changes. The **AudioRenderer** instance proactively gains the focus when the **start** event occurs and releases the focus when the **pause** or **stop** event occurs. Therefore, you do not need to request to gain or release the focus.
| type | string | Yes | Event type. The value **'audioInterrupt'** means the audio interruption event, which is triggered when audio playback is interrupted. |
| callback | Callback<[InterruptEvent](#interruptevent9)> | Yes | Callback used to return the audio interruption event. |
| type | string | Yes | Event type. The value **'audioInterrupt'** means the audio interruption event, which is triggered when audio rendering is interrupted. |
| callback | Callback\<[InterruptEvent](#interruptevent9)\> | Yes | Callback used to return the audio interruption event. |
**Error codes**
...
...
@@ -5131,50 +5148,68 @@ For details about the error codes, see [Audio Error Codes](../errorcodes/errorco
**Example**
```js
letisPlay;
letstarted;
letisPlaying;// An identifier specifying whether rendering is in progress.
letisDucked;// An identifier specifying whether the audio volume is reduced.
// The system forcibly interrupts audio rendering. The application must update the status and displayed content accordingly.
switch(interruptEvent.hintType){
caseaudio.InterruptHint.INTERRUPT_HINT_PAUSE:
console.info('Force paused. Stop writing');
isPlay=false;
// The audio stream has been paused and temporarily loses the focus. It will receive the interruptEvent corresponding to resume when it is able to regain the focus.
console.info('Force paused. Update playing status and stop writing');
isPlaying=false;// A simplified processing indicating several operations for switching the application to the paused state.
break;
caseaudio.InterruptHint.INTERRUPT_HINT_STOP:
console.info('Force stopped. Stop writing');
isPlay=false;
// The audio stream has been stopped and permanently loses the focus. The user must manually trigger the operation to resume rendering.
console.info('Force stopped. Update playing status and stop writing');
isPlaying=false;// A simplified processing indicating several operations for switching the application to the paused state.
break;
caseaudio.InterruptHint.INTERRUPT_HINT_DUCK:
// The audio stream is rendered at a reduced volume.
// The application can choose to take action or ignore.
switch(interruptEvent.hintType){
caseaudio.InterruptHint.INTERRUPT_HINT_RESUME:
// It is recommended that the application continue rendering. (The audio stream has been forcibly paused and temporarily lost the focus. It can resume rendering now.)
console.info('Resume force paused renderer or ignore');
awaitaudioRenderer.start().then(asyncfunction(){
console.info('AudioInterruptMusic: renderInstant started :SUCCESS ');
Subscribes to audio interruption events. This API uses a callback to get interrupt events.
Same as [on('interrupt')](#oninterrupt), this API is used to listen for focus changes. The **AudioCapturer** instance proactively gains the focus when the **start** event occurs and releases the focus when the **pause** or **stop** event occurs. Therefore, you do not need to request to gain or release the focus.
| type | string | Yes | Event type. The value **'audioInterrupt'** means the audio interruption event, which is triggered when audio capturing is interrupted. |
| callback | Callback\<[InterruptEvent](#interruptevent9)\> | Yes | Callback used to return the audio interruption event. |
**Error codes**
For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
| ID | Error Message |
| ------- | ------------------------------ |
| 6800101 | if input parameter value error |
**Example**
```js
letisCapturing;// An identifier specifying whether capturing is in progress.
// The system forcibly interrupts audio capturing. The application must update the status and displayed content accordingly.
switch(interruptEvent.hintType){
caseaudio.InterruptHint.INTERRUPT_HINT_PAUSE:
// The audio stream has been paused and temporarily loses the focus. It will receive the interruptEvent corresponding to resume when it is able to regain the focus.
console.info('Force paused. Update capturing status and stop reading');
isCapturing=false;// A simplified processing indicating several operations for switching the application to the paused state.
break;
caseaudio.InterruptHint.INTERRUPT_HINT_STOP:
// The audio stream has been stopped and permanently loses the focus. The user must manually trigger the operation to resume capturing.
console.info('Force stopped. Update capturing status and stop reading');
isCapturing=false;// A simplified processing indicating several operations for switching the application to the paused state.
// The application can choose to take action or ignore.
switch(interruptEvent.hintType){
caseaudio.InterruptHint.INTERRUPT_HINT_RESUME:
// It is recommended that the application continue capturing. (The audio stream has been forcibly paused and temporarily lost the focus. It can resume capturing now.)
console.info('Resume force paused renderer or ignore');
// To continue capturing, the application must perform the required operations.
break;
caseaudio.InterruptHint.INTERRUPT_HINT_PAUSE:
// It is recommended that the application pause capturing.
console.info('Choose to pause or ignore');
// To pause capturing, the application must perform the required operations.
break;
caseaudio.InterruptHint.INTERRUPT_HINT_STOP:
// It is recommended that the application stop capturing.
console.info('Choose to stop or ignore');
// To stop capturing, the application must perform the required operations.