New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TIMOB-24581] Android: Support WebView.setMediaPlaybackRequiresUserGesture #8967
Conversation
Pretty sure this does work without the kroll method annotation, did you test this before? Also missing docs and test-case. |
if (Build.VERSION.SDK_INT >= 17) { | ||
getWebView().getSettings().setMediaPlaybackRequiresUserGesture(enabled); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This causes an "opcode" warning in the Android log on API Level 16 and lower. While harmless, we don't want to add any more noise to the log. Doing the following would be better...
`
public void setMediaPlaybackRequiresUserGesture(boolean enabled)
{
if (Build.VERSION.SDK_INT >= 17) {
TiUIWebView webView = getWebView();
if (webView != null) {
ApiLevel17.setMediaPlaybackRequiresUserGesture(webView.getSettings(), enabled);
}
}
}
private static class ApiLevel17
{
private ApiLevel17() {}
public static boolean setMediaPlaybackRequiresUserGesture(
android.webkit.WebSettings settings, boolean enabled)
{
if (settings != null) {
settings.setMediaPlaybackRequiresUserGesture(enabled);
}
}
}
`
The above solution is based on Google's blog post "How to have your (Cup)cake and eat it too". It takes advantage of Java's lazy class loading to avoid the opcode warning. Google's Android Supports library does something very similar to this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, ideally, this should be a property (getter/setter) in JavaScript and not a method. Having a setter without a getter is not good design (but a getter-only API is okay).
@hansemannn @jquick-axway I just did an update that define mediaPlaybackRequiresUserGesture as a property of TiWebView and included docs. I also add here a test-case. Please check
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cleaned PR
CR: PASS
👍
@bduyng @garymathews The test case is a bit unclear to me what should I be looking out for. I looked at the documentation as well but I am still confused on how to test this. |
@bduyng , @garymathews - when I have the property to false & I do a tap, swipe etc in the webview the video does not play. What's it supposed to do ? |
This is what I understand... and I could be wrong... On Android, a WebView cannot play an embedded video via the JavaScript in the HTML while the So, setting this to |
@hansemannn can I know the reason why this PR still not merge in 6.2.2.GA? are there any things that I can do here to have it in 6.3.0 on the end of the month? Thanks!! |
@bduyng The QE-testing was not completed and then overwhelmed by the other releases (Android O, iOS 11). Also it does not have parity with iOS so far, which we are trying to focus on more before adding anything platform-specific. Isn't it something like "autoplay"? If so, we could probably do an iOS / Windows parity easily and get it done. Sorry for the inconvenience! EDIT: There is mediaPlaybackRequiresUserAction:
This is exactly what we need if I'm correct? |
@hansemannn you mean it can be done quickly if we support for both iOS and Android? I think I can add mediaPlaybackRequiresUserAction for iOS easily |
Generated by 🚫 dangerJS |
@hansemannn I updated the code to support |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix the docs, then it should be good to go.
summary: Sets whether the WebView requires a user gesture to play media. | ||
type: Boolean | ||
platforms: [android, iphone, ipad] | ||
since: "6.2.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use "7.0.0" instead. 6.2.0 is already shipped, 6.3.0 is already in RC next week + iOS 11 focussed and the next one after that is 7.0.0.
This does not work on android. After the app launches & clicking the webview nothing happens. |
Upgrade and support for me the new version features |
@bduyng @garymathews Are you able to address the QE comments? I will need to reschedule it for now. |
Closing pull request due to inactivity for now. @bduyng If you are able to address the review comments, we are happy to re-schedule it again! |
Titanium.UI.WebView.mediaPlaybackRequiredUserGesture
propertyTEST CASE
JIRA Ticket