安卓手机浏览器无法自动播放背景音乐 需要在mounted 强制执行播放 auido.play()

如果是在微信环境 需要额外处理

const userAgent = window.navigator.userAgent;
const IS_IN_IOS = !!userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);

const IS_IN_WX = /MicroMessenger/i.test(userAgent);

if (ENV.IS_IN_WX) { // 是否微信环境
  if (ENV.IS_IN_IOS) {
    changeAudioPlayStatus(true);
    changeAudioPlayStatus(false);
  }
  } else {
  changeAudioPlayStatus(true);
}
document.addEventListener('WeixinJSBridgeReady', () => {
  // 微信H5环境,监听WeixinJSBridgeReady事件,再次进行play
  changeAudioPlayStatus(true);
}, false);

我就看看
22 声望0 粉丝

nestjs