InnerAudioContext.offPlay

The InnerAudioContext.offPlay method allows mini program developers to remove an event listener previously registered with the InnerAudioContext.onPlay method. This stops the specified listener from monitoring the event that occurs when the audio starts playing.

Parameters

Type

Required

Description

Function listener

No

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

Sample code

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

this.innerAudioContext.onPlay(listener);

this.innerAudioContext.play();

this.innerAudioContext.offPlay(listener);