androidx / media

Jetpack Media3 support libraries for media use cases, including ExoPlayer, an extensible media player for Android
https://developer.android.com/media/media3
Apache License 2.0
1.74k stars 416 forks source link

ForegroundServiceStartNotAllowedException thrown when pressing play on chrome cast device #218

Open JaCobbMedia opened 1 year ago

JaCobbMedia commented 1 year ago

Media3 Version

1.0.0-beta03

Devices that reproduce the issue

Devices that do not reproduce the issue

No response

Reproducible in the demo app?

Not tested

Reproduction steps

Managed to reproduce it on UAMP media3 branch

  1. Start UAMP app (media3 branch)
  2. Select any item to play
  3. Cast it to device
  4. Move app to background
  5. Lock device
  6. Press pause on chrome cast device
  7. Wait for few seconds
  8. Press play
  9. ForegroundServiceStartNotAllowedException is thrown

Might not happen instantly so repeat 6-8 steps few times with different wait times

Expected result

Should successfully start foreground service or at least not crash

Actual result

ForegroundServiceStartNotAllowedException is thrown

Media

Any media in the UAMP app

Bug Report

marcbaechinger commented 1 year ago

With local playback, a play command (MediaSession, PendingIntent) gets an exemption to be able to start a service in the foreground when playback resumes. This is obviously not possible when this is initiated on the remote cast device and the Android system is not aware of this.

Thanks for reporting.

JaCobbMedia commented 1 year ago

One of our users got same crash, but from a google quick search box (???), ControllerInfo in logs - controller = ControllerInfo {pkg=com.google.android.googlequicksearchbox, uid=10232}. Not really sure how you can control playback from search box, but case is pretty much the same as I described previously, user goes to background and presses play/pause on search box (???). Could this be the same issue as with Cast device @marcbaechinger ?

marcbaechinger commented 1 year ago

com.google.android.googlequicksearchbox is Google Assistant that is part of the search app. This is a known bug on Android 12 (S) that doesn't have an exemption for commands sent over media session.

JaCobbMedia commented 1 year ago

thank you for a quick answer @marcbaechinger . Can we expect fix with next release?

marcbaechinger commented 1 year ago

We can't fix that. It's a platform bug. We are working on a workaround to avoid the crash that will be part of the next release. With this the app won't crash but Assistant will still not be able to resume playback. We will update this issue when this lands on dev-v2 and when merged into the release branch.

JaCobbMedia commented 1 year ago

Ohh, anyways thank you for the info!