SimpMusic icon indicating copy to clipboard operation
SimpMusic copied to clipboard

Playback stops permanently with 00:00 / NA:NA at track transition after a brief network loss (broken since v1.0.4)

Open Dollarius opened this issue 4 months ago • 12 comments

Duplicate Check

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

Describe the Bug

When the network drops briefly while a song is playing (very common while moving around with the phone: leaving Wi-Fi range, mobile signal blips), the current song keeps playing fine from its buffer. But when it ends, the next track fails instantly with "Source error": the player shows position 00:00 and duration NA:NA, and playback stops permanently. It does not recover even if the network came back minutes before the transition.

This is a different bug from #2022 / #2233. Same visible symptom (music stops mid-queue), different cause: this one is triggered by a short network loss and kills playback at the next track transition.

Root cause (verified in logcat, details below): CrossfadeExoPlayerAdapter precaches upcoming tracks in background ExoPlayers. If the stream URL resolution fails during a network blip, that precached player dies silently (STATE_IDLE with playerError set) but stays in the precachedPlayers map.

Affects all versions since v1.0.4, which introduced CrossfadeExoPlayerAdapter and its precache mechanism (no playerError check existed in any version).

Steps to Reproduce

  1. Play a queue (autoplay/radio) on Android.
  2. While a song is playing, cut the network for ~10 seconds (toggle airplane mode, or walk out of Wi-Fi range). Timing: the cut must overlap the moment the app precaches the next track, which happens right after a track transition.
  3. Restore the network. The current song keeps playing normally.
  4. Wait for the song to end.
  5. The next track shows 00:00 / NA:NA and playback stops. Play/pause does not recover it.

Expected Behavior

A short network loss should not kill playback. If a precached player failed, the app should prepare the track again at transition time (the network may be back), and if it is still offline it should surface a retryable error instead of stopping silently on a dead player.

App Version

1.5.1

Android Version

Android 16

Device Model

Samsung Galaxy S23 (SM-S911B)

Custom ROM

  • [ ] I am using a custom ROM

Log / Error Details

Full logcat available. Key sequence (same app process across both captures):

The precache player for the upcoming track dies during the network blip, 4 resolve attempts then a permanent error:

18:11:31.142 E Stream: Error: Unable to resolve host "music.youtube.com": No address associated with hostname
18:11:31.142 E Stream: Failed to resolve stream URL for qeMFqkcPYcg
... (3 more retries: 31.287, 32.337, 34.393)
18:11:34.405 E ExoPlayerImplInternal: Playback error
18:11:34.405 E ExoPlayerImplInternal:   androidx.media3.exoplayer.ExoPlaybackException: Source error
18:11:34.405 E ExoPlayerImplInternal:   Caused by: java.io.IOException: Failed to resolve stream URL for qeMFqkcPYcg

Network is back at 18:15:10 (the next precache resolves fine), but the dead player is never re-prepared. Eight minutes after it died, it is swapped in as the current player and the session reports its stored error 4 ms later:

18:19:17.295 D CrossfadeExoPlayerAdapter: Using precached player for qeMFqkcPYcg
18:19:17.296 D CrossfadeExoPlayerAdapter: State: PREPARING -> PLAYING (playWhenReady=true)
18:19:17.297 D DelegatingForwardingPlayer: Delegate swapped successfully
18:19:17.300 D MediaSessionService: ... playbackState=PlaybackState {state=ERROR(7), position=0, buffered position=0, ... error=Source error}

Possible fix directions:

  • At swap time, if the cached player has playerError != null (or is idle), release it and fall back to the existing fresh-player path.
  • Attach an error listener to precache players so a failed one is evicted from precachedPlayers, allowing re-precache when the network returns.
  • Consider adding ERROR_CODE_IO_NETWORK_CONNECTION_FAILED (2001) to the retryable codes in onPlayerError (the comment mentions it but the condition omits it).

Dollarius avatar Jul 14 '26 10:07 Dollarius

I tentatively developed a fix: maxrave-dev/core#12. When the network drops while the next song is being precached, that broken player stayed in the cache and the app still used it at the next track change, so playback stopped with its old error. With the PR, broken precached players are removed right away and the track is loaded from scratch at the track change.

Solves the issue for me (tested on Galaxy S23, Android 16, debug build of main plus the PR): worst case the next song shows 00:00 for a couple of seconds while it loads, then plays. No more permanent stop.

23:30:22.551 W CrossfadeExoPlayerAdapter: Evicting failed precached player for lDK9QqIzhwk: ERROR_CODE_IO_UNSPECIFIED
23:36:15.435 D CrossfadeExoPlayerAdapter: Creating new player for lDK9QqIzhwk
23:36:17.748 (stream URL resolves, playback continues)

Dollarius avatar Jul 14 '26 15:07 Dollarius

I have the same issue. When switching networks whether data or WiFi, music player just stops working basically. Just says NA/NA for all songs. Gonna try restarting my phone, but it sicks if I have to do that every time.

m-val-co avatar Jul 14 '26 15:07 m-val-co

