InnerAudioContext.onError

The InnerAudioContext.onError method allows mini program developers to register a callback that is executed when an error occurs during audio playback. This allows developers to handle playback errors dynamically, enhancing the user experience.

Parameters

Type

Required

Description

Function listener

Yes

The callback to be executed when an error occurs during playback. For more information about values returned to this function, refer to Callback parameters.

Callback parameters

When the registered callback function is executed, it receives an object that contains the following parameters:

Parameter

Type

Required

Description

errCode

Number

Yes

An error code that represents the specific error encountered. For more information, refer to Error codes.

errMessage

String

Yes

An error message that describes the corresponding error code. For more information, refer to Error codes.

Error codes

Error code

Error message

Further action

10007

Audio src error

Ensure that the audio resource path is correct and the resource is valid.

-1

Unknown error

Ensure that the foreground audio resource is valid.

Sample code

Set callback

copy
this.innerAudioContext = my.createInnerAudioContext ();
this.innerAudioContext.src = 'https://www.sample.com/sample.mp3';
this.innerAudioContext.play();
this.innerAudioContext.onError(() => {
  console.log ('on audio play error');
});

Callback return

copy
{"errCode":10007,"errMessage":"Audio src error"}