停止播放音乐。
<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 id="J_btnPlayBackgroundAudio" class="btn btn-default">开始播放</button>
<button id="J_btnPauseBackgroundAudio" class="btn btn-default">暂停播放</button>
<button id="J_btnStopBackgroundAudio" class="btn btn-default">停止播放</button>
<button id="J_btnSeekBackgroundAudio" class="btn btn-default">从0开始播放</button>
<button id="J_btnGetState" class="btn btn-default">获取播放状态信息</button>
<pre id="J_output" 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>