简体   繁体   English

不重新加载就无法使用 Flutter_WebRTC 包

[英]Unable to use Flutter_WebRTC package without reload

I am trying to use the package , flutter WebRTC.我正在尝试使用软件包flutter WebRTC。 I use it in the following manner:我按以下方式使用它:

  1. Declare the localRenderer.声明本地渲染器。
  2. Initialize it.初始化它。
  3. Call the getUserMedia function to get the stream.调用 getUserMedia 函数以获取流。
  4. Assign the srcObject of localRenderer to the stream.将 localRenderer 的 srcObject 分配给流。
  5. View the local renderer in RTCVideoView widget.在 RTCVideoView 小部件中查看本地渲染器。

I use 2 and 3 in the initState, and 4 within the getUserMedia.我在 initState 中使用 2 和 3,在 getUserMedia 中使用 4。

But, What I am facing is.但是,我面临的是。 At first the video does not appear.起初视频没有出现。 Until, reload it using r while debugging, it suddenly appears.直到,在调试时使用r重新加载它,它突然出现。

When in production reloading might not be possible.在生产中重新加载可能是不可能的。 Is there a way to view the video without reloading everytime?有没有办法每次都无需重新加载即可查看视频?

When assigning the srcObject of the localRenderer to the stream make sure you are doing that inside a setState .将 localRenderer 的 srcObject 分配给流时,请确保您在setState中执行此操作。

The function should look something like this:该函数应如下所示:

playVideoFromCamera() async {
    final constraints = {'video': true, 'audio': true};
    final stream = await navigator.mediaDevices.getUserMedia(constraints);
   setState(() {
      _localRenderer.srcObject = stream;
   });
}

and wrap things up in the initState并在 initState 中完成

@override
  void initState() {
    super.initState();
    initRenderers();
    playVideoFromCamera();
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM