flutter-webrtc是不是在手机工作,但在浏览器工作

qf9go6mv  于 2023-03-24  发布在  Flutter
关注(0)|答案(1)|浏览(105)

flutter_webrc在浏览器上工作,但在手机上不工作。在调试控制台中,它给出

I/org.webrtc.Logging(5106):EglRenderer:持续时间:4001毫秒。收到的帧数:46.放弃:0.渲染:46.渲染fps:11.5.平均渲染时间:1359 us。平均交换缓冲时间:944 us.s.平均交换缓冲时间:982 us.:*
**

class _testState extends State<test> {
      final localRender=RTCVideoRenderer();
      @override
      void initState() {
        // TODO: implement initState
            getUserMedia();
    
        localRender.initialize();
        super.initState();
      }
      void dispose(){
        localRender.dispose();
        super.dispose();
      }
      
       getUserMedia() async {
      try {
        MediaStream stream = await navigator.mediaDevices.getUserMedia({"audio":true,"video":true});
        print(stream.toString());
        localRender.srcObject = stream;
        print("working");
      } catch (e) {
        print("Failed to get user media: $e");
      }
    
      }
      @override
      
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(title: Text("title"),),
          body: Container(
            height: 300,
            width: 200,
            child:RTCVideoView(localRender,mirror: true,)
          ),
        );
      }
    }
jchrr9hc

jchrr9hc1#

将这些行添加到androidManifest.xml:

<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

如果它不起作用,我认为你应该提供更多的信息来发现问题。

相关问题