0

我正在尝试在颤振中控制 facebook 视频,我正在使用 flutter_inappwebview。当我在 chrome 中运行 html(下面,在我的代码中)时,它就像魅力一样,但是当我在我的应用程序中使用它时,我得到了错误,而且我无法点击视频,所以它不会播放。

我尝试过使用<iframe>,我可以轻松地单击视频并播放/暂停它,但我想要视频控制器,以便我可以控制我的应用程序中的视频。

这是我的代码

class PLAYER extends StatefulWidget {
  const PLAYER({Key? key}) : super(key: key);

  @override
  _PLAYERState createState() => _PLAYERState();
}

class _PLAYERState extends State<PLAYER> {
  String player = ''' 
  <html>
  <body>
  <script>
  window.fbAsyncInit = function() {
        FB.init({
          appId      : 'my adpp id',
          xfbml      : true,
          version    : 'v3.2'
        });
      var my_video_player;
  FB.Event.subscribe('xfbml.ready', function(msg) {
  console.log("readyy");
    if (msg.type === 'video') {
      my_video_player = msg.instance;
      var myEventHandler = my_video_player.subscribe('startedPlaying', function(e) {
  console.log("started playing");
  });
    }
  });}


  </script>
  <div id="fb-root"></div>
  <script async defer src="https://connect.facebook.net/en_US/sdk.js"></script>

  <div class="fb-video"    
     data-href="https://www.facebook.com/facebook/videos/10153231379946729/" 
     data-autoplay="false"
     data-width="100%" data-show-text="false" data-allowfullscreen="false">
  </div>
  </body>
  </html>
  ''';

  late InAppWebViewController controller;
  var txt = "text";

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: ListView(
        shrinkWrap: true,
        children: [
          Container(
            height: 200,
            child: InAppWebView(
              initialData: InAppWebViewInitialData(data: player),
              onConsoleMessage: (wc, log) {
                setState(() {
                  txt = txt + "\n\n\n\n\n\n" + log.message;
                });
              },
              onWebViewCreated: (webController) {
                controller = webController;
              },
            ),
          ),
          Padding(
            padding: const EdgeInsets.all(8.0),
            child: Text(txt),
          )
        ],
      ),
    );
  }
}

在我的应用程序中运行此代码时出现错误,

I/flutter (10098): {message: ErrorUtils caught an error:
I/flutter (10098): 
I/flutter (10098): Minified invariant #11793;  Params: about
I/flutter (10098): 
I/flutter (10098): Subsequent non-fatal errors won't be logged; 
4

0 回答 0