Player still stops on 1.5.1 (since v1.0.4): foreground service dropped 10 minutes after a track change
Thanks @maxrave-dev for the audio-focus fix in core f293309 (1.5.0): that part of #2022 is now fixed. But I found another cause of music stopping, still present in 1.5.1 (Galaxy S23, Android 16, FOSS APK).
What I can observe (3 sessions tonight, same pattern each time): exactly 10 minutes after a track change, the foreground service flag is silently removed while music is still playing. About a minute later Android stops the service as idle, the app loses network, and playback starves at the next track. This leads to music stopping after 4-5 songs, as observed by @Lunar-Flame69 @MrDaraku @Allzweck @Prosto-Pasha @afabmoro97 @dafcavservicios @okcomputerfan.
20:54:54.261 D CrossfadeExoPlayerAdapter: End of stream reached <- track change, playing fine
21:04:54.330 D NotificationService: removeFlagFromNotificationLocked
pkg = com.maxrave.simpmusic notificationId = 200, flag = 64 <- +10:00.07: FGS dropped mid-track
21:05:42.245 W System.err: android_getaddrinfo failed: EAI_NODATA <- idle app loses network
21:05:54.325 W ActivityManager: Stopping service due to app idle:
u0a252 ... com.maxrave.simpmusic/...SimpleMediaService <- +1 min: service stopped
21:08:30.740 E ExoPlayerImplInternal: ... Failed to resolve stream URL <- next track starves
dumpsys activity services confirms it: isForeground=true at session start, silently false mid-playback, no pause anywhere in the log. The other two sessions show the same 10-minute delta (20:24:49 to 20:34:49, and one at 19:56:08).
My best guess at the mechanism: media3 1.9+ keeps the foreground service alive with a "user engaged" check plus a 10-minute grace timer. During a track swap, loadAndPlayTrackInternal swaps the ForwardingPlayer delegate and notifies MediaSession while the promoted precached player still has playWhenReady=false (play() comes a few lines later). That brief "not playing" sample could arm the timer, and the cancellation on re-engagement seems to never happen, maybe because media3's internal controller snapshot goes stale after the delegate swap. I'm not sure about the exact media3 internals here.
Possible fixes:
- In
loadAndPlayTrackInternal, callplay()beforeswapDelegate()/notifyMediaItemChanged(), so MediaSession never observesplayWhenReady=falseduring a swap (the crossfade path already does this). - In
SimpleMediaService.onUpdateNotification, forcestartInForegroundRequired = truewheneversession.playeris actually playing, which should self-heal any wrong demotion within seconds.
Same symptom: #2222 (open), #2155, and older: #1995, #1983, #1965, #1948, #1894, #1847, #1818, #1386.
+1 still happening with me | v1.5.1, LineageOS 22.2, Android 15, Motorola G7 Plus, FOSS APK.
thanks man for explaining better 🙏
I attempted a fix: maxrave-dev/core#10. Tested the patched build on my S23 (Android 16): more than 1 hour of uninterrupted background playback with 14 track changes, where 1.5.1 always stopped within ~15 minutes. The foreground service now stays up the whole time (isForeground=true throughout, and the flag = 64 removal no longer appears in logcat).
Update: had more than 6h of uninterrupted music with this fix https://github.com/maxrave-dev/core/pull/10.
Continua a bloccarsi anche nella versione 1.6.0
Problem still appears with version 2.0.0, but less frequent, I think after 1h. But even if I have the app in foreground it happens, like when in a car.
Still reproduces on 2.0.0 (versionCode 57), tested today on a Galaxy S23 (SM-S911B), Android 16, stock release build. The behaviour is unchanged.
Repro
- Start a playlist or radio with several tracks.
- Let one track finish so a transition happens. Call that time T.
- Press home, screen off. Do not open the app again: opening it rescues the process and hides the symptom.
- Leave the phone alone.
Ten minutes after that transition, the foreground service flag is removed while audio is still playing:
06:42:13 CrossfadeExoPlayerAdapter: End of stream reached
06:42:13 CrossfadeExoPlayerAdapter: Using precached player for TRACK_B
06:46:05 CrossfadeExoPlayerAdapter: Using precached player for TRACK_C
06:51:03 CrossfadeExoPlayerAdapter: Using precached player for TRACK_D
06:52:13 NotificationService: removeFlagFromNotificationLocked pkg = com.maxrave.simpmusic notificationId = 200, flag = 64
06:53:13 ActivityManager: Stopping service due to app idle: u0a417 com.maxrave.simpmusic/com.maxrave.media3.service.SimpleMediaService
The strip lands ten minutes to the second after the 06:42:13 transition. The later transitions at 06:46:05 and 06:51:03 do not cancel or re-arm it, which is the stale MediaController snapshot described in the original report.
I sampled dumpsys activity services com.maxrave.simpmusic every 30 seconds alongside the session state. The service loses foreground status while the track position keeps advancing normally:
06:52:10 isForeground=true state=PLAYING(3), position=65621
06:52:40 isForeground=<gone> state=PLAYING(3), position=95531
06:53:10 isForeground=<gone> state=PLAYING(3), position=125538
It never prints isForeground=false. The line disappears from the ServiceRecord altogether, which is how Android reports a service that is no longer foreground. Before and after, same service:
before: isForeground=true foregroundId=200 types=0x00000002
after: (no isForeground line) startForegroundCount=2 createdFromFg=true
Position went 65621 to 95531 to 125538, so music was audibly playing throughout.
A minute after the strip the service is idle-stopped, and a few minutes later the app loses network:
06:58:21 System.err: java.net.UnknownHostException: Unable to resolve host "music.youtube.com"
06:58:21 Stream: Failed to resolve stream URL for TRACK_H
Two new details
The demotion is permanent for the life of the service. Reopening the app pulls the process back to the foreground, but the service itself stays demoted (startForegroundCount stays at 2, and the isForeground line never returns). So the self-heal in onUpdateNotification really is needed.
The network loss is aimed at SimpMusic specifically, it is not a Wi-Fi problem. Over a three minute window, every DNS failure on the device belonged to SimpMusic and none to any other app. As a control I toggled airplane mode later on, and several unrelated apps failed together, which looks completely different.
The process is never killed on this device. It keeps playing from buffer until the next track needs the network, which is why it always stops between songs rather than mid-song.
maxrave-dev/core#10 still fixes this, my phone works for hours with it applied. It has been open without review since 2026-07-09.
Track IDs replaced with TRACK_x placeholders.
@maxrave-dev could you take a look at this one? It needs your decision, so the bot won't answer it on its own.
@Dollarius I fixxed in 15266ec9cf21b28ded58c86c980ef04372b028a7 core https://github.com/maxrave-dev/SimpMusic/commit/15266ec9cf21b28ded58c86c980ef04372b028a7
Thanks! I'm looking forward to testing this on the next release, and then I'll close this issue.
I compiled the dev branch myself: fixed on a FOSS build of dev (91ec84b3, which includes 15266ec), Galaxy S23. I repeated my 2.5.0 repro twice: screen off right after a track change, phone treated as unplugged, 16 minutes each. Both times the service stayed in the foreground and played through every track change. On 2.5.0 it lost its foreground status at 10 minutes and stopped.
Thanks a lot @maxrave-dev for fixing this!
Closing.
Fixed in 2.6.0 (maxrave-dev/core@cca36ea, maxrave-dev/core@9df595d): the FOSS build keeps its foreground service when playback moves to a precached track, so Android no longer stops the player about 10 minutes later.