如何让 flutter_inappwebview 在暂停时加载带有视频的 youtube 页面?

问题描述

我一直在努力遵守网络滥用政策,我对此知之甚少,你们能帮助我理解的任何方式都会受到赞赏。 我正在尝试打开 YouTube 链接但不开始播放视频,我已经解决了使用 Flutter_inappwebview 而不是 Flutte_webview 在后台继续播放视频的问题,但不知道如何防止它在开始时播放.我也不确定是否还有其他需要更改的地方以遵守 YouTube 和 Play 管理中心的政策。

这是我的代码

class podcastTab extends StatefulWidget {
  @override
  _podcastTabState createState() => _podcastTabState();
}

class _podcastTabState extends State<podcastTab> with WidgetsBindingObserver {
  InAppWebViewController webView;

  @override
  void initState() {
    WidgetsBinding.instance.addobserver(this);
    super.initState();
  }
  @override
  void dispose() {
    WidgetsBinding.instance.removeObserver(this);
    super.dispose();
  }
  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    print('state = $state');
    if (webView != null) {
      if (state == AppLifecycleState.paused) {
        webView.pauseTimers();
        if (Platform.isAndroid) {
          webView.android.pause();
        }
      } else {
        webView.resumeTimers();
        if (Platform.isAndroid) {
          webView.android.resume();
        }
      }
    }
  }
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          elevation: 0.0,backgroundColor: Colors.grey[900],leading: FlatButton(
            child: new Icon(
              Icons.arrow_back_ios_rounded,color: Colors.yellow,),onpressed: () {
              Navigator.pop(context);
            },body: Container(
          child: Column(
            children: <Widget>[
              Expanded(
                child: InAppWebView(
                  initialUrl:
                      "https://www.youtube.com/watch?v=R4sB74NJzcY&list=PLCxoHXWd63cwaD2ceIZGZU4QfkA0C0Tb_",initialHeaders: {},initialOptions: InAppWebViewGroupOptions(
                    crossplatform: InAppWebViewOptions(
                      debuggingEnabled: true,onWebViewCreated: (InAppWebViewController controller) {
                    webView = controller;
                  },onLoadStart:
                      (InAppWebViewController controller,String url) {},onLoadStop:
                      (InAppWebViewController controller,],);
  }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)