Repository navigation
Description
Summary
Progressive direct-play playback must treat the underlying HTTP response as disposable. If a reverse proxy terminates a response while Media3 is intentionally not reading because its playback buffer is full, Android should reopen the stream at the exact byte offset with Range and continue without surfacing a player error or remounting the media item.
This is the client-side fix that lets Silo work behind stock nginx/OpenResty configurations without requiring operators to raise send_timeout to an hour.
Incident shape
A Shield downloaded an original-quality stream much faster than playback and filled Media3's buffer. Media3 correctly stopped reading from the socket. A reverse proxy using nginx's default client-facing send_timeout 60s terminated the no-write-progress HTTP/2 stream. The failure was not observed until the buffer drained a few minutes later:
StreamResetException(INTERNAL_ERROR) → ERROR_CODE_IO_NETWORK_CONNECTION_FAILED → same-route player remount → visible playback hiccup.
This is a transport-lifecycle event, not a decoder failure or evidence that the buffer was empty when the proxy closed the response.
Current implementation
Source baseline reviewed: d19cfb8483a5a7b52d46ab14138a2d435e3e3070.
PlayerOkHttpClient.ktprefers HTTP/2 over HTTP/1.1.MediaLoadRetryPolicy.ktretries socket/connect/timeout failures andProtocolException("unexpected end of stream"), but an OkHttp HTTP/2 stream reset is a plainIOExceptionshape that currently returnsC.TIME_UNSET.- The Media3 progressive loader can reopen a failed load using a ranged
DataSpec; the existing authenticated/routed data-source stack supports reopening requests. - The ViewModels currently allow one transient same-route recovery by calling
setMediaItem(position) + prepare(). That discards buffered media and makes an otherwise recoverable byte-stream interruption visible. - This is distinct from Playback: retry (don't error) on transient segment/manifest failures so server transcode restart-resilience works #3, which is primarily about manifest/segment retry during server-transcode outages. It may explain the black-screen subset of Android TV (v0.3.11): playback reliability + controls — elapsed time, pause consistency, ~10-min black-screen #70.
Proposed PR scope
- Make mid-body transport failures retryable inside Media3 for range-resumable progressive direct-play sources:
- HTTP/2 stream reset / connection shutdown
- premature EOF after byte progress
- equivalent idempotent GET connection failures
- Use
LoadErrorInfo.loadEventInfo.bytesLoaded(and the selected delivery type/capability) to distinguish a resumable mid-stream failure from an initial connection failure or non-resumable progressive remux. - Let Media3 reopen from its current
DataSpec.position; do not route the successful recovery through the ViewModel remount/replan ladder. - Keep the retry window and backoff bounded. Do not retry authentication/authorization failures, unsupported range responses, parser/decoder failures, or non-idempotent requests.
- Add structured diagnostics for:
- original exception/cause
- bytes loaded before failure
- requested resume offset
- retry attempt/delay
- whether the error escaped to
Player.Listener.onPlayerError
- Audit
SiloLoadControl.calculateTargetBufferBytes: measured network capacity (latestBitrateEstimate) must not inflate a progressive media buffer target when an actual media bitrate is available. This may be a follow-up PR if keeping the recovery change focused.
Acceptance criteria
- A proxy-terminated HTTP/1.1 or HTTP/2 direct-play response resumes with a new
Rangerequest at the correct next byte. - The player timeline and playback position remain continuous; no
setMediaItem + prepare, protocol replan, black frame, or user-visible error occurs. - Retry is bounded and cannot loop indefinitely when the origin repeatedly fails without progress.
- A server that ignores
Range, returns invalidContent-Range, changes the entity, or returns 401/403 produces the appropriate existing recovery/error path rather than silent corruption. - HLS segment retry behavior from Playback: retry (don't error) on transient segment/manifest failures so server transcode restart-resilience works #3 remains intact.
- Phone and Android TV use the same policy and both pass focused tests.
Verification
Automated
Use a full Media3 progressive-source test (not only a policy unit test):
- Serve a valid seekable fixture with
Accept-Ranges: bytes. - Terminate the first 206 response after meaningful byte progress using both premature EOF and an HTTP/2 reset-equivalent failure.
- Assert the next request contains the exact expected
Range. - Assert playback reaches the end without a player error or media-item remount.
- Cover no-progress retry exhaustion, mismatched
Content-Range, 401/403, 416-at-EOF, and non-resumable delivery.
Device soak
Put the development server behind nginx/OpenResty with a short client-facing send_timeout, allow a Shield to fill its buffer and stop reading, and verify multiple close/resume cycles during a long high-bitrate title with no visible hiccup.
Non-goals
- Replacing progressive original-file direct play with HLS.
- Server-side byte pacing or payload heartbeats.
- Depending on a one-hour reverse-proxy timeout.
Activity
Quick104 commentedon Jul 21, 2026
Coordinated work:
feat(player): resume progressive direct play transparently after mid-…
Quick104 commentedon Sep 4, 2026
Implemented by PR #99. Progressive original-file playback can retry mid-body transport failures inside Media3 and reopen at the byte offset, with bounded retries and an ETag/If-Range guard, without routing successful recovery through a player remount or protocol replan. Phone and TV share the policy.
The merged PR records a real ExoPlayer/MockWebServer integration test proving ranged recovery through playback completion, failure-path coverage, both app builds, and a Galaxy S26 Ultra server-side range check. PR #147 subsequently bounded the buffer's idle window and records testing against the restored 60-second proxy timeout.
Verified the recovery implementation and integration tests remain on main at
8791af20, whose unit-test check passes. No new device soak was run during this cleanup. Closing as completed.