From d03c15d15c36f005eab57b57a16920f6e5f12ad6 Mon Sep 17 00:00:00 2001 From: Sebastian Kaspari Date: Tue, 13 Aug 2019 22:02:20 +0200 Subject: [PATCH] Issue #4431: Integrate feature-media component (Nightly and debug builds only). (#4683) --- .../main/java/org/mozilla/fenix/FeatureFlags.kt | 14 ++++++++++++++ .../main/java/org/mozilla/fenix/components/Core.kt | 13 ++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt b/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt index afa528651..15f614b79 100644 --- a/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt +++ b/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt @@ -31,4 +31,18 @@ object FeatureFlags { * reload. */ const val pullToRefreshEnabled = false + + /** + * Integration of media features provided by `feature-media` component: + * - Background playback without the app getting killed + * - Media notification with play/pause controls + * - Audio Focus handling (pausing/resuming in agreement with other media apps) + * - Support for hardware controls to toggle play/pause (e.g. buttons on a headset) + * + * Behind nightly flag until all related Android Components issues are fixed and QA has signed + * off. + * + * https://github.com/mozilla-mobile/fenix/issues/4431 + */ + val mediaIntegration = nightly or debug } diff --git a/app/src/main/java/org/mozilla/fenix/components/Core.kt b/app/src/main/java/org/mozilla/fenix/components/Core.kt index 91571254d..d09f9bd6c 100644 --- a/app/src/main/java/org/mozilla/fenix/components/Core.kt +++ b/app/src/main/java/org/mozilla/fenix/components/Core.kt @@ -24,10 +24,13 @@ import mozilla.components.concept.engine.EngineSession.TrackingProtectionPolicy import mozilla.components.concept.engine.EngineSession.TrackingProtectionPolicy.Companion.SAFE_BROWSING_ALL import mozilla.components.concept.engine.mediaquery.PreferredColorScheme import mozilla.components.concept.fetch.Client +import mozilla.components.feature.media.MediaFeature import mozilla.components.feature.media.RecordingDevicesNotificationFeature +import mozilla.components.feature.media.state.MediaStateMachine import mozilla.components.feature.session.HistoryDelegate import mozilla.components.lib.crash.handler.CrashHandlerService import org.mozilla.fenix.AppRequestInterceptor +import org.mozilla.fenix.FeatureFlags import org.mozilla.fenix.ext.components import org.mozilla.fenix.test.Mockable import org.mozilla.fenix.utils.Settings @@ -78,7 +81,7 @@ class Core(private val context: Context) { historyTrackingDelegate = HistoryDelegate(historyStorage), preferredColorScheme = getPreferredColorScheme(), automaticFontSizeAdjustment = Settings.getInstance(context).shouldUseAutoSize, - suspendMediaWhenInactive = true + suspendMediaWhenInactive = !FeatureFlags.mediaIntegration ) GeckoEngine(context, defaultSettings, runtime) @@ -125,6 +128,14 @@ class Core(private val context: Context) { .whenGoingToBackground() .whenSessionsChange() } + + if (FeatureFlags.mediaIntegration) { + MediaStateMachine.start(sessionManager) + + // Enable media features like showing an ongoing notification with media controls when + // media in web content is playing. + MediaFeature(context).enable() + } } }