video组件播放m3u8直播视频时,如果同时创建了音频,那么可以正常播放但loading一直存在。尤其当你点击暂停直播,再点击播放的时候
ios 复现, 安卓没有此问题
代码如下:
js :
const app = getApp()
Page({
data: {
music: 0,
motto: 'Hello World',
userInfo: {},
hasUserInfo: false,
canIUse: wx.canIUse('button.open-type.getUserInfo')
},
//事件处理函数
Bindstop: function() {
this.myaudio.pause();
},
BindPlay: function() {
this.myaudio.play();
},
bindwaiting: function(e) {
console.log('bindwaiting',e)
},
binderror: function(e) {
console.log('binderror',e)
},
onLoad: function () {
const myaudio = wx.createInnerAudioContext();
this.myaudio = myaudio;
//设置obeyMuteSwitch: false(不遵循系统静音开关,即使用户打开了静音开关,也能继续发出声音)
//设置autoplay: true(自动开始播放)
if (wx.setInnerAudioOption) {
wx.setInnerAudioOption({
obeyMuteSwitch: false,
autoplay: true
})
}else {
myaudio.obeyMuteSwitch = false;
myaudio.autoplay = true;
}
//监听各个阶段
myaudio.onCanplay(() => {
console.log('可以播放');
myaudio.play();
});
myaudio.onPlay(() => {
console.log('监听到音频开始播放');
});
myaudio.onEnded(() => {
console.log('音频自然播放结束事件');
});
myaudio.onStop(() => {
console.log('音频停止事件');
});
myaudio.onError((res) => {
console.log(res.errMsg);
console.log(res.errCode);
});
myaudio.onWaiting((res) => {
console.log('音频加载中事件,当音频因为数据不足,需要停下来加载时会触发')
});
//设置播放链接
myaudio.src = 'xxx.mp3';
//播放
},
})
html :
<video style="width:100%" bindwaiting="bindwaiting" binderror="binderror" autoplay bindplay="BindPlay" bindpause="Bindstop" src="xxx.m3u8" controls></video>
你好,请提供出现问题的具体机型、能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)