a261442315 2024-04-08 11:12 采纳率: 50%
浏览 6
已结题

腾讯云直播updateRemoteVideo报错

腾讯云直播updateRemoteVideo报错
在html中点击atherList中的用户列表,将id传输后更新视频在canvasView上,但atherList中可以看到用户的实时画面,点击后却报错INVALID_OPERATION: cannot updateRemoteVideo because remote user(userId: ...) does not publishing stream.

           <div ref="canvasView" class="centerVideo_mobile" style="width: 100%; height: 100%" :id="bigView"></div>
          <div class="atherList" ref="pohoneOther">
              <div :id="localOpenViewId" @click="itemClick(createRoomParams.userId)"></div>
              <div v-for="(item, index) in atherPeople" :key="index" :id="item.userId" @click="itemClick(item.userId)">
              </div>
            </div>





  mounted() {
     trtc.on(TRTC.EVENT.REMOTE_VIDEO_AVAILABLE, ({ userId, streamType }) => {
        if (
          userId.indexOf("down") == -1 &&
          userId.indexOf("up") == -1 &&
          this.bigView == ""
        ) {
          this.bigView = userId;
        }
      // 为了播放视频画面,您需在 DOM 中放置一个 HTMLElement,可以是一个 div 标签,假设其 id 为 `${userId}_${streamType}`
      const view = userId;
      this.$nextTick(() => {
        trtc.startRemoteVideo({
          userId,
          streamType,
          view,
          option: { fillMode: "cover" },
        });
      });
    });
}

methods: {
   async itemClick(i) {
      this.bigView = JSON.parse(JSON.stringify(i));
       await trtc.updateRemoteVideo({
          view: this.bigView,
          userId: this.bigView,
          streamType: "main",
      });
    },
  • 写回答

4条回答 默认 最新

  • a261442315 2024-04-08 17:21
    关注

    最终解决方案为使用try catch和updateLocalView

    this.$nextTick(async () => {
            try {
              await trtc.updateLocalVideo({ option: { mirror: true } });
            } catch (error) {
              console.warn(error, '我是切换错误1');
            }
            try {
              await trtc.updateRemoteVideo({
                view: localView,
                userId: localView,
                streamType: "main",
              });
            } catch (error) {
              console.warn(error, '我是切换错误2');
            }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

问题事件

  • 系统已结题 4月16日
  • 已采纳回答 4月8日
  • 创建了问题 4月8日

悬赏问题

  • ¥15 网络分析设施点无法识别
  • ¥15 状态图的并发态问题咨询
  • ¥15 PFC3D,plot
  • ¥15 VAE模型编程报错无法解决
  • ¥100 基于SVM的信息粒化时序回归预测,有偿求解!
  • ¥15 物体组批优化问题-数学建模求解答
  • ¥15 微信原生小程序tabBar编译报错
  • ¥350 麦克风声源定位坐标不准
  • ¥15 apifox与swagger使用
  • ¥15 egg异步请求返回404的问题