程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了无法在 webview_flutter 中加载相机大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决无法在 webview_flutter 中加载相机?

开发过程中遇到无法在 webview_flutter 中加载相机的问题如何解决?下面主要结合日常开发的经验,给出你关于无法在 webview_flutter 中加载相机的解决方法建议,希望对你解决无法在 webview_flutter 中加载相机有所启发或帮助;

我正在使用 webvIEw_Flutter: ^0.3.15+1 用于 Flutter(here) 中的应用内浏览器,我想打开这个带有摄像头的 URL check,但它没有按预期打开,也没有相机已加载到该网页上

webVIEw 页面代码

import 'package:Flutter/foundation.dart';
import 'package:Flutter/gestures.dart';
import 'package:Flutter/material.dart';
import 'package:webvIEw_Flutter/webvIEw_Flutter.dart';
import 'dart:async';

class ExamWebVIEw extends StatefulWidget {
  final PageController controller;
  final int destination;

  const ExamWebVIEw({Key key,this.controller,Key index,this.destination})
      : super(key: key);
  @overrIDe
  _ExamWebVIEwState createState() => _ExamWebVIEwState();
}

class _ExamWebVIEwState extends State<ExamWebVIEw> {
  Completer<WebVIEwController> _controller = Completer<WebVIEwController>();
  JavaScriptChannel _toasterJavaScriptChannel(BuildContext context) {
    return JavaScriptChannel(
        name: '_Toaster',onMessageReceived: (JavaScriptMessage message) {
          Scaffold.of(context).showSnackbar(
            Snackbar(content: Text(message.message)),);
        });
  }

  Widget build(BuildContext context) {
    return Scaffold(
        appbar: Appbar(
          Title: Center(
            child: Text("Exam"),),body: Column(
          children: <Widget>[
            Expanded(
              child: WebVIEw(
                initialUrl:
                    "https://therealtechwiz.github.io/project/facerecognition",gestureRecognizers: Set()
                  ..add(
                    Factory<VerticalDragGestureRecognizer>(
                      () => VerticalDragGestureRecognizer(),// Factory<VerticalDragGestureRecognizer>(
                //  () => VerticalDragGestureRecognizer()..onUpdate = (_) {},// ),initialmediaplaybackPolicy: automediaplaybackPolicy
                    .require_user_action_for_all_media_types,JavaScriptMode: JavaScriptMode.unrestricted,onWebVIEwCreated: (WebVIEwController webVIEwController) {
                  _controller.complete(webVIEwController);
                },JavaScriptChannels: <JavaScriptChannel>[
                  _toasterJavaScriptChannel(context),].toSet(),)
          ],));
  }
}

在 androID/app/src/main/AndroIDManifest.xml 中添加了这些权限

<uses-permission androID:name="androID.permission.CAMERA" />
 <uses-feature androID:name="androID.harDWare.camera" />
 <uses-feature androID:name="androID.harDWare.camera.autofocus" />
<uses-permission androID:name="androID.permission.INTERNET"/>

终端响应:

D/EgretLoader(23485): EgretLoader(Context context)
D/EgretLoader(23485): The context is not activity
W/ContentCatcher(23485): Failed to notify a WebVIEw
I/chromium(23485): [INFO:CONSolE(79)] "[object DOMException] please use the fiddle instead",source: https://therealtechwiz.github.io/project/facerecognition/script.Js (79)
I/chromium(23485): [INFO:CONSolE(1)] "Uncaught (in promise) Error: Failed to fetch: (404),from url: https://therealtechwiz.github.io/models/face_recognition_model-weights_manifest.Json",source: https://therealtechwiz.github.io/project/facerecognition/face-API.min.Js (1)
W/Choreographer(23485): Frame time is 0.077364 ms in the future!  Check that graphics HAL is generating vsync timestamps using the correct timebase.

得到这个输出:

无法在 webview_flutter 中加载相机

预期输出:can be seen here

无法在 webview_flutter 中加载相机

任何人都可以看到并建议我修复的解决方案

解决方法

这样做的原因是您需要在加载 webview 和 setMediaPlaybackRequiresUserGesturefalsewebView's 设置之前请求摄像头/麦克风权限。

    webview.getSettings().setMediaPlaybackRequiresUserGesture(false);

我不相信 webview_flutter 默认会这样做,所以你需要 fork 插件并更改代码才能做到这一点。

我在使用 url_launcher 时遇到了类似的问题,不得不将它分叉并添加一些自定义代码来处理 Whereby 集成(对于 ios,WKWebView 将不起作用 - 您将需要 SFSafariViewController)。

你可以在这里找到我的版本

  url_launcher: #^5.4.2
    git: 
      url: git://github.com/yokoboko/url_launcher.git
      path: url_launcher

大佬总结

以上是大佬教程为你收集整理的无法在 webview_flutter 中加载相机全部内容,希望文章能够帮你解决无法在 webview_flutter 中加载相机所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: