-
Notifications
You must be signed in to change notification settings - Fork 681
Description
Version
Media3 main branch
More version details
Summary
CastContext stops updating its CastState after the app returns from the background. When the app is backgrounded, the state changes from DEVICE_AVAILABLE to NO_DEVICES_AVAILABLE as expected, but on resume the state never returns to DEVICE_AVAILABLE and no further state callbacks are triggered. This leaves the app stuck in an incorrect cast-state until restart.
We are updating our UI based on this CastState, which is now partially broken.
Reproduce
To reproduce this, use the latest Media3 main branch and run the demo-session variant.
Within the MainActivity, add:
override fun onResume() {
super.onResume()
val snapshot = CastContext.getSharedInstance(this).castState
Log.d("[DEBUG]", "onResume: snapshot $snapshot")
}
And within the MainActivity.onCreate add:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
CastContext.getSharedInstance(this).addCastStateListener { state ->
Log.d("[DEBUG]", "addCastStateListener: $state <-----")
}
Now run the app and make sure that casting devices are available.
Steps:
- Observe that the listener prints CastState 2 (DEVICES_AVAILABLE).
- Background the app.
- Observe that the listener prints CastState 1 (NO_DEVICES_AVAILABLE) — as expected.
- Return the app to the foreground.
- Observe that the listener does not print a new state, and the snapshot printed in onResume is still CastState 1 (NO_DEVICES_AVAILABLE).
I might be missing something, but it seems that this listener is not working correctly. Any help is highly appreciated. Keep up the good work, and thanks in advance.
Devices that reproduce the issue
Samsung a51 Android 13
Pixel 7 Android 16
Devices that do not reproduce the issue
No response
Reproducible in the demo app?
Yes
Bug Report
- You will email the zip file produced by
adb bugreportto android-media-github@google.com after filing this issue.