0
Playback states & service states
Nite edited this page 2021-05-04 13:32:27 +02:00
- Service running: Service is running, but startForeground was not called. (Actually on current APIs this state would result in an Exception. MediaPlayerService is started with startForegroundService, and foreground services must call startForeground with a notification in ~5 secs. Also see this.)
- Service is running in Background: Service is running, but stopForeground was called.
- Service as Foreground: Service is running, startForeground was called, Notification is shown
- stopForeground: If we exit foreground, we can specify a flag, whether to remove, or to detach the notification.
If detached, the notification will stay, even when the service has been de-foregrounded - registerMediaButtonReceiver: With the newer architecture this is only possible if we have a service
Condition | Playback State | Service running | Service has notification | Service as Foreground | stop Foreground() | register MediaButtonReceiver |
---|---|---|---|---|---|---|
App starts, no resumable track | STOPPED | ✗ | ✗ | ✗ | ✗ | Only possible if service is running. |
App starts, with resumable track (1) | PAUSED | ✓ | ✓ | ✓ | ✗ | ✓ |
Active playing | PLAYING | ✓ | ✓ | ✓ | ✗ | ✓ |
Paused by the user | PAUSED | ✓ | ✓ | (2) | stopForeground(DETACH) | ✓ |
Playback has finished / idle (3) | STOPPED | ✗ | ✗ | ✗ | stopForeground() or stopForeground(DETACH) | Only possible if service is running. |
(1): This is the current logic, but #426 is about changing this. After #426 is implemented, the App will start in a simple STOPPED state.
(2): The current logic is that in the paused state the service remains in the foreground. The notification can't be dismissed, only with the "x".
The desired operation would be possibly that the service must detach the notification and go to background here. The notification can be dismissed by the user without the "x". Also resuming playback must bring the service back to foreground.
(3): Currently this also happens when the notification is dismissed with the "x".