在flutter中初始化window.navigator.getUserMedia时出错

问题描述

我正在尝试在我的代码中使用window.navigator.getUserMedia,并且这向我显示了奇怪的长错误。

这是我的代码:

 window.navigator.getUserMedia(audio: true,video: true).then((stream) {
      _localRenderer.srcObject = stream;
});

错误:

A value of type 'MediaStream (where MediaStream is defined in /home/klaus/developement/flutter/bin/cache/pkg/sky_engine/lib/html/html_dart2js.dart)' can't be assigned to a variable of type 'MediaStream (where MediaStream is defined in /home/klaus/developement/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_webrtc-0.3.2/lib/src/media_stream.dart)'.
Try changing the type of the variable,or casting the right-hand type to 'MediaStream (where MediaStream is defined in /home/klaus/developement/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_webrtc-0.3.2/lib/src/media_stream.dart)'

解决方法

使用MediaDevices代替导航器 像这样

MediaDevices.getUserMedia(constrains).then((MediaStream stream) {
  _localRenderer.srcObject = stream;
}

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...