Problem / Context
When the screen turns off or the player activity is backgrounded, playback pauses. Users want audio (e.g. music videos, concerts, "listening" to a series in bed) to keep playing with the screen off, with auto-advance to the next episode still working.
Upstream reference: jarnedemeulemeester#1206
Current behavior in our fork
app/phone/src/main/java/dev/jdtech/jellyfin/BasePlayerActivity.kt:43-53 — onPause() saves playWhenReady then forces viewModel.player.playWhenReady = false, pausing on any backgrounding including screen-off.
- A
MediaSession is built in onStart (:29) but released in onStop (:55-58); there is no foreground MediaSessionService, so the OS can kill playback and no playback notification exists.
Proposed implementation
- Add a media3
MediaSessionService (new class, e.g. player/local/.../PlaybackService.kt extending androidx.media3.session.MediaSessionService) that owns/holds the ExoPlayer and exposes a MediaSession. Register it in app/phone/src/main/AndroidManifest.xml with the androidx.media3.session.MediaSessionService intent filter and FOREGROUND_SERVICE_MEDIA_PLAYBACK permission.
- Settings key: add
playerBackgroundAudio: Boolean (default false) to settings/.../domain/AppPreferences.kt (+ Constants.kt key) and a toggle in the player settings screen (settings module State/Action/ViewModel + app/phone/.../presentation/settings).
- Gate the force-pause: in
BasePlayerActivity.onPause, only force playWhenReady = false when the background-audio setting is disabled.
- Keep the session alive in background: adjust
MediaSession lifecycle so it is not released while audio should continue; rely on the foreground-service notification to keep the process.
- Consider detaching the video surface when backgrounded (audio-only continuation) to avoid wasted decoding.
MVI / settings pieces
AppPreferences.playerBackgroundAudio (DataStore boolean).
- Settings screen:
SettingsAction.SetBackgroundAudio, state field, and a SettingsSwitchCard.
Acceptance criteria
Problem / Context
When the screen turns off or the player activity is backgrounded, playback pauses. Users want audio (e.g. music videos, concerts, "listening" to a series in bed) to keep playing with the screen off, with auto-advance to the next episode still working.
Upstream reference: jarnedemeulemeester#1206
Current behavior in our fork
app/phone/src/main/java/dev/jdtech/jellyfin/BasePlayerActivity.kt:43-53—onPause()savesplayWhenReadythen forcesviewModel.player.playWhenReady = false, pausing on any backgrounding including screen-off.MediaSessionis built inonStart(:29) but released inonStop(:55-58); there is no foregroundMediaSessionService, so the OS can kill playback and no playback notification exists.Proposed implementation
MediaSessionService(new class, e.g.player/local/.../PlaybackService.ktextendingandroidx.media3.session.MediaSessionService) that owns/holds theExoPlayerand exposes aMediaSession. Register it inapp/phone/src/main/AndroidManifest.xmlwith theandroidx.media3.session.MediaSessionServiceintent filter andFOREGROUND_SERVICE_MEDIA_PLAYBACKpermission.playerBackgroundAudio: Boolean(default false) tosettings/.../domain/AppPreferences.kt(+Constants.ktkey) and a toggle in the player settings screen (settings module State/Action/ViewModel +app/phone/.../presentation/settings).BasePlayerActivity.onPause, only forceplayWhenReady = falsewhen the background-audio setting is disabled.MediaSessionlifecycle so it is not released while audio should continue; rely on the foreground-service notification to keep the process.MVI / settings pieces
AppPreferences.playerBackgroundAudio(DataStore boolean).SettingsAction.SetBackgroundAudio, state field, and aSettingsSwitchCard.Acceptance criteria
postPlaybackProgress/postPlaybackStop) still fires correctly.FOREGROUND_SERVICE_MEDIA_PLAYBACKpermission declared; builds on the targeted API levels.