Skip to content
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

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,18 @@ public boolean getEnableZoomControls()
return enabled;
}

@Kroll.method(runOnUiThread=true) @Kroll.setProperty(runOnUiThread=true)
public void setMediaPlaybackRequiresUserGesture(boolean enabled)
{
setPropertyAndFire(TiC.PROPERTY_MEDIA_PLAYBACK_REQUIRES_USER_GESTURE, enabled);
}

@Kroll.method @Kroll.getProperty
public boolean getMediaPlaybackRequiresUserGesture()
{
return TiConvert.toBoolean(getProperty(TiC.PROPERTY_MEDIA_PLAYBACK_REQUIRES_USER_GESTURE), true);
}

public void clearBasicAuthentication()
{
fusername = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,11 @@ public TiUIWebView(TiViewProxy proxy)
settings.setBuiltInZoomControls(enableZoom);
settings.setSupportZoom(enableZoom);

if (Build.VERSION.SDK_INT >= TiC.API_LEVEL_JELLY_BEAN_MR1 &&
proxy.hasProperty(TiC.PROPERTY_MEDIA_PLAYBACK_REQUIRES_USER_GESTURE)) {
settings.setMediaPlaybackRequiresUserGesture(TiConvert.toBoolean(proxy.getProperty(TiC.PROPERTY_MEDIA_PLAYBACK_REQUIRES_USER_GESTURE)));
}

if (Build.VERSION.SDK_INT >= TiC.API_LEVEL_JELLY_BEAN) {
settings.setAllowUniversalAccessFromFileURLs(true); // default is "false" for JellyBean, TIMOB-13065
}
Expand Down
6 changes: 6 additions & 0 deletions android/titanium/src/java/org/appcelerator/titanium/TiC.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class TiC
public static final int API_LEVEL_HONEYCOMB = 11;
public static final int API_LEVEL_ICE_CREAM_SANDWICH = 14;
public static final int API_LEVEL_JELLY_BEAN = 16;
public static final int API_LEVEL_JELLY_BEAN_MR1 = 17;

public static final int PERMISSION_CODE_CALENDAR = 100;
public static final int PERMISSION_CODE_CAMERA = 101;
Expand Down Expand Up @@ -3182,6 +3183,11 @@ public class TiC
*/
public static final String PROPERTY_DEPARTMENT = "department";

/**
* @module.api
*/
public static final String PROPERTY_MEDIA_PLAYBACK_REQUIRES_USER_GESTURE = "mediaPlaybackRequiresUserGesture";

public static final String SIZE_AUTO = "auto";
public static final String URL_APP_PREFIX = "app://";
public static final String URL_APP_SCHEME = "app";
Expand Down
6 changes: 6 additions & 0 deletions apidoc/Titanium/UI/WebView.yml
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,12 @@ properties:
type: Dictionary
platforms: [android,iphone,ipad]
since: "6.1.0"
- name: mediaPlaybackRequiresUserGesture
summary: Sets whether the WebView requires a user gesture to play media.
type: Boolean
platforms: [android, iphone, ipad]
since: "6.2.0"
Copy link
Collaborator

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.

default: true


examples:
Expand Down
8 changes: 8 additions & 0 deletions iphone/Classes/TiUIWebView.m
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,14 @@ - (void)setKeyboardDisplayRequiresUserAction_:(id)value
[[self webview] setKeyboardDisplayRequiresUserAction:[TiUtils boolValue:value def:YES]];
}

- (void)setMediaPlaybackRequiresUserGesture_:(id)value
{
ENSURE_TYPE(value, NSNumber);
[[self proxy] replaceValue:value forKey:@"mediaPlaybackRequiresUserGesture" notification:NO];

[[self webview] setMediaPlaybackRequiresUserAction:[TiUtils boolValue:value def:YES]];
}

#pragma mark WebView Delegate

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
Expand Down