@statechange="statechangeLive"
@netstatus="netstatusLive"
@error="errorLive"
></live-pusher>
<button @click="changeCamera">切换摄像头</button>
<button @click="startLive">开始推流(开始直播)</button>
<button @click="stopLive">结束推流</button>
</view>
</view>
</template>
<script>
export default {
data() {
return {
url: 'rtmp://101.201.56.81:1935/live', //直播地址
enableCamera: true, //是否开启摄像头
devicePosition: 'front', //front/back(前置后置)
context: null
}
},
onReady() {
console.log('准备就绪');
this.context = uni.createLivePusherContext('livePusher',this)
},
methods: {
statechangeLive(e){//直播推流状态变化事件
console.log('直播推流状态变化事件');
console.log(JSON.stringify(e));
},
netstatusLive(e){//直播推流网络状态通知
console.log('直播推流网络状态通知');
console.log(JSON.stringify(e));
},
errorLive(e){//渲染发生错误
console.log('渲染发生错误');
console.log(JSON.stringify(e));
},
changeCamera(){//点击切换摄像头
if(this.devicePosition == 'front'){
this.devicePosition = 'back'
}else if(this.devicePosition == 'back'){
this.devicePosition = 'front'
}
},
startLive(){//开始推流
this.context.start({
success:(res)=>{
console.log('推流成功');
console.log(JSON.stringify(res));
},
fail:(err)=>{
console.log('推流失败');
console.log(JSON.stringify(err));
}
})
},
stopLive(){//结束推流
this.context.stop({
success:(res)=>{
console.log('结束推流成功');
console.log(JSON.stringify(res));
},
fail:(err)=>{
console.log('结束推流失败');
console.log(JSON.stringify(err));
}
})
}
}
}
</script>
这里面的推流地址我换成http://101.201.56.81/live/index.m3u8(此地址obs也能成功推流)后不会走error了,但是会直接关闭摄像头直接没反应了。
rtmp地址下的报错信息如下:
{"type":"statechange","target":{"dataset":{},"offsetLeft":31,"message":"java.lang.IllegalArgumentException: Invalid RTMP URL. Must be in format: rtmp://host[:port]/application/streamName","id":"","code":"3004","offsetTop":0},"detail":{"message":"java.lang.IllegalArgumentException: Invalid RTMP URL. Must be in format: rtmp://host[:port]/application/streamName","code":"3004"},"currentTarget":{"dataset":{},"id":"","offsetLeft":31,"offsetTop":0},"timeStamp":0,"mp":{"@warning":"mp is deprecated","type":"statechange","target":{"dataset":{},"offsetLeft":31,"message":"java.lang.IllegalArgumentException: Invalid RTMP URL. Must be in format: rtmp://host[:port]/application/streamName","id":"","code":"3004","offsetTop":0},"detail":{"message":"java.lang.IllegalArgumentException: Invalid RTMP URL. Must be in format: rtmp://host[:port]/application/streamName","code":"3004"},"currentTarget":{"dataset":{},"id":"","offsetLeft":31,"offsetTop":0},"timeStamp":0},"_processed":true}
0 个回复