From ad8c19043e2bc290664a6da793aee014b6c936d8 Mon Sep 17 00:00:00 2001 From: Matt Chowning Date: Thu, 16 Feb 2023 09:10:43 -0500 Subject: [PATCH 1/2] Tell media router to discover cast devices --- .../pocketcasts/ui/MainActivity.kt | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/au/com/shiftyjelly/pocketcasts/ui/MainActivity.kt b/app/src/main/java/au/com/shiftyjelly/pocketcasts/ui/MainActivity.kt index c84c04e8edd..d9d6a30ab30 100644 --- a/app/src/main/java/au/com/shiftyjelly/pocketcasts/ui/MainActivity.kt +++ b/app/src/main/java/au/com/shiftyjelly/pocketcasts/ui/MainActivity.kt @@ -30,6 +30,9 @@ import androidx.lifecycle.LiveData import androidx.lifecycle.LiveDataReactiveStreams import androidx.lifecycle.Observer import androidx.lifecycle.lifecycleScope +import androidx.mediarouter.media.MediaControlIntent +import androidx.mediarouter.media.MediaRouteSelector +import androidx.mediarouter.media.MediaRouter import androidx.transition.Slide import au.com.shiftyjelly.pocketcasts.R import au.com.shiftyjelly.pocketcasts.account.AccountActivity @@ -184,6 +187,12 @@ class MainActivity : private var videoPlayerShown: Boolean = false private var overrideNextRefreshTimer: Boolean = false + private var mediaRouter: MediaRouter? = null + private val mediaRouterCallback = object : MediaRouter.Callback() {} + private val mediaRouteSelector = MediaRouteSelector.Builder() + .addControlCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK) + .build() + private val childrenWithBackStack: List get() = supportFragmentManager.fragments.filterIsInstance() @@ -359,6 +368,8 @@ class MainActivity : handleIntent(intent, savedInstanceState) updateSystemColors() + + mediaRouter = MediaRouter.getInstance(this) } override fun openOnboardingFlow(onboardingFlow: OnboardingFlow) { @@ -374,6 +385,17 @@ class MainActivity : videoPlayerShown = false } } + + // Tell media router to discover routes + mediaRouter?.addCallback(mediaRouteSelector, mediaRouterCallback, MediaRouter.CALLBACK_FLAG_REQUEST_DISCOVERY) + } + + override fun onStop() { + super.onStop() + // Remove the callback flag CALLBACK_FLAG_REQUEST_DISCOVERY on stop by calling + // addCallback() again in order to tell the media router that it no longer + // needs to invest effort trying to discover routes of these kinds for now. + mediaRouter?.addCallback(mediaRouteSelector, mediaRouterCallback, 0) } private fun openFullscreenViewPlayer() { @@ -450,8 +472,8 @@ class MainActivity : override fun onDestroy() { super.onDestroy() - disposables.clear() + mediaRouter?.removeCallback(mediaRouterCallback) } @Suppress("DEPRECATION") From 4a9b17a8ddcf4b791e3bec50adc7bb28524b9e6d Mon Sep 17 00:00:00 2001 From: Matt Chowning Date: Thu, 16 Feb 2023 10:39:58 -0500 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d1c0bf2c9ab..f5835838639 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ 7.33 ----- +* Bug Fixes: + * Improve discovery of chromecast devices. + ([#780](https://github.com/Automattic/pocket-casts-android/issues/780)). 7.32 -----