1***@163.com
1***@163.com
  • 发布:2023-04-11 17:12
  • 更新:2023-04-11 17:12
  • 阅读:284

liver-pusher组件在APP下运行推流失败

分类:uni-app
我配了一个nginx rtmp服务器,用obs测试了推流和vlc测试了拉流都成功了,但是使用uniapp里的liver-pusher组件推流却一直都是失败的,有人知道是什么原因导致的吗? 代码如下: <template> <view class="content"> <!-- 推流 --> <view> <live-pusher id="livePusher" ref="livePusher" url="url" enable-camera="enableCamera" auto-focus="true" background-mute="true" enable-agc="true" enable-ans="true" mode="SD"
@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}

2023-04-11 17:12 负责人:无 分享
已邀请:

要回复问题请先登录注册