Introducing a new way to review your PRs.

Read the announcement

crmne / spotifast

Spotify, native and fast. One lightweight Rust app for your whole library, local playback, and Spotify Connect on Linux, macOS, and Windows.

View on GitHub

19 documents · Updated Nov 18, 2026

docs / music-playback-and-devices

Music playback and device control

Spotifast presents one playback experience across the local player and Spotify Connect devices. It turns play commands into synchronized player state, routes local sound to a chosen audio output, and combines local listening records with Spotify's records from other devices.

Playback model

Local and remote playback

Playback can run in the built-in player or on another Spotify Connect device. The app selects the local target when this computer is ready and active. Otherwise it sends control requests to the selected or currently active remote device.

The built-in player keeps its Spotify Connect session in sync. This lets other Spotify clients see changes made in Spotifast. A session can end without stopping audio at once, so the player carries the current track through a reconnect and resumes it with the new session. A live session and an active Connect target are separate states: another device can take over while this computer remains ready for the next load.

The main playback view uses one NowPlaying snapshot for both paths. The snapshot identifies the track and device and reports position, play state, shuffle, repeat, volume, and the controls that the target allows. Connect pushes changes from other devices so the app can refresh remote state without waiting for its normal poll.

flowchart LR
    UI[Playback controls] --> Target{Active target}
    Target -->|This computer| Local[Local player]
    Target -->|Other device| Remote[Spotify Connect device]
    Local --> State[Unified playback state]
    Remote --> Push[Connect state updates]
    Push --> State
    State --> UI

References: src/app.rs• L199-230 src/app.rs• L1953-1989 src/player.rs• L150-245 src/player.rs• L502-617 src/player.rs• L392-420

Playback commands

The control set covers play and pause, next and previous, seek, volume, shuffle, repeat, queue changes, context loading, and device transfer. A new load can start a context or a list of URIs at a chosen item and position. Autoplay can continue from the context instead of ending at its last item. A load keeps the current repeat choice unless the request supplies a new one, so choosing another item does not silently turn repeat off.

The app applies local feedback quickly for actions such as play, seek, and volume. It then accepts the player or Spotify response as the lasting state. Volume previews affect the local sound while a slider moves; the final value is sent to Spotify when the change is committed.

Explicit track changes interrupt queued old audio before the replacement starts. Natural track changes keep gapless output. This distinction prevents a manual skip from playing stale buffered sound in front of the requested track.

References: src/player.rs• L248-315 src/player.rs• L849-975 src/player.rs• L989-995 src/sink.rs• L91-100

Audio output

Audio sink

The audio sink is the boundary between decoded Spotify audio and the operating system. It opens the chosen output when playback needs it, keeps a short queue ahead of the device, and pauses the device when playback is paused. It reports output failures to the app instead of taking down the player.

The sink follows the system default when no output is selected. If the selected output disappears, the audio layer can follow a new default. If no output can open, Spotifast remains usable as a remote control and shows an error for local sound.

Volume is applied at the output stage. This means a volume change also affects audio already waiting in the sink. Short fades smooth play, pause, mute, and explicit track changes.

References: src/player.rs• L997-1055 src/sink.rs• L1-13 src/sink.rs• L453-505 src/sink.rs• L722-803

Sample-rate conversion

Spotify audio enters the local path as stereo 44.1 kHz audio. The output keeps that rate when the device accepts it. When a device uses another rate, the sink converts the stream before it reaches the device.

The converter keeps its filter state between audio chunks. This makes chunk boundaries transparent and avoids clicks that can occur when each chunk is converted as a separate signal. The same audio path can also feed equalization and visualizers without making the visualizer level depend on the listening volume.

References: src/sink.rs• L597-605 src/sink.rs• L806-902 src/resample.rs• L1-8 src/resample.rs• L35-113

Processed audio routes

An optional managed audio route can receive the player stream before it reaches a private output path. The route keeps a small timing margin between the source process and the output. It adjusts that margin after dropouts and changes rate slightly when needed instead of inserting long silent gaps.

On Linux, the route uses PipeWire and can be rebuilt when the graph fails. On systems that support native capture, the route can observe the managed process while keeping the app's playback state separate from the route's health. This path is an audio integration, not a second playback target.

References: src/…/audio.rs• L1-30 src/…/audio.rs• L999-1041 src/…/audio.rs• L1090-1179

Device selection

Spotify Connect devices

The device picker combines devices returned by Spotify with receivers found on the local network. It places the active device first, then uses account-scoped selection history to make often-used devices easier to find. A device's identity is separate from its display name, so a renamed device remains the same target.

Selecting a remote device transfers playback control to that device. Selecting this computer uses the local player when it is ready. The picker also shows whether a device is restricted or cannot accept volume changes.

References: src/…/devices.rs• L14-71 src/…/devices.rs• L423-496 src/…/devices.rs• L526-614

Local audio outputs

The device picker also contains the physical audio output used by the built-in player. It lists the system default and available outputs only when needed. A selected output is saved by a stable device id; older name-based settings are upgraded after the output opens.

An unavailable saved output remains visible so the user can understand the current choice and change it. If it is not present, local playback falls back to the system default rather than failing only because the saved device is missing.

References: src/…/devices.rs• L233-373 src/sink.rs• L912-981 src/sink.rs• L1038-1088

Network receivers

