<view class="page-body">
<view class="page-section tc">
<live-pusher id="pusher" url="直播推流地址" mode="RTC" autopush bindstatechange="statechange" />
<view class="btn-area">
<button bindtap="bindStart" 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="bindSwitchCamera" class="page-body-button" type="primary">切换前后摄像头</button>
</view>
</view>
</view>
js
onReady(res) {
this.ctx = wx.createLivePusherContext('pusher')
},
statechange(e) {
console.log('live-pusher code:', e.detail.code)
},
bindStart() {
this.ctx.start({
success: res => {
console.log(1)
console.log('start success')
},
fail: res => {
console.log('start fail')
}
})
},
bindPause() {
this.ctx.pause({
success: res => {
console.log('pause success')
},
fail: res => {
console.log('pause fail')
}
})
},
bindStop() {
this.ctx.stop({
success: res => {
console.log('stop success')
},
fail: res => {
console.log('stop fail')
}
})
},
bindResume() {
this.ctx.resume({
success: res => {
console.log('resume success')
},
fail: res => {
console.log('resume fail')
}
})
},
bindSwitchCamera() {
this.ctx.switchCamera({
success: res => {
console.log('switchCamera success')
},
fail: res => {
console.log('switchCamera fail')
}
})
},
你好,是live-player组件还是小程序直播呢?这两个是不一样的哦,可以参考下对应文档说明。
live-pusher 组件是需要特定的类目的,看看有没有申请
https://developers.weixin.qq.com/miniprogram/dev/component/live-player.html