* fix(audio): release idle output stream after 60s (#1071)
Lazy-open CPAL on first playback and close the device handle after one
minute without active audio so Windows can sleep; emit output-released
for cold resume and skip post-wake reopen when idle.
* docs: CHANGELOG and credits for idle audio stream fix (PR #1073)
* fix(audio): satisfy clippy if-same-then-else in idle watcher
* fix(audio): silence rodio DeviceSink drop unless logging is debug
Gate log_on_drop(false) on runtime should_log_debug() so normal/off
logging modes avoid stderr noise from intentional idle stream release.
* feat(audio): cold-start paused restore and silent engine prepare
After getPlayQueue on startup, apply saved seek position to the UI,
prefetch the current track to hot cache, and load the engine paused via
new audio_play startPaused so playback does not audibly start before
pause. Shared engineLoadTrackAtPosition with queue-undo restore.
* fix(audio): satisfy clippy too_many_arguments on stream arm helper
Bundle spawn_legacy_stream_start_when_armed parameters into
LegacyStreamStartWhenArmed so workspace clippy passes.
* fix(audio): release output stream immediately on stop (#1071)
Stop and natural queue end call audio_stop; close the CPAL device right
away instead of waiting for the 60s idle timer. Pause keeps the grace
period for warm resume.
* fix(audio): keep waveform mounted after stop (#1071)
Stop preserves currentTrack, so its cached analysis waveform stays valid.
Stop no longer nulls waveformBins for the still-shown track and re-hydrates
them from the analysis DB, instead of dropping to flat placeholder bars.
* test(audio): cover output_stream_is_needed branches; harden audio_play arg (#1071)
- Add unit tests for the idle-keepalive decision: empty/playing/paused main
sink, preview and fading-out sinks, and radio playing/paused. Players are
built device-less via rodio's Player::new + a Zero source, so empty()/state
are exercised without an audio device.
- Make audio_play's `start_paused` an Option<bool> defaulting to false, so the
new field is strictly additive (omitting startPaused no longer fails serde).
- Drop the unused `_engine` parameter from start_stream_idle_watcher; it
resolves the engine from the AppHandle each poll.
* refactor(audio): extract sink-swap lifecycle into sink_swap module (#1071)
Move SinkSwapInputs/swap_in_new_sink and the legacy stream-arm helper
(LegacyStreamStartWhenArmed/spawn_legacy_stream_start_when_armed) out of
play_input.rs into a focused sink_swap.rs, so source selection and source
building stay separate from sink lifecycle. play_input.rs drops from 953 to
799 lines. No behavior change.
* fix(audio): resume playback seamlessly on output device switch (#743)
When the OS default output device changed (Bluetooth, USB DAC, HDMI),
rodio/cpal had to reopen the stream, which silently stopped the active
sink and left the engine with no playback — causing the track to restart
from the beginning (or not restart at all after the null-payload bug).
Root cause (null-payload):
audio_set_device emitted () (unit), which Tauri serialises to JSON
null. The null-guard added for the "Rust handled replay internally"
signal was therefore also triggered by manual device switches, so
playTrack was never called and the engine stayed silent.
Fix: audio_set_device now emits the current playback position as f64
(null remains the exclusive "Rust handled" sentinel).
Rust-side seamless replay (device watcher path):
reopen_output_stream captures a ResumeSnapshot before the blocking
stream reopen, then calls try_resume_after_device_change, which:
- local files (psysonic-local://): reopens the file, builds a new
seekable source, seeks to the saved position — zero frontend
round-trip, no audible restart.
- fully-cached HTTP tracks (stream_completed_cache / spill file):
replays from the in-memory or on-disk bytes — no re-download.
- partial downloads / radio / paused: returns false → falls back to
the existing frontend path (seekFallbackVisualTarget + playTrack).
Frontend (useAudioDeviceBridge):
null payload → Rust already resumed; skip playTrack.
number payload → call playTrack + seekFallbackVisualTarget(position).
Visibility: pub(super) → pub(crate) on the play_input / progress_task
helpers that device_watcher.rs needs to call directly.
* refactor(audio): split device_resume module; add bridge tests
Split the 551-line device_watcher.rs (above the ~500-line soft ceiling)
by extracting ResumeSnapshot and try_resume_after_device_change into a
dedicated device_resume.rs module. device_watcher.rs is now 320 lines,
device_resume.rs 258 lines.
Add useAudioDeviceBridge.test.ts: 9 characterisation tests covering the
null-payload guard ("Rust replayed, skip playTrack"), the seek-fallback
path (position > 0.5 s sets seekFallbackVisualTarget), paused-device
branch (resetAudioPause), and the device-reset event path.
* chore(changelog): add entry for #765 (device switch seamless resume)
Moves all audio playback code (Symphonia decode, rodio output, HTTP
streaming, gapless, previews, and the seven stream/ source-type
submodules from the prior split) out of the top crate into a new
psysonic-audio crate.
crates/psysonic-audio/ new lib crate, depends on
psysonic-core + psysonic-analysis
src/{engine,helpers,decode,…}.rs flattened layout (no more
extra audio/ namespace level)
src/stream/ seven submodules from M0
src/lib.rs re-exports macros from
psysonic-core and the public
API surface
The audio↔analysis edges identified in the dep survey are now real
crate deps (audio depends on analysis directly: AnalysisCache reads,
recommended_gain_for_target, submit_analysis_cpu_seed). Only the
analysis→audio back-edge goes through the PlaybackQueryHandle port
registered in M2.
Cross-crate ref migrations applied via batch sed:
crate::audio::* → crate::* (intra-crate)
crate::analysis_cache::* → psysonic_analysis::analysis_cache::*
crate::submit_analysis_cpu_seed → psysonic_analysis::analysis_runtime::*
crate::subsonic_wire_user_agent → psysonic_core::user_agent::*
Top crate keeps `crate::audio::*` paths working via
`pub use psysonic_audio as audio;` — lib_commands/cli callers untouched.
`stop_audio_engine` (mac process-exit cleanup) moved into the audio
crate as `pub fn stop_audio_engine` since it reaches AudioEngine
internals; tray.rs now re-exports the moved fn.
Two small visibility promotions in engine.rs:
pub(crate) fn analysis_track_id_is_current_playback → pub
pub(crate) fn ranged_loudness_backfill_should_defer → pub
Behaviour preserving. Cargo check + clippy --workspace clean.