y***@qq.com
y***@qq.com
  • 发布:2020-12-08 16:08
  • 更新:2020-12-08 16:08
  • 阅读:685

uniapp 直播推流正常页面没问题 但是只要做成组件打开推流就报错

分类:uni-app

代码 nvue

<template>
<view>
<live-pusher id="livePusher" :url="url" :enable-camera="enableCamera" mode="FHD"></live-pusher>
<button @click="startLive">开始推流(开始直播)</button>
<button @click="stopLive">结束推流</button>
</view>
</template>

<script>
export default {
data() {
return {
url: 'rtmp://192.168.1.112/live/zfy',
enableCamera: true,
context: null
};
},
created() {
this.context = uni.createLivePusherContext('livePusher', this);
this.context.switchCamera() // 摄像头切换(切换为后置)
this.context.startPreview() // 摄像头预览 (不加会黑屏)
},
methods: {
startLive() {
this.context.start({
success: a => {
console.log('livePusher.start:' + JSON.stringify(a));
}
});
},
stopLive() {
this.context.stop({
success: a => {
console.log(JSON.stringify(a));
}
});
}
}
};
</script>

2020-12-08 16:08 负责人:无 分享
已邀请:

该问题目前已经被锁定, 无法添加新回复