WebVideoPlayerController constructor

WebVideoPlayerController()

Implementation

WebVideoPlayerController()
    : super(WebPlayerValue(0, 0, 0, false, false, false, true)) {
  final PlatformWebViewControllerCreationParams params;
  if (WebViewPlatform.instance is WebKitWebViewPlatform) {
    params = WebKitWebViewControllerCreationParams(
      allowsInlineMediaPlayback: true,
      mediaTypesRequiringUserAction: const <PlaybackMediaTypes>{},
    );
  } else {
    params = const PlatformWebViewControllerCreationParams();
  }

  _webViewController = WebViewController.fromPlatformCreationParams(params)
    ..setJavaScriptMode(JavaScriptMode.unrestricted)
    ..addJavaScriptChannel("PlayerError", onMessageReceived: (params) {
      _errorListerner?.call(params.message.toString());
    })
    ..addJavaScriptChannel("PlayerInfo", onMessageReceived: (params) {
      print("Player Info Message : ${params.message}");
      List<String> mData = [
        "0",
        "0",
        "0",
        "false",
        "false",
        "false",
        "false"
      ];
      try {
        mData = (jsonDecode(params.message) as List)
            .map<String>((item) => item.toString())
            .toList();
      } catch (e) {
        print(e);
      }

      value = WebPlayerValue(
          double.tryParse(mData[0]) ?? 0,
          double.tryParse(mData[1]) ?? 0,
          double.tryParse(mData[2]) ?? 0,
          bool.tryParse(mData[3]) ?? false,
          value.isFullScreen,
          bool.tryParse(mData[4]) ?? false,
          bool.tryParse(mData[5]) ?? false);
    })
    ..setBackgroundColor(Colors.transparent)
    ..enableZoom(false);

  if (_webViewController.platform is AndroidWebViewController) {
    AndroidWebViewController.enableDebugging(true);
    (_webViewController.platform as AndroidWebViewController)
        .setMediaPlaybackRequiresUserGesture(false);
  }
}