InnerAudioContext.onPlay

The InnerAudioContext.onPlay method allows mini program developers to register a callback that is executed when the audio starts playing.

Parameters

Type

Required

Description

Function listener

Yes

The callback to be executed when the audio starts playing.

Sample code

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