You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Agora观众端黑屏但有声音问题修复(agora_rtc_engine 6.1.0 Flutter)

修复Flutter端Agora直播观众端黑屏问题

针对你遇到的观众端仅能听到声音无法看到画面的问题,以下是具体修复方案:

1. 修正远程视频的UID参数(核心问题)

你的观众端_videoPanel中,远程视频控制器错误使用了widget.config.userId(观众自身的UID),必须传入主播的UID才能加载主播画面。

修改步骤:

  • 在页面状态类中添加变量存储主播UID:
    int? _hostUid;
    
  • 在RtcEngineEventHandler的onUserJoined回调中记录主播UID(单主播场景直接赋值即可):
    onUserJoined: (RtcConnection connection, int remoteUid, int elapsed) {
      print("Remote user uid:$remoteUid joined the channel");
      setState(() {
        _hostUid = remoteUid;
      });
    },
    
  • 修正观众端的AgoraVideoView控制器:
    else {
      return _hostUid != null
          ? AgoraVideoView(
              controller: VideoViewController.remote(
                rtcEngine: agoraEngine,
                canvas: VideoCanvas(uid: _hostUid!),
                connection: RtcConnection(channelId: widget.config.channel),
              ),
            )
          : const Center(child: Text("等待主播上线"));
    }
    

2. 明确设置观众端的视频订阅选项

在观众端的ChannelMediaOptions中显式开启自动订阅视频,确保SDK行为符合预期:

options = ChannelMediaOptions(
  clientRoleType: ClientRoleType.clientRoleAudience,
  channelProfile: ChannelProfileType.channelProfileLiveBroadcasting,
  token: widget.config.token,
  autoSubscribeVideo: true,
  autoSubscribeAudio: true,
);

3. 验证权限配置

确保项目配置了必要的系统权限:

  • Android(android/app/src/main/AndroidManifest.xml):
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.INTERNET" />
    
  • iOS(ios/Runner/Info.plist):
    <key>NSCameraUsageDescription</key>
    <string>需要访问摄像头进行直播</string>
    <key>NSMicrophoneUsageDescription</key>
    <string>需要访问麦克风进行直播</string>
    

完成以上修改后,观众端即可正常加载主播的视频画面。

内容的提问来源于stack exchange,提问作者Abdulmalek Dery

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 03:24:56