How do I make flutter_inappwebview load youtube page with video on pause?

751 Views Asked by At

I have been trying to follow the network abuse policy, which I don't know much about, any way you guys can help me understand this would be apreciated. I am trying to get the YouTube link to open but to not start playing video, I have already solved the problem where the video would keep playing on the background using Flutter_inappwebview instead of Flutte_webview but don't know how to keep it from playing at start. I am also not sure if there is other thing that I need to change to follow the policys of YouTube and Play Console.

This my code

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, String url) {},
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
0

There are 0 best solutions below