live-player中在onHide中操作直播实例不生效
<view class="page-body">
<view class="page-section tc">
<live-player id="player" src="{{liveSrc}}"
mode="live" bindstatechange="statechange" binderror="error" background-mute/>
<view class="btn-area">
<button bindtap="bindPlay" class="page-body-button" type="primary">播放</button>
<button bindtap="bindPause" class="page-body-button" type="primary">暂停</button>
<button bindtap="bindStop" class="page-body-button" type="primary">停止</button>
<button bindtap="bindResume" class="page-body-button" type="primary">恢复</button>
<button bindtap="bindMute" class="page-body-button" type="primary">静音</button>
<button bindtap="setSrc" class="page-body-button" type="primary">src</button>
</view>
</view>
</view>
/* eslint-disable */
const app = getApp()
Page({
data: {
liveSrc: "",
state: 0, // 当前视频状态,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
});
}
})
},
bindExitFullScreen() {
this.ctx.requestFullScreen({
direction: 90,
success: res => {
console.log('requestFullScreen success')
},
fail: res => {
console.log('requestFullScreen fail')
this.setData({
state: -1
});
}
})
},
setSrc(){
this.setData({
liveSrc: ""
});
console.log(this.data.liveSrc);
this.ctx = null;
},
onShow(){
console.log("show~~~~~~");
// setTimeout(() => {
// this.bindPlay();
// }, 1000);
},
onHide(){
console.log("hide~~~~~~");
this.setData({
liveSrc: ""
});
this.bindStop();
}
/* 直播相关 end */
})
同问
我也遇到this.ctx.stop()对ios系统无效的问题 官方人员没有回答啊
我也遇到这个问题,是因为onhide的时候页面view先跳转到其他页面,逻辑层执行代码的时候获取不到拉留对象,请问你现在解决了吗
现在有解决方案了吗
onHide的时候用 this.ctx.stop()事件呢
也没有效果,试过了