media icon indicating copy to clipboard operation
media copied to clipboard

Unable to resume playback in onPlayWhenReadyChanged (Player.Listener)

Open y20k opened this issue 2 years ago • 1 comments

Media3 Version

1.0.0-beta02

Devices that reproduce the issue

  • Emulator Pixel 5 API 33

Devices that do not reproduce the issue

No response

Reproducible in the demo app?

Not tested

Reproduction steps

  1. in a MediaSessionService create a Player with the attribute setPauseAtEndOfMediaItems(true)
  2. start playback of MediaItem A
  3. unbind the service from its activty (kill the activity for example)
  4. listen in onPlayWhenReadyChanged (Player.Listener) for the reason (int) Player.PLAY_WHEN_READY_CHANGE_REASON_END_OF_MEDIA_ITEM
  5. load a new MediaItem B when Player.PLAY_WHEN_READY_CHANGE_REASON_END_OF_MEDIA_ITEM
  6. start playback of new *MediaItem` B

Expected result

Player resumes playback with the MediaItem B.

Actual result

The app crashes and throws ForegroundServiceStartNotAllowedException (android.app.ForegroundServiceStartNotAllowedException: startForegroundService() not allowed due to mAllowStartForeground false: service org.y20k.escapepod/.PlayerService).

Problem / my explanation: setPauseAtEndOfMediaItems(true) pauses the player. If the service is not bound to an activity and playback is paused, media3 makes the service call stopForeground(true) - probably here.

I think, once paused a MediaSessionService cannot start playback again by itself. A solution might be #45.

Media

Not applicable

Bug Report

  • [X] You will email the zip file produced by adb bugreport to [email protected] after filing this issue.

y20k avatar Aug 02 '22 09:08 y20k

I just wanted to let you know that I found a solution to my specific problem. The problem

once paused a MediaSessionService cannot start playback again by itself

might still be an issue for other uses cases than mine.

y20k avatar Aug 03 '22 15:08 y20k

Thanks for the detailed report.

You are mentioning issue #45 that has some comments explaining the design decision of taking the service off the foreground when the player is paused by default. The justification for this is mainly system health.

By default means that an app can override MediaSessionService.updateNotification(MediaSession) and manage foreground handling itself.

marcbaechinger avatar Aug 18 '22 00:08 marcbaechinger

Hi @marcbaechinger

Thanks for explaining the default behavior and the customization options to circumvent the problem I observed.

This is not a bug.

y20k avatar Aug 18 '22 12:08 y20k