CB-7786 Support mediaPlaybackRequiresUserAction on Android
This closes #132
This commit is contained in:
parent
be1f6076c2
commit
b51a4dc54e
@ -35,3 +35,30 @@ The details are explained there, but the important items are:
|
|||||||
- Run the tests so your patch doesn't break existing functionality.
|
- Run the tests so your patch doesn't break existing functionality.
|
||||||
|
|
||||||
We look forward to your contributions!
|
We look forward to your contributions!
|
||||||
|
|
||||||
|
The notes on [Commit Workflow](https://github.com/apache/cordova-coho/blob/master/docs/committer-workflow.md#commit-workflow) can be helpful even if you are not a committer.
|
||||||
|
|
||||||
|
## Running plugin tests
|
||||||
|
|
||||||
|
* clone and install [cordova-plugin-test-framework](https://github.com/apache/cordova-plugin-test-framework)
|
||||||
|
```
|
||||||
|
git clone git@github.com:apache/cordova-plugin-test-framework.git
|
||||||
|
```
|
||||||
|
* edit ```cordova-plugin-test-framework/www/assets/index.html``` and add the following line
|
||||||
|
```
|
||||||
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com http://cordova.apache.org http://google.co.uk https://google.co.uk 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
|
||||||
|
```
|
||||||
|
* create test project
|
||||||
|
```
|
||||||
|
cordova create plugintest
|
||||||
|
cd plugintest
|
||||||
|
cordova platform add android
|
||||||
|
cordova plugin add ../cordova-plugin-inappbrowser
|
||||||
|
cordova plugin add ../cordova-plugin-inappbrowser/tests
|
||||||
|
cordova plugin add ../cordova-plugin-test-framework
|
||||||
|
```
|
||||||
|
* edit ```config.xml``` and replace ```<content src="index.html" />``` with ```<content src="cdvtests/index.html" />```
|
||||||
|
* run application
|
||||||
|
```
|
||||||
|
cordova run
|
||||||
|
```
|
||||||
|
@ -100,6 +100,7 @@ instance, or the system browser.
|
|||||||
- __clearsessioncache__: set to `yes` to have the session cookie cache cleared before the new window is opened
|
- __clearsessioncache__: set to `yes` to have the session cookie cache cleared before the new window is opened
|
||||||
- __zoom__: set to `yes` to show Android browser's zoom controls, set to `no` to hide them. Default value is `yes`.
|
- __zoom__: set to `yes` to show Android browser's zoom controls, set to `no` to hide them. Default value is `yes`.
|
||||||
- __hardwareback__: set to `yes` to use the hardware back button to navigate backwards through the `InAppBrowser`'s history. If there is no previous page, the `InAppBrowser` will close. The default value is `yes`, so you must set it to `no` if you want the back button to simply close the InAppBrowser.
|
- __hardwareback__: set to `yes` to use the hardware back button to navigate backwards through the `InAppBrowser`'s history. If there is no previous page, the `InAppBrowser` will close. The default value is `yes`, so you must set it to `no` if you want the back button to simply close the InAppBrowser.
|
||||||
|
- __mediaPlaybackRequiresUserAction__: Set to `yes` to prevent HTML5 audio or video from autoplaying (defaults to `no`).
|
||||||
|
|
||||||
iOS only:
|
iOS only:
|
||||||
|
|
||||||
@ -110,7 +111,7 @@ instance, or the system browser.
|
|||||||
- __clearsessioncache__: set to `yes` to have the session cookie cache cleared before the new window is opened
|
- __clearsessioncache__: set to `yes` to have the session cookie cache cleared before the new window is opened
|
||||||
- __toolbar__: set to `yes` or `no` to turn the toolbar on or off for the InAppBrowser (defaults to `yes`)
|
- __toolbar__: set to `yes` or `no` to turn the toolbar on or off for the InAppBrowser (defaults to `yes`)
|
||||||
- __enableViewportScale__: Set to `yes` or `no` to prevent viewport scaling through a meta tag (defaults to `no`).
|
- __enableViewportScale__: Set to `yes` or `no` to prevent viewport scaling through a meta tag (defaults to `no`).
|
||||||
- __mediaPlaybackRequiresUserAction__: Set to `yes` or `no` to prevent HTML5 audio or video from autoplaying (defaults to `no`).
|
- __mediaPlaybackRequiresUserAction__: Set to `yes` to prevent HTML5 audio or video from autoplaying (defaults to `no`).
|
||||||
- __allowInlineMediaPlayback__: Set to `yes` or `no` to allow in-line HTML5 media playback, displaying within the browser window rather than a device-specific playback interface. The HTML's `video` element must also include the `webkit-playsinline` attribute (defaults to `no`)
|
- __allowInlineMediaPlayback__: Set to `yes` or `no` to allow in-line HTML5 media playback, displaying within the browser window rather than a device-specific playback interface. The HTML's `video` element must also include the `webkit-playsinline` attribute (defaults to `no`)
|
||||||
- __keyboardDisplayRequiresUserAction__: Set to `yes` or `no` to open the keyboard when form elements receive focus via JavaScript's `focus()` call (defaults to `yes`).
|
- __keyboardDisplayRequiresUserAction__: Set to `yes` or `no` to open the keyboard when form elements receive focus via JavaScript's `focus()` call (defaults to `yes`).
|
||||||
- __suppressesIncrementalRendering__: Set to `yes` or `no` to wait until all new view content is received before being rendered (defaults to `no`).
|
- __suppressesIncrementalRendering__: Set to `yes` or `no` to wait until all new view content is received before being rendered (defaults to `no`).
|
||||||
|
@ -85,6 +85,7 @@ public class InAppBrowser extends CordovaPlugin {
|
|||||||
private static final String CLEAR_ALL_CACHE = "clearcache";
|
private static final String CLEAR_ALL_CACHE = "clearcache";
|
||||||
private static final String CLEAR_SESSION_CACHE = "clearsessioncache";
|
private static final String CLEAR_SESSION_CACHE = "clearsessioncache";
|
||||||
private static final String HARDWARE_BACK_BUTTON = "hardwareback";
|
private static final String HARDWARE_BACK_BUTTON = "hardwareback";
|
||||||
|
private static final String MEDIA_PLAYBACK_REQUIRES_USER_ACTION = "mediaPlaybackRequiresUserAction";
|
||||||
|
|
||||||
private InAppBrowserDialog dialog;
|
private InAppBrowserDialog dialog;
|
||||||
private WebView inAppWebView;
|
private WebView inAppWebView;
|
||||||
@ -96,6 +97,7 @@ public class InAppBrowser extends CordovaPlugin {
|
|||||||
private boolean clearAllCache = false;
|
private boolean clearAllCache = false;
|
||||||
private boolean clearSessionCache = false;
|
private boolean clearSessionCache = false;
|
||||||
private boolean hadwareBackButton = true;
|
private boolean hadwareBackButton = true;
|
||||||
|
private boolean mediaPlaybackRequiresUserGesture = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes the request and returns PluginResult.
|
* Executes the request and returns PluginResult.
|
||||||
@ -473,6 +475,8 @@ public class InAppBrowser extends CordovaPlugin {
|
|||||||
showLocationBar = true;
|
showLocationBar = true;
|
||||||
showZoomControls = true;
|
showZoomControls = true;
|
||||||
openWindowHidden = false;
|
openWindowHidden = false;
|
||||||
|
mediaPlaybackRequiresUserGesture = false;
|
||||||
|
|
||||||
if (features != null) {
|
if (features != null) {
|
||||||
Boolean show = features.get(LOCATION);
|
Boolean show = features.get(LOCATION);
|
||||||
if (show != null) {
|
if (show != null) {
|
||||||
@ -490,6 +494,10 @@ public class InAppBrowser extends CordovaPlugin {
|
|||||||
if (hardwareBack != null) {
|
if (hardwareBack != null) {
|
||||||
hadwareBackButton = hardwareBack.booleanValue();
|
hadwareBackButton = hardwareBack.booleanValue();
|
||||||
}
|
}
|
||||||
|
Boolean mediaPlayback = features.get(MEDIA_PLAYBACK_REQUIRES_USER_ACTION);
|
||||||
|
if (mediaPlayback != null) {
|
||||||
|
mediaPlaybackRequiresUserGesture = mediaPlayback.booleanValue();
|
||||||
|
}
|
||||||
Boolean cache = features.get(CLEAR_ALL_CACHE);
|
Boolean cache = features.get(CLEAR_ALL_CACHE);
|
||||||
if (cache != null) {
|
if (cache != null) {
|
||||||
clearAllCache = cache.booleanValue();
|
clearAllCache = cache.booleanValue();
|
||||||
@ -660,6 +668,10 @@ public class InAppBrowser extends CordovaPlugin {
|
|||||||
settings.setBuiltInZoomControls(showZoomControls);
|
settings.setBuiltInZoomControls(showZoomControls);
|
||||||
settings.setPluginState(android.webkit.WebSettings.PluginState.ON);
|
settings.setPluginState(android.webkit.WebSettings.PluginState.ON);
|
||||||
|
|
||||||
|
if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
||||||
|
settings.setMediaPlaybackRequiresUserGesture(mediaPlaybackRequiresUserGesture);
|
||||||
|
}
|
||||||
|
|
||||||
//Toggle whether this is enabled or not!
|
//Toggle whether this is enabled or not!
|
||||||
Bundle appSettings = cordova.getActivity().getIntent().getExtras();
|
Bundle appSettings = cordova.getActivity().getIntent().getExtras();
|
||||||
boolean enableDatabase = appSettings == null ? true : appSettings.getBoolean("InAppBrowserStorageEnabled", true);
|
boolean enableDatabase = appSettings == null ? true : appSettings.getBoolean("InAppBrowserStorageEnabled", true);
|
||||||
@ -931,4 +943,3 @@ public class InAppBrowser extends CordovaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,5 +38,8 @@
|
|||||||
<button onclick="document.getElementById('player').play()"> play </button>
|
<button onclick="document.getElementById('player').play()"> play </button>
|
||||||
<button onclick="document.getElementById('player').pause()"> pause </button>
|
<button onclick="document.getElementById('player').pause()"> pause </button>
|
||||||
</div>
|
</div>
|
||||||
|
<script>
|
||||||
|
document.getElementById('player').play();
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -423,7 +423,11 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
|||||||
|
|
||||||
var video_tag_tests = '<h1>Video tag</h1>' +
|
var video_tag_tests = '<h1>Video tag</h1>' +
|
||||||
'<div id="openRemoteVideo"></div>' +
|
'<div id="openRemoteVideo"></div>' +
|
||||||
'Expected result: open successfully in InAppBrowser with an embedded video that works after clicking the "play" button.';
|
'Expected result: open successfully in InAppBrowser with an embedded video plays automatically on iOS and Android.' +
|
||||||
|
'<div id="openRemoteNeedUserNoVideo"></div>' +
|
||||||
|
'Expected result: open successfully in InAppBrowser with an embedded video plays automatically on iOS and Android.' +
|
||||||
|
'<div id="openRemoteNeedUserYesVideo"></div>' +
|
||||||
|
'Expected result: open successfully in InAppBrowser with an embedded video does not play automatically on iOS and Android but rather works after clicking the "play" button.';
|
||||||
|
|
||||||
var local_with_anchor_tag_tests = '<h1>Local with anchor tag</h1>' +
|
var local_with_anchor_tag_tests = '<h1>Local with anchor tag</h1>' +
|
||||||
'<div id="openAnchor1"></div>' +
|
'<div id="openAnchor1"></div>' +
|
||||||
@ -611,6 +615,12 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
|||||||
createActionButton('Remote Video', function () {
|
createActionButton('Remote Video', function () {
|
||||||
doOpen(videohtml, '_blank');
|
doOpen(videohtml, '_blank');
|
||||||
}, 'openRemoteVideo');
|
}, 'openRemoteVideo');
|
||||||
|
createActionButton('Remote Need User No Video', function () {
|
||||||
|
doOpen(videohtml, '_blank', 'mediaPlaybackRequiresUserAction=no');
|
||||||
|
}, 'openRemoteNeedUserNoVideo');
|
||||||
|
createActionButton('Remote Need User Yes Video', function () {
|
||||||
|
doOpen(videohtml, '_blank', 'mediaPlaybackRequiresUserAction=yes');
|
||||||
|
}, 'openRemoteNeedUserYesVideo');
|
||||||
|
|
||||||
//Local With Anchor Tag
|
//Local With Anchor Tag
|
||||||
createActionButton('Anchor1', function () {
|
createActionButton('Anchor1', function () {
|
||||||
@ -620,4 +630,3 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
|||||||
doOpen(localhtml + '#anchor2', '_blank');
|
doOpen(localhtml + '#anchor2', '_blank');
|
||||||
}, 'openAnchor2');
|
}, 'openAnchor2');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user