Quellcode durchsuchen

add mediaPlaybackRequiresUserGesture parameter (#614)

Kevin Caicedo vor 6 Jahren
Ursprung
Commit
4235e3bef0

+ 2 - 0
android/src/main/java/com/flutter_webview_plugin/FlutterWebviewPlugin.java

@@ -113,6 +113,7 @@ public class FlutterWebviewPlugin implements MethodCallHandler, PluginRegistry.A
         boolean withJavascript = call.argument("withJavascript");
         boolean clearCache = call.argument("clearCache");
         boolean clearCookies = call.argument("clearCookies");
+        boolean mediaPlaybackRequiresUserGesture = call.argument("mediaPlaybackRequiresUserGesture");
         boolean withZoom = call.argument("withZoom");
         boolean displayZoomControls = call.argument("displayZoomControls");
         boolean withLocalStorage = call.argument("withLocalStorage");
@@ -145,6 +146,7 @@ public class FlutterWebviewPlugin implements MethodCallHandler, PluginRegistry.A
                 clearCache,
                 hidden,
                 clearCookies,
+                mediaPlaybackRequiresUserGesture,
                 userAgent,
                 url,
                 headers,

+ 5 - 0
android/src/main/java/com/flutter_webview_plugin/WebviewManager.java

@@ -364,6 +364,7 @@ class WebviewManager {
             boolean clearCache,
             boolean hidden,
             boolean clearCookies,
+            boolean mediaPlaybackRequiresUserGesture,
             String userAgent,
             String url,
             Map<String, String> headers,
@@ -398,6 +399,10 @@ class WebviewManager {
 
         webView.getSettings().setUseWideViewPort(useWideViewPort);
 
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
+            webView.getSettings().setMediaPlaybackRequiresUserGesture(mediaPlaybackRequiresUserGesture);
+        }
+
         // Handle debugging
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
             webView.setWebContentsDebuggingEnabled(debuggingEnabled);

+ 1 - 0
example/lib/main.dart

@@ -36,6 +36,7 @@ class MyApp extends StatelessWidget {
           return WebviewScaffold(
             url: selectedUrl,
             javascriptChannels: jsChannels,
+            mediaPlaybackRequiresUserGesture: false,
             appBar: AppBar(
               title: const Text('Widget WebView'),
             ),

+ 2 - 0
lib/src/base.dart

@@ -148,6 +148,7 @@ class FlutterWebviewPlugin {
     bool withJavascript,
     bool clearCache,
     bool clearCookies,
+    bool mediaPlaybackRequiresUserGesture,
     bool hidden,
     bool enableAppScheme,
     Rect rect,
@@ -174,6 +175,7 @@ class FlutterWebviewPlugin {
       'clearCache': clearCache ?? false,
       'hidden': hidden ?? false,
       'clearCookies': clearCookies ?? false,
+      'mediaPlaybackRequiresUserGesture': mediaPlaybackRequiresUserGesture ?? true,
       'enableAppScheme': enableAppScheme ?? true,
       'userAgent': userAgent,
       'withZoom': withZoom ?? false,

+ 3 - 0
lib/src/webview_scaffold.dart

@@ -17,6 +17,7 @@ class WebviewScaffold extends StatefulWidget {
     this.withJavascript,
     this.clearCache,
     this.clearCookies,
+    this.mediaPlaybackRequiresUserGesture = true,
     this.enableAppScheme,
     this.userAgent,
     this.primary = true,
@@ -49,6 +50,7 @@ class WebviewScaffold extends StatefulWidget {
   final bool withJavascript;
   final bool clearCache;
   final bool clearCookies;
+  final bool mediaPlaybackRequiresUserGesture;
   final bool enableAppScheme;
   final String userAgent;
   final bool primary;
@@ -158,6 +160,7 @@ class _WebviewScaffoldState extends State<WebviewScaffold> {
               withJavascript: widget.withJavascript,
               clearCache: widget.clearCache,
               clearCookies: widget.clearCookies,
+              mediaPlaybackRequiresUserGesture: widget.mediaPlaybackRequiresUserGesture,
               hidden: widget.hidden,
               enableAppScheme: widget.enableAppScheme,
               userAgent: widget.userAgent,