From 698648f15d4c2297ebc478f4437f7d192e4810a6 Mon Sep 17 00:00:00 2001 From: daserge Date: Tue, 16 Aug 2016 21:22:32 +0300 Subject: [PATCH] CB-11013 IAB enabling background play of YouTube videos? Adds shouldPause feature to stop backgound audio --- README.md | 1 + src/android/InAppBrowser.java | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/README.md b/README.md index e1d81b8..9781ebc 100644 --- a/README.md +++ b/README.md @@ -109,6 +109,7 @@ instance, or the system browser. - __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. - __mediaPlaybackRequiresUserAction__: Set to `yes` to prevent HTML5 audio or video from autoplaying (defaults to `no`). + - __shouldPauseOnSuspend__: Set to `yes` to make InAppBrowser WebView to pause/resume with the app to stop background audio (this may be required to avoid Google Play issues like described in [CB-11013](https://issues.apache.org/jira/browse/CB-11013)). iOS only: diff --git a/src/android/InAppBrowser.java b/src/android/InAppBrowser.java index 38c3cbc..5a9b9af 100644 --- a/src/android/InAppBrowser.java +++ b/src/android/InAppBrowser.java @@ -87,6 +87,7 @@ public class InAppBrowser extends CordovaPlugin { private static final String CLEAR_SESSION_CACHE = "clearsessioncache"; private static final String HARDWARE_BACK_BUTTON = "hardwareback"; private static final String MEDIA_PLAYBACK_REQUIRES_USER_ACTION = "mediaPlaybackRequiresUserAction"; + private static final String SHOULD_PAUSE = "shouldPauseOnSuspend"; private InAppBrowserDialog dialog; private WebView inAppWebView; @@ -99,6 +100,7 @@ public class InAppBrowser extends CordovaPlugin { private boolean clearSessionCache = false; private boolean hadwareBackButton = true; private boolean mediaPlaybackRequiresUserGesture = false; + private boolean shouldPauseInAppBrowser = false; /** * Executes the request and returns PluginResult. @@ -265,6 +267,26 @@ public class InAppBrowser extends CordovaPlugin { closeDialog(); } + /** + * Called when the system is about to start resuming a previous activity. + */ + @Override + public void onPause(boolean multitasking) { + if (shouldPauseInAppBrowser) { + inAppWebView.onPause(); + } + } + + /** + * Called when the activity will start interacting with the user. + */ + @Override + public void onResume(boolean multitasking) { + if (shouldPauseInAppBrowser) { + inAppWebView.onResume(); + } + } + /** * Called by AccelBroker when listener is to be shut down. * Stop listener. @@ -514,6 +536,10 @@ public class InAppBrowser extends CordovaPlugin { clearSessionCache = cache.booleanValue(); } } + Boolean shouldPause = features.get(SHOULD_PAUSE); + if (shouldPause != null) { + shouldPauseInAppBrowser = shouldPause.booleanValue(); + } } final CordovaWebView thatWebView = this.webView;