Apply stream-quality change live by reloading at current position

Finish the Settings "Apply" behavior so changing streaming quality mid-track
switches format immediately instead of only persisting the cookie for the next
play.

- SettingsMenu reads the AudioPlayerProvider cascade and threads the player into
  StreamQualitySetting as an explicit parameter (the MudMenu panel portals to
  MudPopoverProvider, outside the cascade scope, so a [CascadingParameter] there
  lands null). StreamQualitySetting's Apply persists the cookie, then asks the
  player to reload preserving position.

- Add a "load at timestamp" path to the player rather than restart-from-0-then-
  seek (which audibly played the start and raced the just-started scheduler into
  a crash). ReloadPreservingPositionAsync loads the track in the newly-resolved
  format beginning DIRECTLY at the saved position:
    * new JS resolveStreamOffset(position) resolves the file-absolute byte offset
      with no playback/buffer state (Opus from its sidecar immediately; WAV after
      a header probe),
    * StartFromPositionAsync converges onto the existing seek/refill loop
      (RunSegmentedStreamAsync with a non-null seekPosition) so the decoder
      reinitializes for a header-less Range continuation and starts playback at
      the target,
    * ProbeHeaderAsync feeds the byte-0 segment to the decoder WITHOUT starting
      playback until the WAV header parses (bounded by 256 KB); the probe buffers
      are dropped by the continuation's clearForSeek, so nothing is audible.

- IStreamingPlayerService gains ReloadPreservingPositionAsync; the QueueService
  test fake implements it.
This commit is contained in:
daniel-c-harvey
2026-06-24 22:55:03 -04:00
parent 7adc35dd5d
commit d686fe48ce
8 changed files with 284 additions and 12 deletions
@@ -91,4 +91,16 @@ public interface IStreamingPlayerService : IPlayerService
/// <see cref="IPlayerService.CurrentTrack"/> and notifies; performs no JS interop.
/// </summary>
Task StageTrack(TrackDto track);
/// <summary>
/// Re-streams the current track in the freshly-resolved delivery format while preserving the
/// listener's playback position (Phase 18 wave 18.6 — the Settings "Apply" restart). The format is
/// re-resolved on the new load via the <c>ResolveStreamFormatAsync</c> seam, so this picks up a just-
/// changed streaming-quality preference. A cross-format byte offset can only be resolved once the NEW
/// format's decoder has parsed its header, so the reload runs a fresh load from byte 0 to initialize
/// that decoder, then seeks back to the saved position through the existing seek-beyond-buffer path.
/// No-op when no track is loaded (nothing playing to switch). Safe to call while a track is playing;
/// a track switch during the brief restore window abandons the position restore.
/// </summary>
Task ReloadPreservingPositionAsync();
}