Flutter Agora Ui视频默认禁用

wnavrhmk  于 2023-06-24  发布在  Flutter
关注(0)|答案(1)|浏览(192)

我有一个视频通道代码,用户可以在一个通道上进行视频通话。我需要做的是当用户第一次来的时候,然后视频被关闭,直到用户想要启用它。现在它的默认摄像头是开着的,但我需要默认关闭

class VideoPage extends StatefulWidget {
  final roomid;
  const VideoPage({Key? key, this.roomid}) : super(key: key);

  @override
  State<VideoPage> createState() => _VideoPageState();
}

class _VideoPageState extends State<VideoPage> {
  bool videoIconEnable = false;
  bool enableVideo = false;

  final AgoraClient client = AgoraClient(
    agoraEventHandlers: (AgoraRtcEventHandlers(leaveChannel: (state) {
      Get.back();
    })),
    // videoDisabled: true,
    agoraConnectionData: AgoraConnectionData(
        appId: "e0700cba7e944848a29e****",
        channelName: "***",
        username: "asdrere",
        tempToken:
            "006e0700cba7****3d9b2IACy1MhejFRYOOqTS9FVTDH+2aMwmwVbbHjpVlqMbEY1ubd/Wk0AAAAAEACGukDPURzvYgEAAQBRHO9i"),
  );

  @override
  void initState() {
    super.initState();
    initAgora();
  }

  void initAgora() async {
    await client.initialize();
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    // client.leaveChannel();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
            backgroundColor: Colors.white,
            // leading: GestureDetector(
            //   onTap: () {
            //     Get.back();
            //   },
            //   child: Icon(
            //     Icons.arrow_back_ios,
            //     color: Colors.grey,
            //   ),
            // ),
            actions: [
              videoIconEnable
                  ? GestureDetector(
                      onTap: () async {
                        setState(() {
                          enableVideo = true;
                        });
                      },
                      child: Padding(
                        padding: const EdgeInsets.all(8.0),
                        child: Icon(
                          Icons.video_call,
                          color: kPrimarycolor,
                          size: 30,
                        ),
                      ),
                    )
                  : Container()
            ],
            title: Text(
              'On Call',
              style: TextStyle(
                  color: kPrimarycolor,
                  fontSize: 30,
                  fontWeight: FontWeight.bold),
            )),
        body: SafeArea(
          child: Stack(
            children: [
              TweenAnimationBuilder<Duration>(
                  duration: Duration(seconds: 10),
                  tween:
                      Tween(begin: Duration(seconds: 10), end: Duration.zero),
                  onEnd: () {
                    setState(() {
                      videoIconEnable = true;
                    });
                    print('Timer ended');
                  },
                  builder:
                      (BuildContext context, Duration value, Widget? child) {
                    final minutes = value.inMinutes;
                    final seconds = value.inSeconds % 60;
                    return Padding(
                        padding: const EdgeInsets.symmetric(vertical: 5),
                        child: Text('Video will start in$minutes:$seconds',
                            textAlign: TextAlign.center,
                            style: TextStyle(
                                color: Colors.black,
                                fontWeight: FontWeight.bold,
                                fontSize: 30)));
                  }),
              videoIconEnable
                  ? AgoraVideoViewer(
                      client: client,
                      layoutType: Layout.floating,
                      

                      enableHostControls:
                          true, // Add this to enable host controls
                    )
                  : Container(),
              AgoraVideoButtons(
                client: client,
              ),
            ],
          ),
        ),
      ),
    );
  }
}

所有按钮工作正常,禁用,启用视频,但我需要视频假的默认值。

j2datikz

j2datikz1#

您可以使用agora ui kit切换视频。

await client.initialize();

client.sessionController.updateUserVideo(
   uid: client.agoraConnectionData.uid ?? 0,
   videoDisabled: !widget.videoEnabled);

 client.sessionController.value.copyWith(
     isLocalVideoDisabled:
         !(client.sessionController.value.isLocalVideoDisabled));
 await client.sessionController.value.engine?.muteLocalVideoStream(
     client.sessionController.value.isLocalVideoDisabled);

相关问题