Please share me your country, and trying to use some VPN This error is geo-blockinng and ip-restriction from YouTube

maxrave-dev avatar Jul 16 '26 03:07 maxrave-dev

I am currently in Japan. This PR fixes it entirely for me maxrave-dev/core#12.

Dollarius avatar Jul 16 '26 03:07 Dollarius

@blank108 you can stop using app, no thanks

maxrave-dev avatar Jul 16 '26 06:07 maxrave-dev

Still reproduces on 2.0.0 (versionCode 57), Galaxy S23 (SM-S911B), Android 16, stock release build.

Repro

  1. Start a playlist. SimpMusic precaches exactly 2 tracks ahead.
  2. Turn on airplane mode about 15 seconds before the current track ends.
  3. Let the track change happen while offline. The next track plays fine, it was already precached. The precache of the track two ahead fails.
  4. Turn airplane mode off and let the connection return.
  5. Two tracks after the blip, playback dies: 00:00, an active play indicator, and silence.

Worth noting: on an affected device you do not need to do any of that. #2233 supplies the failure by itself. It gets the app's network revoked, a precache fails during that window, and the dead player stays in the map. That is how I hit it today, without touching the network.

A precache fails at 06:58 while the app is being throttled:

06:58:21  CrossfadeExoPlayerAdapter: Using precached player for TRACK_F
06:58:21  Stream: Failed to resolve stream URL for TRACK_H

The network came back afterwards, but TRACK_H was never re-prepared. Nine minutes later playback reaches it:

07:07:44  CrossfadeExoPlayerAdapter: End of stream reached
07:07:44  CrossfadeExoPlayerAdapter: Using precached player for TRACK_H
07:07:44  MediaSessionService: playbackState=PlaybackState {state=ERROR(7), position=0, buffered position=0, speed=0.0, error=Source error}
07:07:44  CrossfadeExoPlayerAdapter: State: PREPARING -> PLAYING (playWhenReady=true)

Just when the swap happens, it ERRORS. There is no gap at all. A real stream URL resolve on this device takes seconds (the retries above span about four), so this cannot be a fresh attempt: it is the error stored on the dead player being replayed. That is the attribution, the dead player was promoted without a playerError check.

Note the last line too. Right after the session has gone to ERROR, the adapter sets its own internal state to PLAYING. There are no eviction or discard lines anywhere in the capture.

Correction to the symptom in my original report. It is not always 00:00 / NA:NA. When the track has a duration in the local database, the now playing screen shows 00:00 next to the correct total time, with an active play indicator and total silence. Three inconsistent sources on one screen:

  • 00:00 is the real position of the dead player
  • the total time comes from SongEntity.durationSeconds, read straight by the UI, not from the player
  • the play indicator comes from the adapter's internal state

NA:NA only appears when the database has no duration for that track. The variant with a plausible duration is more confusing, and probably explains the reports that describe it as "it says it is playing but there is no sound".

The corpse stays in the map and automatic recovery never happens: onPlayerError does not fire retroactively for the promoted player, so the retry logic never runs and playback sits in ERROR until the user notices.

Pressing play does recover it, so this is not force-stop territory. Verified today on 2.0.0: a precache that failed to resolve at 08:32:47 was swapped in 49 minutes later at 09:21:53, sat at ERROR(7) position=0 buffered=0, and a single play command re-resolved the URL and started the track. Note it restarts from the beginning rather than resuming, because the dead player had never played anything.

maxrave-dev/core#12 fixes this and has been open since 2026-07-14.

Track IDs replaced with TRACK_x placeholders.

Dollarius avatar Aug 30 '26 22:08 Dollarius

Still reproduces on 2.2.0 (Galaxy S23, Android 16, stock release). A short network cut at a track change silently kills the track two positions later. Pressing play recovers it.

Details and repro script

Reproduced three times today:

09:25:08  network off 8s, at a track change
09:25:12  Stream: Failed to resolve stream URL for djV11Xbc914
09:33:00  CrossfadeExoPlayerAdapter: Using precached player for djV11Xbc914
09:33:05  session: ERROR(7) position=0 buffered=0   (still ERROR at 09:33:31, no retry)

It is not only network drops. On 2.0.0 a precache failed with the network fine, because YouTube returned no stream (Stream: Error: No URL found), and playback died when the queue reached that track 9 minutes later. Any failed precache becomes a silent stop, and an unplayable track halts the queue instead of being skipped.

The script cuts Wi-Fi and mobile data with svc, because airplane mode can leave Wi-Fi on.

#!/usr/bin/env bash
# Repro for #2239: a network blip during a track change leaves a dead preloaded
# player that is swapped in two tracks later and never recovers.
#
# Needs: adb, phone connected, SimpMusic playing a playlist (3+ songs left).
# Wi-Fi and mobile data are cut with `svc` because airplane mode may keep Wi-Fi on.
set -u
PKG=${PKG:-com.maxrave.simpmusic}
BLIP=${BLIP:-8}

