2***@qq.com
2***@qq.com
  • 发布:2026-03-05 10:26
  • 更新:2026-03-05 10:27
  • 阅读:20

【报Bug】live-pusher设置enable-camera为false,但是接收的video组件依然有视频画面,muted静音设置不管是true还是false,推流出去的都有声音

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: 10

HBuilderX类型: 正式

HBuilderX版本号: 4.87

手机系统: Android

手机系统版本号: Android 16

手机厂商: 小米

手机机型: Redmi k70 Ultra

页面类型: vue

vue版本: vue2

打包方式: 云端

项目创建方式: HBuilderX

示例代码:
<template> <view> <live-pusher id='livePusher' ref="livePusher" class="livePusher" url="rtmp://118.24.143.70:1935/live/room7_327801" mode="mode" muted="true" enable-camera="true" auto-focus="true"

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>

操作步骤:

live-pusher设置enable-camera为false,但是接收的video组件依然有视频画面,muted静音设置不管是true还是false,推流出去的都有声音

预期结果:

enable-camera为false,但是接收的video组件没有视频画面,muted静音设置不管是true时有声音,为false时没声音才对

实际结果:

enable-camera为false,但是接收的video组件依然有视频画面,muted静音设置不管是true还是false,推流出去的都有声音

bug描述:

live-pusher设置enable-camera为false,但是接收的video组件依然有视频画面,muted静音设置不管是true还是false,推流出去的都有声音

2026-03-05 10:26 负责人:无 分享
已邀请:
Ask小助手

Ask小助手 - Ask社区AI助手

请补充平台分类:安卓, ios, 鸿蒙或小程序。并提供详细的推送黑屏图问题描述,包括hbuilderx版本信息、辅助示例代码及报错信息。
欢迎到专业群( uni-app 官方技术交流群 1 ) 咨询,群中有相关专业的管理员和群友。

作为 DCloud 官方人员,我对这条 bug 反馈进行如下评审:

  1. 反馈完整性评估

    • 标题与描述:基本能说明现象,但缺少“推流端/拉流端是否重启”“网络环境”等关键信息。
    • 代码示例:可直接运行,但 manifest.json 中未勾选 LivePusher 模块(App 端必需),也未说明是否使用自定义基座。
    • 复现步骤:仅给出按钮操作,未说明“先 startPreview → 再 stopPreview → 再 start”的完整时序,官方人员难以 100 % 复现。
    • 预期/实际结果:描述清晰,但“enable-camera 为 false 仍出画面”与“muted 无效”混在一起,应拆成两条独立 issue。
    • 分类信息:版本、平台、机型齐全。
  2. Bug 是否成立
    根据知识库:

    • App 端 live-pusher 在 vue 页面需 HBuilderX ≥ 3.4.1,且 manifest.json 必须勾选 LivePusher 模块;反馈者使用 4.87 版本满足版本要求,但未确认是否勾选模块。
    • muted 仅作用于麦克风采集,不影响已采集数据的播放端;若推流端静音失败,播放端自然仍有声音,这属于“预期行为”而非 bug。
    • enable-camera 设为 false 后,组件应停止采集摄像头画面;若播放端仍显示画面,大概率是推流端未真正停止采集或 CDN 缓存了最后一帧。需确认是否调用了 stopPreview / stop,并检查 snapshot 是否返回黑屏图。
  3. 概念/使用问题

    • 反馈者把“muted”理解为“让远端听不到声音”,实际 muted 仅控制本地麦克风是否静音;若需远端静音,应使用推流端 stop 或切换纯音频模式。
    • 反馈者尝试在 stopPreview 后手动设置 enable-camera=false,但 enable-camera 是组件属性,应在 template 中绑定变量并通过 setData 修改,而非直接改 this.enableCamera。

结论
该反馈在“muted 无效”上属于概念误解,不构成 bug;在“enable-camera=false 仍有画面”上需补充复现步骤并确认模块配置、调用时序后,才能判定是否为真 bug。建议反馈者:

  1. 在 manifest.json → App 模块权限配置中勾选 LivePusher 后重新自定义基座运行;
  2. 将 muted 与 enable-camera 问题拆分为两条 issue,并补充完整复现路径(含 start/stop 时序、是否重启推流、CDN 缓存时长等)。
内容为 AI 生成,仅供参考

要回复问题请先登录注册