tools.js 478 B

123456789101112131415161718
  1. // 播放音频
  2. export function playAudio(type){
  3. const innerAudioContext = uni.createInnerAudioContext();
  4. // innerAudioContext.autoplay = true;
  5. innerAudioContext.src = '/static/'+type+'.mp3';
  6. innerAudioContext.onCanplay(res => {
  7. innerAudioContext.play()
  8. })
  9. innerAudioContext.onPlay(() => {
  10. console.log('开始播放');
  11. });
  12. innerAudioContext.onError((res) => {
  13. console.log(res.errCode);
  14. });
  15. innerAudioContext.onEnded(res => {
  16. innerAudioContext.destroy()
  17. })
  18. }