fix(cast): seek by fraction of the cast track duration

The seekbar derived the absolute position from the local core's playback
duration, which is 0/stale while casting (the local backend is stopped),
so fraction * duration collapsed to ~0 and every drag restarted the
track. Resolve the real duration from the cast track's catalog metadata
instead (new seek_fraction_if_cast). Fixes seek on both Chromecast and
DLNA.

cc
This commit is contained in:
vicrodh committed 2026-07-17 21:22:36 -06:00
1 parent 142142e317
commit e84d1035f8
2 files changed
+38 -3

No files matched your search

+29
View File
@@ -555,6 +555,35 @@ impl SlintCastService {
Ok(true)
}
/// Seek to a 0..1 fraction of the CURRENT cast track.
///
/// The seekbar cannot derive the absolute position from the local core's
/// playback duration while casting: the local backend is stopped, so its
/// duration reads 0 (or a stale value from the last local track), and
/// `fraction * duration` collapses to ~0 — every drag restarts the track.
/// Resolve the real duration from the cast track's catalog metadata (the
/// same source the position poll uses) instead.
pub async fn seek_fraction_if_cast(&self, fraction: f64) -> Result<bool, String> {
if !self.is_casting().await {
return Ok(false);
}
let dur = self
.runtime
.core()
.current_track()
.await
.map(|t| t.duration_secs as f64)
.unwrap_or(0.0);
if dur <= 0.0 {
// No usable duration — swallow the seek rather than jump to 0 and
// restart the track. Reports handled (true) so the caller stops.
return Ok(true);
}
let secs = (fraction.clamp(0.0, 1.0) * dur).max(0.0);
self.seek_secs(secs).await?;
Ok(true)
}
pub async fn set_volume_if_cast(&self, volume: f32) -> Result<bool, String> {
let proto = {
let inner = self.inner.lock().await;
+9 -3
View File
@@ -12854,9 +12854,15 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let handle = handle.clone();
handle.clone().spawn(async move {
if let Some(cast) = cast_service::service() {
let frac = fraction.clamp(0.0, 1.0) as f64;
let dur = runtime.core().get_playback_state().duration as f64;
match cast.seek_if_cast(frac * dur).await {
// Pass the raw fraction: the cast service resolves the
// real duration from the cast track. The local core's
// duration is 0/stale while casting (backend stopped),
// so `fraction * core_duration` would seek to ~0 and
// restart the track on every drag.
match cast
.seek_fraction_if_cast(fraction.clamp(0.0, 1.0) as f64)
.await
{
Ok(true) => return,
Ok(false) => {}
Err(e) => {