在H5页面中使用audio标签后,canplay方法在安卓和浏览器中正常,但是ios的微信环境中无法触发
原因:
In Safari on iOS (for all devices, including iPad), where the user may
be on a cellular network and be charged per data unit, preload and
autoplay are disabled. No data is loaded until the user initiates it.
This means the JavaScript play() and load() methods are also inactive
until the user initiates playback, unless the play() or load() method
is triggered by user action. In other words, a user-initiated Play
button works, but an onLoad="play()" event does not
大概意思就是:苹果禁止了Autoplay和JS "onload" 加载播放。
解决办法:
mounted()
if(this.isiOS){
his.allPlay()
}
},
allPlay(){
let _that = this
_that.allAudioObj = document.getElementById('audiotempAll')
if(typeof WeixinJSBridge == 'object' && typeof WeixinJSBridge.invoke == 'function'){
WeixinJSBridge.invoke('getNetworkType', {}, function (res) {
// 在这里拿到 e.err_msg, 这里面就包含了所有的网络类型
// alert(res.err_msg);
_that.audioObj.load()
_that.allAudioObj.load();
console.log(_that.allAudioObj.duration)
});
}else{
console.log('非微信环境')
}
},
思路:
监听微信内部的weixinJSBridgeReady触发对音频的操作
但是这个只能解决微信内部打开H5,并不解决safari中打开依然无法获取的问题
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。