2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-15 18:12:54 +00:00

Bug 1837158 - Media playback should be stopped when the app is destroyed.

This commit is contained in:
iorgamgabriel 2023-07-06 11:51:35 +03:00 committed by mergify[bot]
parent 3d1ed2735d
commit cff7694368

View File

@ -49,6 +49,7 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import mozilla.appservices.places.BookmarkRoot
import mozilla.components.browser.state.action.ContentAction
import mozilla.components.browser.state.action.MediaSessionAction
import mozilla.components.browser.state.action.SearchAction
import mozilla.components.browser.state.search.SearchEngine
import mozilla.components.browser.state.selector.getNormalOrPrivateTabs
@ -602,6 +603,7 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
components.core.pocketStoriesService.stopPeriodicSponsoredStoriesRefresh()
privateNotificationObserver?.stop()
components.notificationsDelegate.unBindActivity(this)
stopMediaSession()
}
override fun onConfigurationChanged(newConfig: Configuration) {
@ -872,6 +874,21 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
themeManager.applyStatusBarTheme(this)
}
// Stop active media when activity is destroyed.
private fun stopMediaSession() {
components.core.store.state.tabs.forEach {
it.mediaSessionState?.controller?.stop()
}
components.core.store.state.findActiveMediaTab()?.let {
components.core.store.dispatch(
MediaSessionAction.DeactivatedMediaSessionAction(
it.id,
),
)
}
}
/**
* Returns the [supportActionBar], inflating it if necessary.
* Everyone should call this instead of supportActionBar.