Some speakers are visible on the local network before Spotify lists them. Discovery finds these receivers and reads enough device information to show a useful row. When the user selects one, Spotifast sends the account data through the receiver's protected setup flow. The receiver then joins Spotify Connect and can be controlled like any other device.

The setup keeps credentials in memory for the transfer and does not log or write the transferred credential. Cast receivers use an endpoint-specific preference key so two devices with the same name do not share selection history.

See Casting and network devices for the external receiver flow.

References: src/zeroconf.rs• L1-11 src/zeroconf.rs• L61-103 src/zeroconf.rs• L357-418 src/zeroconf.rs• L421-467

Device history

Device history is a small preference used to order the picker. It stores only device preference keys and keeps the history for one signed-in account at a time. Frequent choices rank first, with recent choice order breaking ties.

History is not playback history. It changes picker order only and does not store receiver addresses or credentials.

References: src/device_history.rs• L1-45 src/…/devices.rs• L56-71

Listening history

Local play records

Spotify does not add plays made through the local librespot player to its recently-played service. Spotifast therefore records local plays after enough listening time has passed. A short track uses a shorter threshold, while a skip before the threshold does not create a record.

Local records are stored privately and capped to a bounded recent set. They are written away from the UI thread so a slow disk does not block playback or interaction.

References: src/history.rs• L1-19 src/history.rs• L44-109

Recent plays

The Recent view merges local records with Spotify's recently-played records from other devices. A remote entry that matches a local play within the allowed time window is shown once. Separate listens remain separate even when they are close together.

The queue panel loads remote history as needed and rebuilds its view when either source changes. This gives the user one recent-play list without claiming that Spotify knows about local playback.

References: src/history.rs• L150-205 src/app.rs• L10381-10430 src/…/queue.rs• L600-727

Queue-facing player state

Queue ownership

The queue can contain the current item, songs manually added by the user, and the next items from the active context. The UI labels these groups as Now playing, Playing next, and Next up so the user can see which rows they control directly.

Only the active local player can reorder, insert at a position, or remove rows from its manual queue. Remote playback supports adding songs, but its live queue cannot be rewritten by this app. In that case queue additions append instead of pretending that a remote reorder succeeded.

References: src/…/queue.rs• L341-355 src/…/queue.rs• L406-485 src/app.rs• L7383-7415 src/player.rs• L288-315

Queue state and display

The queue view prefers the local player snapshot when the Web API is briefly behind after a skip. It refreshes after track changes and queue edits, and it rejects stale responses when a newer queue action has already changed the expected order.

The queue can also save the current and upcoming local view as a playlist. A separate Recent tab uses the merged listening history rather than the active playback queue.

References: src/…/queue.rs• L15-35 src/…/queue.rs• L286-303 src/…/queue.rs• L356-382 src/app.rs• L555-571

See Player control and audio output for the player-facing control contract.

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep NowPlaying fields aligned with both local LocalState and remote playback snapshots. A missing field can make the same control behave differently by target.
  • Keep device preference keys stable across Spotify device rows and network receiver rows. Changing a key silently resets picker ordering.
  • Keep local queue capability checks aligned with queue actions. Remote targets must not receive local reorder, insert, or remove operations.
  • Keep output-device migration compatible with both stable ids and older saved names.
  • Keep local-history merge rules aligned with the timestamps used when a play is counted and when Spotify reports it.
  • Keep load handling aligned with the repeat preference. A new context must not reset repeat mode when the request does not set one.
  • Keep reconnect handling aligned with both the Connect session state and the carried local track. A session change must not stop or restart audio at the wrong position.

Important failure modes

TriggerConsequenceGuard
The selected audio output is missingLocal playback falls back to the system default or reports that no output is availableResolve saved ids and names when opening the sink; show the output error without stopping the app
A remote device refuses volume controlThe volume control cannot change that deviceUse the target's can_set_volume capability before enabling the slider
A local queue action races with a queue refreshA stale response could restore the old order or a removed rowTrack queue request and edit state, then discard responses that no longer match
A local play is also returned by SpotifyThe Recent view could show one listen twiceMatch local and remote records within the duplicate time window
A network receiver is advertised but does not answerThe receiver is not offered as a usable targetResolve receiver information before adding it to the normal device list
A Connect session ends while local audio still has a trackAudio can stop or resume from an old position after reconnectKeep the interrupted track and current position, then restore the carried player through the new session
A new load omits repeat optionsRepeat can change unexpectedly when the context changesPass the current repeat mode to each ordinary load unless the request sets a new mode

Key files

FileWhy to read it
src/player.rsDefines the local player state, playback commands, Connect session, event updates, audio sink setup, and resume behavior
src/app.rsConnects local and remote targets into one app-level playback and queue model
src/sink.rsExplains the local audio boundary, output selection, buffering, fades, and failure reporting
src/resample.rsExplains how audio remains continuous when the device rate differs from Spotify's rate
src/…/player_bar.rsShows the user-facing transport, progress, volume, device, and queue controls
src/…/devices.rsShows how Connect devices, network receivers, and local outputs appear in one picker
src/zeroconf.rsDescribes discovery and account setup for receivers not yet listed by Spotify
src/device_history.rsDefines account-scoped ordering preferences for device selection
src/history.rsDefines local play counting and merging with Spotify's recent-play records
src/…/queue.rsShows the queue's ownership model and its relationship to playback state