Skip to content

Commit ef400fa

Browse files
committed
fix(AbsAgentWebSettings): allow media playback without user gesture (#339)
Resolves #339 Issue #339 reports that an embedded video on a page loaded in AgentWeb fails with: Failed to execute 'play' on 'HTMLMediaElement': API can only be initiated by a user gesture. The platform default for setMediaPlaybackRequiresUserGesture is true, and AbsAgentWebSettings.settings() never overrides it. Many embedded video players (TikTok/Douyin share pages, Twitter video, etc.) start playback programmatically and break under that default. This change calls mWebSettings.setMediaPlaybackRequiresUserGesture(false) in settings() so the platform's WebView allows programmatic playback, matching the behavior most in-app browsers want. The mixed-content half of the same issue (HTTP video on HTTPS page) is already handled by the existing setMixedContentMode(MIXED_CONTENT_ALWAYS_ALLOW) call further down in the same method.
1 parent 95d48cd commit ef400fa

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

agentweb-core/src/main/java/com/just/agentweb/AbsAgentWebSettings.java

100755100644
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ private void settings(WebView webView) {
6565
mWebSettings.setSupportZoom(true);
6666
mWebSettings.setBuiltInZoomControls(false);
6767
mWebSettings.setSavePassword(false);
68+
// Issue #339: HTMLMediaElement.play() throws "API can only be initiated by
69+
// a user gesture" for embedded video players that auto-play. Allow
70+
// programmatic playback so embedded players (e.g. share-page videos) work.
71+
mWebSettings.setMediaPlaybackRequiresUserGesture(false);
6872
if (AgentWebUtils.checkNetwork(webView.getContext().getApplicationContext())) {
6973
//根据cache-control获取数据。
7074
mWebSettings.setCacheMode(WebSettings.LOAD_DEFAULT);

0 commit comments

Comments
 (0)