InnerAudioContext.onEnded

解释:音频自然播放结束事件

方法参数

Function callback

示例

在开发者工具中预览效果

扫码体验

InnerAudioContext.onEnded - 图1请使用百度APP扫码

图片示例

InnerAudioContext.onEnded - 图2

InnerAudioContext.onEnded - 图3

InnerAudioContext.onEnded - 图4

代码示例

  • 在 swan 文件中
  1. <view class="wrap">
  2. <button type="primary" bindtap="seekEnded">点击到音频末尾</button>
  3. <view class="card-area">
  4. 听至音频末尾即可触发事件
  5. </view>
  6. </view>
  • 在 js 文件中
  1. Page({
  2. onLoad() {
  3. const innerAudioContext = swan.createInnerAudioContext();
  4. innerAudioContext.src = 'https://vd3.bdstatic.com/mda-ic7mxzt5cvz6f4y5/mda-ic7mxzt5cvz6f4y5.mp3';
  5. innerAudioContext.autoplay = false;
  6. innerAudioContext.onPlay(res => {
  7. console.log('onPlay', res);
  8. });
  9. innerAudioContext.onEnded(res => {
  10. swan.showModal({
  11. title: 'onEnded',
  12. content: JSON.stringify(res)
  13. });
  14. });
  15. this.innerAudioContext = innerAudioContext;
  16. this.innerAudioContext.play();
  17. },
  18. seekEnded() {
  19. this.innerAudioContext.onTimeUpdate(res => {
  20. this.innerAudioContext.seek(res.data.duration)
  21. });
  22. }
  23. });