InnerAudioContext.offCanPlay

The InnerAudioContext.offCanPlay method allows mini program developers to remove an event listener previously registered with the InnerAudioContext.onCanPlay method. This stops the specified listener from monitoring the event that occurs when the audio is ready to play.

Parameters

Type

Required

Description

Function listener

No

The callback that is passed to the InnerAudioContext.onCanPlay method. If this parameter is not specified, all InnerAudioContext.onCanPlay listeners are removed.

Sample code

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

this.innerAudioContext.onCanPlay(listener);
this.innerAudioContext.offCanPlay(listener);