ap.pauseBackgroundAudio 暂停播放音乐

优质
小牛编辑
132浏览
2023-12-01

ap.pauseBackgroundAudio(CALLBACK)

暂停播放音乐。

代码示例

<script src="https://gw.alipayobjects.com/as/g/h5-lib/alipayjsapi/3.1.1/alipayjsapi.inc.min.js"></script>

<style>.output{ display:block; max-width: 100%; overflow: auto}</style>
<button class="btn btn-default">开始播放</button>
<button class="btn btn-default">暂停播放</button>
<button class="btn btn-default">停止播放</button>
<button class="btn btn-default">从0开始播放</button>
<button class="btn btn-default">获取播放状态信息</button>
<pre class="output"></pre>
<script>
  var btnPlayBackgroundAudio = document.querySelector('#J_btnPlayBackgroundAudio');
  var btnPauseBackgroundAudio = document.querySelector('#J_btnPauseBackgroundAudio');
  var btnStopBackgroundAudio = document.querySelector('#J_btnStopBackgroundAudio');
  var btnSeekBackgroundAudio = document.querySelector('#J_btnSeekBackgroundAudio');
  var btnGetState = document.querySelector('#J_btnGetState');
  var output = document.querySelector('#J_output');

  btnPlayBackgroundAudio.addEventListener('click', function(){
    ap.playBackgroundAudio({
      url: 'https://os.alipayobjects.com/rmsportal/FOjtUAVjVsfldZgjBdxE.mp3',
      title: '舒缓轻音乐',
      cover: 'https://zos.alipayobjects.com/rmsportal/VRrMXbgUSdsibQjwZpyT.png'
    });
  });
  btnPauseBackgroundAudio.addEventListener('click', function(){
    ap.pauseBackgroundAudio();
  });
  btnStopBackgroundAudio.addEventListener('click', function(){
    ap.stopBackgroundAudio();
  });
  btnSeekBackgroundAudio.addEventListener('click', function(){
    ap.seekBackgroundAudio(0);
  });
  btnGetState.addEventListener('click', function(){
    ap.getBackgroundAudioPlayerState(function(res){
      output.innerHTML = JSON.stringify(res, undefined, '  ');
    });
  });
</script>