state() { adb shell dumpsys media_session | grep -m1 "state=PlaybackState" | sed 's/.*state=\([A-Z_]*([0-9]*)\), position=\([0-9]*\), buffered position=\([0-9]*\).*/\1 pos=\2 buf=\3/'; }
wait_track_change() { adb logcat -T 1 -e "Precached player for index" -m 1 CrossfadeExoPlayerAdapter:D '*:S' >/dev/null; }

PID=$(adb shell pidof "$PKG") || { echo "$PKG not running"; exit 1; }
echo "pid $PID, $(adb shell dumpsys package "$PKG" | grep -m1 versionName | tr -d ' ')"
echo "[$(date +%T)] waiting for a track change..."
wait_track_change
BLIPT=$(adb shell 'date "+%m-%d %H:%M:%S.000"' | tr -d '\r')
echo "[$(date +%T)] track changed, cutting Wi-Fi + data for ${BLIP}s"
adb shell svc wifi disable; adb shell svc data disable
sleep "$BLIP"
adb shell svc wifi enable; adb shell svc data enable
echo "[$(date +%T)] network restored"
sleep 5
DEAD=$(adb logcat -d -T "$BLIPT" --pid "$PID" | grep -o "Failed to resolve stream URL for [A-Za-z0-9_-]*" | tail -1 | awk '{print $NF}')
[ -n "$DEAD" ] || { echo "no preload failed this time; rerun"; exit 2; }
echo "[$(date +%T)] preload failed for $DEAD (the app preloads 2 tracks ahead, so it plays in 1-2 tracks)"

echo "[$(date +%T)] waiting until the queue reaches $DEAD..."
adb logcat -T 1 -e "Using precached player for $DEAD" -m 1 CrossfadeExoPlayerAdapter:D '*:S'
for i in 1 2 3 4 5 6; do sleep 5; echo "[$(date +%T)] $(state)"; done
adb logcat -d -v time --pid "$PID" | grep -E "Using precached player for $DEAD|State: |Source error|ERROR_CODE" | tail -8

Dollarius avatar Sep 29 '26 05:09 Dollarius

Retested on 2.5.0 (Galaxy S23, Android 16, stock release).

  • Crossfade off: fixed. maxrave-dev/core@d90b53f (the live broadcast change, in 2.3.0) discards a failed preload at the track change (Creating new player for ...), and the song plays after a ~2 s pause.
  • Crossfade on: still reproduces. triggerCrossfadeTransition takes the preloaded player with precachedPlayers.remove(nextVideoId) and no playerError check, so the failed one is swapped in. Playback sits at ERROR(7) position=0, while the adapter logs Crossfade complete and keeps its own state at PLAYING. Pause/play doesn't recover it (the error fired before the adapter's listener was attached, so play never re-prepares); only Next does.

Logcat extract (crossfade on, 5 s):

14:52:46  preload of track 3 fails: Failed to resolve stream URL (network off 8 s)
14:59:49  Starting crossfade to track 3  (failed player swapped in)
14:59:54  Crossfade complete, swapping players
15:05:34  still ERROR(7) pos=0
15:08:28  play pressed: PAUSED -> PLAYING, still silent
15:08:38  Next pressed: plays normally

Dollarius avatar Nov 04 '26 08:11 Dollarius

Still happens on dev after maxrave-dev/core#12 was merged, but only with crossfade on. The crossfade uses the failed preload without checking it, so playback stops at 0:00. Pause/play in the app doesn't bring it back, while Next and play from the notification do. Fix: maxrave-dev/core#55.

Details

Galaxy S23, dev 91ec84b3 (core 1cdb95d), crossfade 5 s, shuffle on. 8 s Wi-Fi and data cut right after a crossfade. The preload fails, with no retry (error 2000). At the crossfade into that song, playback stays at ERROR at position 0 (reproduced twice). In-app pause/play: still ERROR. Next: plays. With the fix, the song loads fresh at the crossfade and plays.

Dollarius avatar Nov 08 '26 11:11 Dollarius

@maxrave-dev could you reopen this until maxrave-dev/core#55 is in?

Dollarius avatar Nov 08 '26 11:11 Dollarius

Fixed in 2.6.0 (maxrave-dev/core#12, maxrave-dev/core@029c420): a precached track that failed to load is discarded instead of swapped in, and a failed precache is retried with a fresh stream URL, so playback no longer stops at 00:00 / NA:NA after a brief network drop.

maxrave-dev avatar Nov 11 '26 08:11 maxrave-dev

Sorry, but this is not fixed with crossfade on.

maxrave-dev/core@029c420 was already in the core I tested on dev (core 1cdb95d), and playback still stopped at 0:00 there after a short network cut at a track change. The crossfade path is unchanged in core multiplatform (a4e6231): triggerCrossfadeTransition still takes the precached player without checking playerError, so a failed preload is swapped in and never plays.

With crossfade off it's fixed.

A possible fix is in maxrave-dev/core#55. Could you reopen this until that or an equivalent is in?

Dollarius avatar Nov 11 '26 09:11 Dollarius