live-player中在onHide中操作直播实例不生效
mode="live" bindstatechange="statechange" binderror="error" background-mute/>
/* eslint-disable */
const app = getApp()
Page({
data: {
liveSrc: "",
state: 0, // 当前视频状态,IOS真机测试navigateBack后showToast Toast不显示。0暂停,1播放,-1无视频或播放失败,用于控制页面上元素的展示
fullScreen: false,
mute: false,
init: true // 是否是第一次播放,用于控制只进行一次play()
},
onLoad: function () {
this.setData({
// liveSrc:"http://tx.corp-flv.huya.com/huyalive/35754395-35754395-153563957213265920-3155517294-10057-A-1523883632-63059.flv?wsSecret=551b73f934a29fcc48ec24010c6a3a81&wsTime=5ad601ce"
liveSrc:"rtmp://live.hkstv.hk.lxdns.com/live/hks"
})
},
onReady(res) {
this.ctx = wx.createLivePlayerContext('player')
},
/* 直播相关 start */
// 静音按钮
tapMute() {
this.bindMute();
},
// 监听状态改变
statechange(e) {
if (e.detail.code == '-2301') {
console.log('loading fail');
this.setData({
state: -1
});
}
console.log('live-player code:', e.detail.code)
},
// 错误处理
error(e) {
console.error('live-player error:', e.detail.errMsg);
this.setData({
state: -1
});
},
bindPlay() {
this.ctx.play({
success: res => {
this.setData({
// state:1 - this.data.state // 1
state: 1
});
console.log('play success')
},
fail: res => {
console.log('play fail');
this.setData({
state: -1
});
}
})
},
bindPause() {
this.ctx.pause({
success: res => {
this.setData({
// state:1 - this.data.state // 0
state: 0
});
console.log('pause success')
},
fail: res => {
console.log('pause fail')
this.setData({
state: -1
});
}
})
},
bindStop() {
this.ctx.stop({
success: res => {
this.setData({
// state:1 - this.data.state // 0
state: 0,
init: true
});
console.log('stop success')
},
fail: res => {
console.log('stop fail')
this.setData({
state: -1
});
}
})
},
bindResume() {
this.ctx.resume({
success: res => {
this.setData({
// state:1 - this.data.state // 1
state: 1
});
console.log('resume success')
},
fail: res => {
console.log('resume fail')
this.setData({
state: -1
});
}
})
},
bindMute() {
this.ctx.mute({
success: res => {
this.setData({
mute: !this.data.mute
});
console.log('mute success')
},
fail: res => {
console.log('mute fail')
this.setData({
state: -1
});
}
})
},
bindFullScreen() {
this.ctx.exitFullScreen({
success: res => {
console.log('exitFullScreen success')
},
fail: res => {
console.log('exitFullScreen fail')
this.setData({
state: -1
本文网址:http://www.91bianli.com/weixinxiaochengxu/57385.html