SimpMusic icon indicating copy to clipboard operation
SimpMusic copied to clipboard

Playback stops after a brief network hiccup (error 2000 is not retryable)

Open Dollarius opened this issue 3 months ago • 5 comments

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

A short network interruption during a song stops playback permanently. It does not resume when the connection comes back. Pressing play recovers it instantly, so nothing is actually broken except that the retry is never attempted.

Repro

  1. Start a playlist.
  2. While a song is still buffering (early in the track works best), turn on airplane mode for about 10 seconds.
  3. Turn it off, the connection returns within seconds.
  4. Playback stops as soon as the already-buffered audio runs out, and stays stopped.
  5. Press play: it resumes from exactly where it stopped.

I did not even do this deliberately. My phone roamed between two Wi-Fi access points on the same SSID at home:

08:38:59  ConnectivityService: registerNetworkAgent NetworkAgentInfo{network{398}   (WIFI CONNECTING)
08:39:04  ConnectivityService: [397 WIFI] disconnected
08:39:04  ConnectivityService: registerNetworkAgent NetworkAgentInfo{network{399}

DNS was unavailable for a few seconds, and the player asked for more stream data inside that window:

08:39:02  Stream: Error: Unable to resolve host "music.youtube.com": No address associated with hostname
08:39:02  Stream: Failed to resolve stream URL for TRACK_A
08:39:02  ExoPlayerImplInternal: Playback error / qt3: Source error
08:39:02      Caused by: java.io.IOException: Failed to resolve stream URL for TRACK_A
08:39:02  CrossfadeExoPlayerAdapter: Playback error: Source error
08:39:02  Player Error: Source error, code: 2000, code name: ERROR_CODE_IO_UNSPECIFIED
08:39:02  CrossfadeExoPlayerAdapter: pause() called (state: PLAYING, playWhenReady: true)
08:39:02  CrossfadeExoPlayerAdapter: State: PLAYING -> ERROR (playWhenReady=true)
08:39:02  CrossfadeExoPlayerAdapter: Pause: Called in invalid state: ERROR

It then sat at ERROR(7), position=48753, buffered position=48753 for 35 minutes with zero retry attempts, while the network was fine the whole time (music.youtube.com resolving in 21 ms).

Cause

In CrossfadeExoPlayerAdapter.onPlayerError:

val isRetryableSourceError =
    error.errorCode == PlaybackException.ERROR_CODE_PARSING_CONTAINER_MALFORMED ||  // 3001
        error.errorCode == PlaybackException.ERROR_CODE_IO_BAD_HTTP_STATUS ||       // 2004
        error.errorCode == PlaybackException.ERROR_CODE_IO_FILE_NOT_FOUND           // 2005

The observed code is 2000, which is not in the set, so the retry branch is never entered and the adapter parks in ERROR. ERROR_CODE_IO_NETWORK_CONNECTION_FAILED (2001) is not there either, even though the comment directly above this expression documents it as handled.

The retry logic already works, it is just never reached

A single play command recovered it immediately:

09:20:05  state=ERROR(7),   position=48753, buffered position=48753
09:20:06  (media play key)
09:20:07  CrossfadeExoPlayerAdapter: State: ERROR -> PLAYING (playWhenReady=true)
09:20:12  state=PLAYING(3), position=51325, buffered position=155021

A fresh URL was resolved and playback resumed from the failure point, which is exactly what the existing retry path does, including its position snapshot.

Suggested fix

Add 2000 and 2001 to isRetryableSourceError, or retry the whole IO class, reusing the maxRetryCount and cachedPosition resume that already sits directly below.

Why this is worse than it looks

Any loss of connectivity triggers this, and SimpMusic manufactures its own. #2233 gets the app's network revoked while it keeps playing, and this morning that revocation produced three failed precaches in six minutes (08:30, 08:32, 08:35), one per track transition. It was provably app-targeted rather than a connectivity problem: all 52 DNS failures in that window belonged to SimpMusic and none to any other process on the phone. Those three then stopped playback one after another about 50 minutes later (#2239), each needing its own manual play. The mid-song failure above was separate, caused by the genuine 5-second Wi-Fi roam. Together that is the mechanism behind reports of "it stops every song and I keep having to press play".

Related: #2233, #2239, #2428

Track ID replaced with a placeholder. Wi-Fi lines trimmed to remove SSID, BSSID, MAC and IP.

Dollarius avatar Aug 31 '26 00:08 Dollarius

Fixed for me in V2.1.0. Thanks! Anyone else confirm?

Start-Cart avatar Sep 15 '26 15:09 Start-Cart

Still reproduces on 2.2.0 (Galaxy S23, Android 16, stock release). @Start-Cart the retry list is unchanged in 2.2.0, so error 2000 is still never retried. 2.1.0 improved stream extraction, which may be what you saw fixed.

Details and repro script

Tap a song you have not played before and cut the network for 8 seconds while it loads:

10:09:16  song starts loading, network off 8s
10:09:19  Player Error: onPlayerError (2000): Source error
10:09:24  network back
10:10:25  session: still ERROR(7) position=0, no retry attempted

Pressing play starts it right away. The cut has to last longer than about 4 seconds, because Media3 retries the load 3 times by itself first.

#!/usr/bin/env bash
# Repro for #2429: a stream load that fails during a brief network blip
# (ERROR_CODE_IO_UNSPECIFIED, 2000) is never retried once the network is back.
#
# Needs: adb, phone connected, SimpMusic open.
# When prompted, tap a song you have NOT played before (so it is not cached or preloaded).
# The script cuts Wi-Fi + data the moment the app starts loading it, for 8s.
# Media3 retries a failed load for ~4s on its own, so the blip must last longer than that.
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/'; }

PID=$(adb shell pidof "$PKG") || { echo "$PKG not running"; exit 1; }
echo "pid $PID, $(adb shell dumpsys package "$PKG" | grep -m1 versionName | tr -d ' ')"
T=$(adb shell 'date "+%m-%d %H:%M:%S.000"' | tr -d '\r')
echo "[$(date +%T)] NOW tap a song you have not played before..."
adb logcat -T 1 -e "Creating new player for" -m 1 CrossfadeExoPlayerAdapter:D '*:S' >/dev/null
adb shell svc wifi disable; adb shell svc data disable
echo "[$(date +%T)] fresh load started, Wi-Fi + data cut for ${BLIP}s"
sleep "$BLIP"
adb shell svc wifi enable; adb shell svc data enable
echo "[$(date +%T)] network restored"

for i in $(seq 1 12); do sleep 5; echo "[$(date +%T)] $(state)"; done
echo "--- app log since start:"
adb logcat -d -v time -T "$T" --pid "$PID" | grep -E "Creating new player|Failed to resolve stream URL|Source error|Retryable source error|Max retries|Load track error|State: " | tail -15

Dollarius avatar Sep 29 '26 05:09 Dollarius

For now, pressing play after the connection comes back is the workaround, as you found. Thanks for re-testing: you're right that in 2.2.0, and on the current dev branch, isRetryableSourceError still only covers 3001, 2004 and 2005, so a 2000 (or a 2001) never reaches the retry path. Nothing released or on dev changes this yet, so this issue stays open as the report for it.

Automatic reply — the maintainer may follow up.

simpmusic-support[bot] avatar Oct 06 '26 16:10 simpmusic-support[bot]

Still reproduces on 2.5.0 (Galaxy S23, Android 16, stock FOSS). The stream resolver now tries a few times in ~3 s, but an 8 s network cut still outlasts it. isRetryableSourceError still only covers 3001, 2004 and 2005 (also on dev), so the 2000 never reaches the retry path. Pressing play recovers it.

Logcat extract:

16:30:34  new playlist, Creating new player for track 1; network off 8 s
16:30:38  Playback error: Source error (2000), State: PLAYING -> ERROR, no retry
16:30:43  network back, still ERROR
16:30:48  play pressed: reloads, playing 2 s later

Dollarius avatar Nov 04 '26 09:11 Dollarius

A possible fix is proposed in maxrave-dev/core#57: it retries network errors, makes the in-app play button work after an error, and reloads the track by itself when the network comes back (up to 5 minutes).

Dollarius avatar Nov 08 '26 15:11 Dollarius