Allow HTML5 video autoplay inside AgentWeb (closes #339)#1085
Open
jim-daf wants to merge 1 commit intoJustson:androidxfrom
Open
Allow HTML5 video autoplay inside AgentWeb (closes #339)#1085jim-daf wants to merge 1 commit intoJustson:androidxfrom
jim-daf wants to merge 1 commit intoJustson:androidxfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Enables HTML5 video autoplay in AgentWeb by updating the default WebSettings configuration, addressing issue #339 where video.play() was blocked due to missing gesture exemptions.
Changes:
- Adds
WebSettings.setMediaPlaybackRequiresUserGesture(false)to the default settings pipeline. - Documents the motivation and context for the autoplay setting change inline.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // "play() can only be initiated by a user gesture" because the default | ||
| // gesture requirement was never lifted. Pages that auto-start video | ||
| // playback (most short-form video sites) need this off. | ||
| mWebSettings.setMediaPlaybackRequiresUserGesture(false); |
There was a problem hiding this comment.
WebSettings#setMediaPlaybackRequiresUserGesture was added in API 17. Since this module’s minSdkVersion is 14, calling it unconditionally can crash on API 14–16 with NoSuchMethodError. Please guard this call with a Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 check (or equivalent) so older devices skip it safely.
Suggested change
| mWebSettings.setMediaPlaybackRequiresUserGesture(false); | |
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { | |
| mWebSettings.setMediaPlaybackRequiresUserGesture(false); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Let HTML5 video autoplay inside AgentWeb
Closes #339
What changed
agentweb-core/src/main/java/com/just/agentweb/AbsAgentWebSettings.javaCall
WebSettings.setMediaPlaybackRequiresUserGesture(false)from the default settings pipeline. Without this, everyvideo.play()triggered by JavaScript on the loaded page was rejected by Chromium with the well-known message "play() can only be initiated by a user gesture", which is exactly what the reporter saw on the douyin reflow page.The existing call to
setMixedContentMode(MIXED_CONTENT_ALWAYS_ALLOW)already handles the "Mixed Content" half of the same trace. With both flags in place the same page now plays back normally.Key snippet
Notes
The flag is documented as having no effect for Web Audio in some Chromium versions. That is acceptable here because the issue is about HTML5
<video>playback. Apps that want to keep the Chromium default can overrideAgentWebSettingsImpl.toSettingand re-enable the gesture requirement.