fix(slint): keep the bar/queue in sync while casting

Smoke-test fixes after the first real Chromecast session:

- Local 450ms poll now skips the bar update while casting (it was pushing the
  stopped local player's position=0/playing=false/local-volume every tick,
  fighting the cast poll → seekbar flicker, wrong play icon, dead volume bar).
  The cast poll owns the bar, mirroring the existing QConnect-controller skip.
- Cast poll + connection-state push now set NowPlayingState.playing (the
  play/pause icon was stuck on play), and set_volume_if_cast pushes the slider
  position (the local set_volume that normally moves it is skipped while casting).
- next/previous no longer use a cast-only path: that advanced the renderer +
  core cursor but never refreshed the card/queue, and left the cursor desynced
  so queue-click resolved the wrong track. They now run the local
  next()/previous() flow (move cursor -> refresh card+queue -> play_audible
  casts the new track), keeping UI + renderer in sync. Auto-advance on track end
  uses the same local next() flow.

cc
This commit is contained in:
vicrodh committed 2026-06-18 12:03:27 -06:00
1 parent d525e4670a
commit 88cf79e1e5
3 files changed
+52 -44

No files matched your search

+28 -24
View File
@@ -539,6 +539,14 @@ impl SlintCastService {
}
}
}
// Reflect the drag on the bar: the local set_volume (which normally
// moves the slider) is skipped while casting, and the cast poll doesn't
// push volume, so update NowPlayingState.volume here.
let weak = self.window.clone();
let _ = weak.upgrade_in_event_loop(move |w| {
use slint::ComponentHandle;
w.global::<NowPlayingState>().set_volume(v);
});
Ok(true)
}
@@ -555,27 +563,10 @@ impl SlintCastService {
Ok(true)
}
/// Advance the QBZ queue and cast the new current track. Ok(false) = not
/// casting.
pub async fn next_if_cast(self: &Arc<Self>) -> Result<bool, String> {
if !self.is_casting().await {
return Ok(false);
}
if let Some(track) = self.runtime.core().next_track().await {
self.cast_track(&track).await?;
}
Ok(true)
}
pub async fn previous_if_cast(self: &Arc<Self>) -> Result<bool, String> {
if !self.is_casting().await {
return Ok(false);
}
if let Some(track) = self.runtime.core().previous_track().await {
self.cast_track(&track).await?;
}
Ok(true)
}
// NOTE: next/previous are intentionally NOT handled here. While casting, the
// local playback::next/previous flow runs (it moves the core cursor +
// refreshes the card/queue), and play_audible casts the new current track.
// A cast-only advance would desync the UI cursor from the renderer.
async fn seek_secs(&self, secs: f64) -> Result<(), String> {
let proto = {
@@ -767,14 +758,22 @@ impl SlintCastService {
np.set_progress((position / duration.max(1.0)).clamp(0.0, 1.0) as f32);
np.set_position_secs(position as i32);
np.set_duration_secs(duration as i32);
np.set_seekable_max(1.0);
np.set_elapsed(format_mmss(position).into());
np.set_remaining(format_mmss((duration - position).max(0.0)).into());
np.set_playing(playing);
});
if ended {
log::info!("[Cast] track ended (state={state}); auto-advancing");
if let Err(e) = self.next_if_cast().await {
log::warn!("[Cast] auto-advance failed: {e}");
}
// Run the SAME local advance the next button uses: it moves the
// core cursor, refreshes the card + queue, and play_audible casts
// the new current track. Keeps the UI and renderer in sync.
crate::playback::next(
self.runtime.clone(),
self.window.clone(),
tokio::runtime::Handle::current(),
);
}
}
@@ -893,6 +892,11 @@ impl SlintCastService {
let np = w.global::<NowPlayingState>();
np.set_cast_active(connected);
np.set_cast_protocol(protocol.into());
// Keep the bar's play/pause icon in sync immediately (the local poll
// is skipped while casting).
if connected {
np.set_playing(playing);
}
});
}
+9 -20
View File
@@ -6744,16 +6744,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let weak = weak.clone();
let handle = handle.clone();
handle.clone().spawn(async move {
if let Some(cast) = cast_service::service() {
match cast.next_if_cast().await {
Ok(true) => return,
Ok(false) => {}
Err(e) => {
log::warn!("[Cast] next: {e}");
return;
}
}
}
// NOTE: no cast-specific branch here. While casting, the local
// next() flow runs — it moves the core cursor, refreshes the
// now-playing card + queue, and calls play_audible, which casts
// the new current track (the play_audible cast gate). Routing
// next() through a cast-only path would advance the renderer but
// leave the UI cursor stale (and then queue-click resolves
// against the wrong index).
if let Some(svc) = qconnect_service::service() {
match svc.skip_next_if_remote().await {
Ok(true) => return,
@@ -6777,16 +6774,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let weak = weak.clone();
let handle = handle.clone();
handle.clone().spawn(async move {
if let Some(cast) = cast_service::service() {
match cast.previous_if_cast().await {
Ok(true) => return,
Ok(false) => {}
Err(e) => {
log::warn!("[Cast] previous: {e}");
return;
}
}
}
// See on_next: no cast branch — the local previous() flow keeps
// the cursor + UI in sync and play_audible casts the new track.
if let Some(svc) = qconnect_service::service() {
match svc.skip_previous_if_remote().await {
Ok(true) => return,
+15
View File
@@ -3488,6 +3488,21 @@ pub fn start_poll_loop(
// Lyrics position source back to the local player (Q7 resolver).
crate::lyrics_sync::clear_remote_anchor();
// --- CAST mode: the cast service's own 1s poll owns the bar -------
// While a Chromecast/DLNA renderer is connected the local player is
// stopped, so the local path below would push position=0 /
// playing=false / local-volume every 450ms and fight the cast poll
// (the reported seekbar flicker, wrong play icon, dead volume bar).
// Skip it entirely; cast_service::poll_once drives the bar.
if let Some(cast) = crate::cast_service::service() {
if cast.is_casting().await {
last_track_id = 0;
was_playing = false;
seen_position = 0;
continue;
}
}
let event = runtime.core().player().get_playback_event();
let track_id = event.track_id;