InnerAudioContext.onCanPlay
The InnerAudioContext.onCanPlay
method allows mini program developers to register a callback that is executed when the audio is ready to play. This typically occurs when enough audio data has been buffered to initiate playback. However, it does not guarantee smooth playback, as network conditions or playback interruptions might still occur.
Parameters
Type | Required | Description |
Function listener | Yes | The callback to be executed when the audio is ready to play. |
Sample code
copy
this.innerAudioContext = my.createInnerAudioContext();
this.innerAudioContext.src = 'https://www.sample.com/sample.mp3';
this.innerAudioContext.onCanPlay(() => {
console.log ('onCanPlay');
});