Skip to content

Commit 29c0480

Browse files
kevincaicedocharafau
authored andcommitted
add mediaPlaybackRequiresUserGesture parameter (#614)
1 parent 5e406a9 commit 29c0480

File tree

5 files changed

+13
-0
lines changed

5 files changed

+13
-0
lines changed

android/src/main/java/com/flutter_webview_plugin/FlutterWebviewPlugin.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ void openUrl(MethodCall call, MethodChannel.Result result) {
113113
boolean withJavascript = call.argument("withJavascript");
114114
boolean clearCache = call.argument("clearCache");
115115
boolean clearCookies = call.argument("clearCookies");
116+
boolean mediaPlaybackRequiresUserGesture = call.argument("mediaPlaybackRequiresUserGesture");
116117
boolean withZoom = call.argument("withZoom");
117118
boolean displayZoomControls = call.argument("displayZoomControls");
118119
boolean withLocalStorage = call.argument("withLocalStorage");
@@ -145,6 +146,7 @@ void openUrl(MethodCall call, MethodChannel.Result result) {
145146
clearCache,
146147
hidden,
147148
clearCookies,
149+
mediaPlaybackRequiresUserGesture,
148150
userAgent,
149151
url,
150152
headers,

android/src/main/java/com/flutter_webview_plugin/WebviewManager.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ void openUrl(
364364
boolean clearCache,
365365
boolean hidden,
366366
boolean clearCookies,
367+
boolean mediaPlaybackRequiresUserGesture,
367368
String userAgent,
368369
String url,
369370
Map<String, String> headers,
@@ -398,6 +399,10 @@ void openUrl(
398399

399400
webView.getSettings().setUseWideViewPort(useWideViewPort);
400401

402+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
403+
webView.getSettings().setMediaPlaybackRequiresUserGesture(mediaPlaybackRequiresUserGesture);
404+
}
405+
401406
// Handle debugging
402407
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
403408
webView.setWebContentsDebuggingEnabled(debuggingEnabled);

example/lib/main.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class MyApp extends StatelessWidget {
3636
return WebviewScaffold(
3737
url: selectedUrl,
3838
javascriptChannels: jsChannels,
39+
mediaPlaybackRequiresUserGesture: false,
3940
appBar: AppBar(
4041
title: const Text('Widget WebView'),
4142
),

lib/src/base.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ class FlutterWebviewPlugin {
148148
bool withJavascript,
149149
bool clearCache,
150150
bool clearCookies,
151+
bool mediaPlaybackRequiresUserGesture,
151152
bool hidden,
152153
bool enableAppScheme,
153154
Rect rect,
@@ -174,6 +175,7 @@ class FlutterWebviewPlugin {
174175
'clearCache': clearCache ?? false,
175176
'hidden': hidden ?? false,
176177
'clearCookies': clearCookies ?? false,
178+
'mediaPlaybackRequiresUserGesture': mediaPlaybackRequiresUserGesture ?? true,
177179
'enableAppScheme': enableAppScheme ?? true,
178180
'userAgent': userAgent,
179181
'withZoom': withZoom ?? false,

lib/src/webview_scaffold.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class WebviewScaffold extends StatefulWidget {
1717
this.withJavascript,
1818
this.clearCache,
1919
this.clearCookies,
20+
this.mediaPlaybackRequiresUserGesture = true,
2021
this.enableAppScheme,
2122
this.userAgent,
2223
this.primary = true,
@@ -49,6 +50,7 @@ class WebviewScaffold extends StatefulWidget {
4950
final bool withJavascript;
5051
final bool clearCache;
5152
final bool clearCookies;
53+
final bool mediaPlaybackRequiresUserGesture;
5254
final bool enableAppScheme;
5355
final String userAgent;
5456
final bool primary;
@@ -158,6 +160,7 @@ class _WebviewScaffoldState extends State<WebviewScaffold> {
158160
withJavascript: widget.withJavascript,
159161
clearCache: widget.clearCache,
160162
clearCookies: widget.clearCookies,
163+
mediaPlaybackRequiresUserGesture: widget.mediaPlaybackRequiresUserGesture,
161164
hidden: widget.hidden,
162165
enableAppScheme: widget.enableAppScheme,
163166
userAgent: widget.userAgent,

0 commit comments

Comments
 (0)