beauty="1"
whiteness="2"
aspect="9:16"
@statechange="statechange"
@netstatus="netstatus"
@error = "error"
</live-pusher>
<button class="btn" @click="start">开始推流</button>
<button class="btn" @click="pause">暂停推流</button>
<button class="btn" @click="resume">resume</button>
<button class="btn" @click="stop">停止推流</button>
<button class="btn" @click="snapshot">快照</button>
<button class="btn" @click="startPreview">开启摄像头预览</button>
<button class="btn" @click="stopPreview">关闭摄像头预览</button>
<button class="btn" @click="switchCamera">切换摄像头</button>
<video
id="livePlayer"
src="http://118.24.143.70/live/room7_327801/index.m3u8"
class="video-player"
controls="false"
autoplay="true"
show-fullscreen-btn="false"
show-play-btn="false"
enable-progress-gesture="false"
show-center-play-btn="true"
object-fit="'contain'" show-loading
/>
</view>
</template>
<script>
export default {
data() {
return {
mode: 'SD',
enableCamera:true
}
},
onLoad(e) {
console.log(JSON.stringify(e))
},
onReady() {
// 注意:需要在onReady中 或 onLoad 延时
this.context = uni.createLivePusherContext("livePusher", this);
// this.cameraContext = uni.createCameraContext(this)
this.context.startPreview()
this.enableCamera = true;
},
onUnload() {
this.stop()
},
methods: {
statechange(e) {
// console.log("statechange:" + JSON.stringify(e));
switch(e.detail.code) {
case 1001:
this.pushStatus = '正在连接'
break
case 1002:
this.pushStatus = '已连接'
break
case 1003:
this.pushStatus = '重新连接中'
break
case -1301:
this.pushStatus = '网络断开'
break
case -1302:
this.pushStatus = '连接失败'
break
case -1303:
this.pushStatus = '连接被拒绝'
break
}
},
netstatus(e) {
// console.log("netstatus:" + JSON.stringify(e));
},
error(e) {
console.log("error:" + JSON.stringify(e));
},
start: function() {
this.context.start({
success: (a) => {
console.log("livePusher.start:" + JSON.stringify(a));
}
});
},
close: function() {
this.context.close({
success: (a) => {
console.log("livePusher.close:" + JSON.stringify(a));
}
});
},
snapshot: function() {
this.context.snapshot({
success: (e) => {
console.log(JSON.stringify(e));
}
});
},
resume: function() {
this.context.resume({
success: (a) => {
console.log("livePusher.resume:" + JSON.stringify(a));
}
});
},
pause: function() {
this.context.pause({
success: (a) => {
console.log("livePusher.pause:" + JSON.stringify(a));
}
});
},
stop: function() {
this.context.stop({
success: (a) => {
console.log(JSON.stringify(a));
}
});
},
switchCamera: function() {
this.context.switchCamera({
success: (a) => {
console.log("livePusher.switchCamera:" + JSON.stringify(a));
}
});
},
startPreview: function() {
// this.$set(this,'enableCarema',true)
// this.context.stop();
// this.enableCarema = true;
// this.context.start();
// console.log(1111,this.context.startPreview)
this.context.startPreview({
success: (a) => {
console.log("livePusher.stopPreview:" + JSON.stringify(a));
}
});
this.enableCamera = true;
// this.context.start({
// success: (a) => {
// console.log('推流已开始')
// },
// fail: (err) => {
// console.error("停止推流失败", err);
// }
// });
// this.context.stop();
// this.enableCamera =true;
// setTimeout(()=>{
// this.context.start();
// },1000)
// this.context?.startPreview({
// success: (a) => {
// this.enableCarema = true;
// this.$forceUpdate();
// console.log("livePusher.startPreview:" + JSON.stringify(a));
// }
// });
},
stopPreview: function() {
// console.log(this.$refs.livePusher)
// console.log(222,this.context.stopPreview)
// console.log(this.context?.mute)
uni.showLoading({ title: '关闭中...' });
// this.context.stopPreview();
// this.context.stop();
// this.enableCamera =false;
// setTimeout(()=>{
// this.context.start();
// },1000)
// setTimeout(()=>{
// this.mode = 'RTC';
// uni.hideLoading();
// },2000)
// this.$refs.livePusher['enable-camera'] = false;
// console.log(this.$refs.livePusher)
// this.context.stop({
// success: () => {
// // 步骤2:停止预览 + 关闭摄像头
// this.context.stopPreview();
// this.enableCamera = false;
// this.$forceUpdate();
// // 步骤3:重启推流(采集封面图)
// setTimeout(() => {
// this.context.start({
// success: () => {
// uni.hideLoading();
// uni.showToast({ title: '已显示黑屏图片', icon: 'success' });
// },
// fail: (err) => {
// uni.hideLoading();
// uni.showToast({ title: '重启推流失败:' + err.errMsg, icon: 'none' });
// }
// });
// }, 300);
// },
// fail: (err) => {
// uni.hideLoading();
// uni.showToast({ title: '操作失败:' + err.errMsg, icon: 'none' });
// }
// });
this.context.stopPreview({
success: (a) => {
uni.hideLoading();
console.log("livePusher.stopPreview:" + JSON.stringify(a));
}
});
// this.enableCamera = false;
// setTimeout(()=>{
// this.context.stop({
// success: (a) => {
// uni.hideLoading();
// console.log('推流已停止')
// },
// fail: (err) => {
// console.error("停止推流失败", err);
// }
// });
// },1000)
// this.cameraContext?.stop();
// this.enableCamera = false;
// this.mode = 'RTC';
uni.hideLoading();
// this.context?.muteVideo({
// success: () => {
// // this.isCameraOpen = false;
// uni.showToast({ title: '摄像头已关闭', icon: 'success' });
// },
// fail: (err) => {
// uni.showToast({ title: '关闭失败:' + err.errMsg, icon: 'none' });
// }
// });
// this.context.snapshot(res => {
// console.log('当前画面状态:', res.tempImagePath); // 验证黑屏
// });
// this.context.stop({
// success: () => {
// // 步骤2:停止预览 + 关闭摄像头采集
// this.context.stopPreview();
// this.enableCamera = false;
// this.$forceUpdate();
// this.context.snapshot(res => {
// console.log('当前画面状态:', res.tempImagePath); // 验证黑屏
// });
// // 步骤3:重启推流(仅音频,无视频)
// // setTimeout(() => {
// // this.context.start({
// // // 关键:推流参数指定仅音频
// // audioOnly: true,
// // success: () => {
// // uni.hideLoading();
// // uni.showToast({ title: '摄像头已关闭(推流仅音频)', icon: 'success' });
// // },
// // fail: (err) => {
// // uni.hideLoading();
// // uni.showToast({ title: '重启推流失败:' + err.errMsg, icon: 'none' });
// // }
// // });
// // }, 300); // 延迟300ms,确保视频流完全中断
// },
// fail: (err) => {
// uni.hideLoading();
// uni.showToast({ title: '关闭失败:' + err.errMsg, icon: 'none' });
// }
// });
}
}
}
</script>
<style lang="scss">
.black-screen-cover {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 99; / 确保覆盖摄像头画面 /
}
.black-screen-img {
width: 100%;
height: 100%;
/ 黑屏图拉伸铺满,保持比例 /
object-fit: cover;
background-color: #000; / 兜底黑屏,防止图片加载失败 /
}
</style>
1 个回复
Ask小助手 - Ask社区AI助手
作为 DCloud 官方人员,我对这条 bug 反馈进行如下评审:
反馈完整性评估
Bug 是否成立
根据知识库:
概念/使用问题
结论
该反馈在“muted 无效”上属于概念误解,不构成 bug;在“enable-camera=false 仍有画面”上需补充复现步骤并确认模块配置、调用时序后,才能判定是否为真 bug。建议反馈者:
要回复问题请先登录或注册
公告
更多>相关问题