SimpMusic icon indicating copy to clipboard operation
SimpMusic copied to clipboard

Player stops between tracks since v1.0.4 (still broken in v1.4.0)

Open Dollarius opened this issue 6 months ago • 20 comments

Duplicate Check

  • [x] I confirm I searched for existing reports and found no duplicates.

Describe the Bug

Music stops playing after 1-2 tracks and needs to be resumed manually. Worked in v1.0.3, broken since v1.0.4, still broken in v1.2.1. Similar symptoms are reported in #1894, #1948, #1965, #1983, #1847, #1818, #1386, #1995.

Three users independently downgraded to v1.0.3 and confirmed the bug disappears: @ptrkbmn (#1965), @woiang (#1948), @Xynel0 (#1948). @dmurthy-dev captured the failure with ADB in #1894 (see Log section).

The cause could be in commit 71ffebb in the core submodule ("integrate CrossfadeExoPlayerAdapter"). Before that commit, SimpleMediaService passed a single long-lived ExoPlayer to MediaLibrarySession. After it, the session gets CrossfadeExoPlayerAdapter.forwardingPlayer, which uses a separate ExoPlayer per track with one MediaItem per instance. At the end of each track that ExoPlayer hits Player.STATE_ENDED. DelegatingForwardingPlayer forwards this to the MediaSession listener. Media3's MediaLibraryService then drops the foreground-service notification, because from its view playback ended. The adapter swaps to the next pre-cached player and calls play(), but during the ~25 ms gap the FGS has already been cancelled. On HyperOS, OneUI and similar ROMs that gap is long enough for the OS to freeze the process.

In v1.0.3 the single ExoPlayer advanced tracks via its internal playlist, so STATE_ENDED was never fired between tracks. FGS stayed attached.

Possible directions to solve this:

  1. Suppress STATE_ENDED in DelegatingForwardingPlayer while a swap is pending (remap to STATE_BUFFERING).
  2. Call forwardingPlayer.swapDelegate(next) and next.play() before the current track hits STATE_ENDED, not after. triggerCrossfadeTransition already does this for crossfade.
  3. Keep the single-ExoPlayer path as default and only use CrossfadeExoPlayerAdapter when crossfade is enabled.

Steps to Reproduce

  1. Open a playlist of at least 5 tracks
  2. Start playback
  3. Lock the screen
  4. Player pauses on its own between tracks within 1-3 songs

Expected Behavior

Continuous playback across tracks, as in v1.0.3.

App Version

1.2.1

Android Version

16

Device Model

Samsung Galaxy S23

Custom ROM

  • [ ] I am using a custom ROM

Custom ROM Name (if applicable)

No response

Screenshots (optional)

No response

Log / Error Details

ADB capture from @dmurthy-dev in #1894:

MediaSessionService: playbackState=STOPPED
ActivityManager:    Cancel FGS notification … ChannelId:media_playback_channel
MediaSessionService: playbackState=PAUSED
ActivityManager:    pid 2644 sent binder code 31101 … to frozen apps, got error -74

Dollarius avatar May 11 '26 11:05 Dollarius

this issue happens on my Amazon Fire HD 8" (2022 model), but not on my phone (Redmi Note 12). Both devices with all updates.

dafcavservicios avatar May 11 '26 16:05 dafcavservicios

This is, quite simply, one of the best bug reports I have ever seen. Problem, diff, solution. Well done.

I went back to 1.03 on my s25 and the issue disappeared!

brendancarr avatar May 12 '26 18:05 brendancarr

I'm having the same problem. I've reverted to version 1.0.3. I'm hoping you can help resolve the issue. Thanks for everything, you guys are fantastic! You've created a wonderful app.

afabmoro97 avatar May 13 '26 14:05 afabmoro97

I have the same problem on the Pixel 8 and the Motorola Edge 50 Pro. After 4–5 songs in a locally downloaded playlist, it stops playing. Hope you fix it.

MrDaraku avatar May 19 '26 08:05 MrDaraku

This is such a good bug report. Thank you @Dollarius !! (And yes, i'm experiencing the same problem. Device: OnePlus 9 Pro, running CrDroid 12.10, which is Android 16)

xad0x avatar May 21 '26 14:05 xad0x

Same problem on OnePlus Ace 3V (Android 16) ver. 1.0.4-1.2.1. This bug appears less often (doesn't) in Android auto (Full link).

Prosto-Pasha avatar May 23 '26 04:05 Prosto-Pasha

I made a fork which fixes the issue https://github.com/DropaBombOnEm/SimpMusic/releases/tag/1.2.1

DropaBombOnEm avatar May 23 '26 22:05 DropaBombOnEm

I made a fork which fixes the issue https://github.com/DropaBombOnEm/SimpMusic/releases/tag/1.2.1

No, it does not fix the issue. And from what i can tell, it's also vibecoded.

xad0x avatar May 24 '26 14:05 xad0x

is it fixed in 1.3.0?

girshcatt avatar May 24 '26 20:05 girshcatt

I made a fork which fixes the issue https://github.com/DropaBombOnEm/SimpMusic/releases/tag/1.2.1

No, it does not fix the issue. And from what i can tell, it's also vibecoded.

@xad0x, It is vibecode, I'm not a programmer and never claimed to be. I'm just trying to get it to work for personal use & share it with the community, if it works. And you're also right that it wasn't fixed, just less-frequent (on my end) and it didn't happen the hour I tested yesterday.

But it seems the root cause was found now though "player.seekTo() causes ExoPlayer to briefly transition through a non-playing buffering state. The onIsPlayingChanged(false) callback fires, cancelling progressJob. When rebuffering completes near-instantly, onIsPlayingChanged(true) may never fire — leaving progressJob permanently dead. The UI shows "playing" but progress never moves".

I'll do some more testing... My bad for the false-claim of it being fixed. 😅

DropaBombOnEm avatar May 24 '26 22:05 DropaBombOnEm

is it fixed in 1.3.0?

Unfortunately no...

frreachergirl-source avatar May 25 '26 17:05 frreachergirl-source

I haven't had any issues with my new 1.3.0-Dev fork, but I'd love for @xad0x to prove me wrong again 😅 🫣

I had 20-30 songs play in the background (during the course of an extended period of time, using other apps & my phone being locked) and playback only paused when my phone switch from Wi-Fi to cellular (when I left home) and I just pressed play from the notification and it resumed like normal...

I also tested my fork via an emulator on my PC and it played songs continuously for hours in-app (app launched on-screen) without playback stopping itself.

DropaBombOnEm avatar May 26 '26 07:05 DropaBombOnEm

This has been fixed. The player no longer drops the foreground service between tracks (STATE_ENDED is now suppressed during track transitions), so the OS can no longer freeze the process during the player swap. Please update to the latest version. Thanks for the detailed root-cause analysis and ADB logs. If it still happens on the latest build, comment with logs and we will reopen.

maxrave-dev avatar Jun 06 '26 11:06 maxrave-dev

@maxrave-dev thank you for all the work on this!

That said, it's still broken in v1.4.0: playback still stops between tracks for me on the latest nightly (dev, core 3ecd15f). Could this be reopened? I dug into it and found a possible cause: this may not be the same foreground-service drop you fixed (my process is never frozen in the logs), but a separate audio-focus issue during the precached-player swap. Details below.

Build: FOSS nightly from CI run https://github.com/maxrave-dev/SimpMusic/actions/runs/27085129738 (dev, core submodule 3ecd15f, includes all three prior playback fixes). Device: Galaxy S23 (SM-S911B), One UI / Android 16, Media3 1.10.1.

I was listening over a Bluetooth speaker (A2DP), which makes the stop very easy to notice, but I don't think Bluetooth itself is the cause. The logs suggest the audio output only gets torn down because playback had already silently paused, so the BT teardown looks like a symptom, not the trigger.

Repro

  1. Queue several tracks and press play.
  2. Let it auto-advance on its own (don't touch the transport controls).
  3. Within a few tracks, playback stops: notification shows the next track at position 0, paused, while the UI "wants" to play.
  4. Pressing play resumes it (this seems to issue a fresh audio-focus request).

In my case it only seems to break when the next track is served from precache, which might explain why it's intermittent ("stops after 4 to 5 songs").

Possible cause (CrossfadeExoPlayerAdapter.kt)

  • Precached/secondary players appear to be created with handleAudioFocus = false (createExoPlayerInstance, ~line 293; used at ~1202, ~1575, ~2455). Only the initial player (~line 244) handles focus.
  • On the track-end swap (loadAndPlayTrackInternal), the old player is released and abandons audio focus, and the precached player's focus handling is enabled afterwards via setAudioAttributes(audioAttributes, true) (~line 1250) and play(). It looks like flipping handleAudioFocus false to true on an already-prepared player may not actually re-acquire focus, so the gap left by the old player is never filled and ExoPlayer ends up at PLAYING -> PAUSED (playWhenReady=true).

(I'm not 100% sure on the exact ExoPlayer internals here, but the logs below seem to point this way.)

Evidence (logcat, sanitized)

The session-wide audio-focus timeline is what made me suspect this. Every successful track change is abandon -> request, except the one that stops:

06-07 16:45:14.516 I/MediaFocusControl: requestAudioFocus() ... callingPack=com.maxrave.simpmusic
06-07 16:48:05.515 I/MediaFocusControl: abandonAudioFocus() ... com.maxrave.simpmusic
06-07 16:48:05.528 I/MediaFocusControl: requestAudioFocus() ... com.maxrave.simpmusic
06-07 16:51:33.151 I/MediaFocusControl: abandonAudioFocus() ... com.maxrave.simpmusic
06-07 16:51:33.166 I/MediaFocusControl: requestAudioFocus() ... com.maxrave.simpmusic
06-07 16:54:43.660 I/MediaFocusControl: abandonAudioFocus() ... com.maxrave.simpmusic
06-07 16:54:43.666 I/MediaFocusControl: requestAudioFocus() ... com.maxrave.simpmusic
06-07 16:57:31.264 I/MediaFocusControl: abandonAudioFocus() ... com.maxrave.simpmusic
06-07 16:57:31.270 I/MediaFocusControl: requestAudioFocus() ... com.maxrave.simpmusic
06-07 17:00:17.331 I/MediaFocusControl: abandonAudioFocus() ... com.maxrave.simpmusic   <-- no request follows

The failing transition in sequence:

06-07 17:00:17.281 D/CrossfadeExoPlayerAdapter: End of stream reached
06-07 17:00:17.281 D/CrossfadeExoPlayerAdapter: State: PLAYING -> PREPARING (playWhenReady=true)
06-07 17:00:17.302 D/CrossfadeExoPlayerAdapter: Using precached player for <videoId>
06-07 17:00:17.314 I/ExoPlayerImpl: Release 6699789 [AndroidXMedia3/1.10.1] [SM-S911B, samsung, 36]
06-07 17:00:17.331 I/MediaFocusControl: abandonAudioFocus() ... com.maxrave.simpmusic
06-07 17:00:17.342 D/CrossfadeExoPlayerAdapter: State: PREPARING -> PLAYING (playWhenReady=true)
06-07 17:00:17.372 D/CrossfadeExoPlayerAdapter: State: PLAYING -> PAUSED (playWhenReady=true)   <-- paused, no focus
06-07 17:00:20.401 I/PAL: Device: close ... PAL_DEVICE_OUT_BLUETOOTH_A2DP, deviceCount 1 -> 0   <-- BT output torn down (after the pause)

(Full 71-line sanitized logcat attached.)

Possible fix direction

Maybe make sure audio focus is actually re-acquired when a precached player is promoted to current, for example by building precache players with audio-focus handling, or forcing a playWhenReady false to true edge after setAudioAttributes(.., true), or requesting focus explicitly before play(). A possible sanity check: every abandonAudioFocus() during a transition should be followed by a requestAudioFocus().

Sad that although v1.4.0 has just been released (#2121), we may have to go back again to v1.0.3. Happy to capture more logs if it would help. Just let me know what would be most useful and thanks again for your work!

2026-06-07_Log_playback_stop.txt

Dollarius avatar Jun 07 '26 08:06 Dollarius

I too tested v1.4.0 and for me it worked. Details: My phone is an OnePlus 9 Pro, ROM is CrDroid 12.10 (Android 16) I enabled Keep service alive in settings and went into the app info (in system settings) > app battery usage > allow background usage > unrestricted. I was not logged into youtube. I listened to the music with bluetooth headphones. I left my phone locked the entire time.

Using these settings i listened to 9 songs in a row without any interruptions.

xad0x avatar Jun 07 '26 10:06 xad0x

Still broken on the released 1.4.0. Reproduced just now on the phone speaker (no Bluetooth):

  1. Installed the released 1.4.0 (not the nightly).
  2. Played an uncached album on the phone speaker (playing by ~08:04).
  3. Playback stopped after exactly 4 songs (08:18:00).
  4. Turned on "keep service alive" and set the app battery to Unrestricted, then pressed play (08:25:51).
  5. Playback stopped again after exactly 1 more song (08:28:56).

Both stops show the same thing: abandonAudioFocus() with no following requestAudioFocus(), then PLAYING -> PAUSED (playWhenReady=true). So the Unrestricted/keep-alive changes made no difference, and no Bluetooth is involved.

Full sanitized logcat attached.

@dafcavservicios @brendancarr @afabmoro97 @MrDaraku @xad0x @Prosto-Pasha @DropaBombOnEm @girshcatt @frreachergirl-source how is it for you guys on 1.4.0?

@maxrave-dev I am available to provide more data/tests if it can be helpful.

2026-06-08_Log_full_app_sanitized.txt

Dollarius avatar Jun 07 '26 23:06 Dollarius

Hi, everyone! I confirm, the problem remains in 1.4.0.

Prosto-Pasha avatar Jun 08 '26 01:06 Prosto-Pasha

Il problema persiste anche nella versione 1.4.0 soprattutto quando collego una sorgente bluetooth

afabmoro97 avatar Jun 19 '26 09:06 afabmoro97

Still in 1.5.0.

Prosto-Pasha avatar Jun 30 '26 06:06 Prosto-Pasha

Il problema persiste ancora una volta nella versione 1.5.0

afabmoro97 avatar Jun 30 '26 15:06 afabmoro97