微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决如何让 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 举报,一经查实,本站将立刻删除。