// 判断是否是微信浏览器
function is_wxBrowser() {
    return /micromessenger/.test(navigator.userAgent.toLowerCase());
}

// 判断是否是ios系统
function is_iOS () {
    return /(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent);
}

// 获取音频时长
 getAudioLength = (el) => {
   if (el) {
      if (is_iOS() && is_wxBrowser()) {
          if(typeof window.WeixinJSBridge === 'object'){
               window.WeixinJSBridge.invoke('getNetworkType', {}, function(e) {
                  const playPromise = el.play()
                    if (playPromise !== undefined) {
                         playPromise
                            .then(() => {
                                el.pause()
                             })
                              .catch(() => {
                                 el.pause()
                              });
                        }
                    });
                }else{
                    const playPromise = el.play()
                    if (playPromise !== undefined) {
                        playPromise
                            .then(() => {
                                el.pause()
                            })
                            .catch(() => {
                                el.pause()
                            });
                    }
                }
            }
            el.onloadedmetadata = () => {
              console.log(el.duration)
            };
        }

音频快进和后退也要触发播放事件,在ios的微信浏览器下需要手动触发播放事件

 posted on 2021-07-23 10:19  Yseraaa  阅读(365)  评论(0编辑  收藏  举报