feat(player): add click-to-seek on progress bar

This commit is contained in:
accusys
2026-03-19 01:47:24 +08:00
parent 263daa0763
commit 643accfc92

View File

@@ -257,6 +257,34 @@ fn run(config: &Config) -> Result<()> {
} }
} }
} }
sdl2::event::Event::MouseButtonDown { x, y, .. } => {
let progress_y = config.height as i32 - progress_height + 5;
let bar_height = 20i32;
if y >= progress_y
&& y <= progress_y + bar_height
&& player_state.total_frames > 0
{
let bar_x_start = 10i32;
let bar_width = config.width as i32 - 20;
if x >= bar_x_start && x <= bar_x_start + bar_width {
let ratio = (x - bar_x_start) as f64 / bar_width as f64;
let target_frame = (player_state.total_frames as f64 * ratio) as u64;
if let Some(ref mut dec) = decoder {
let time_ms =
((target_frame as f64 / player_state.fps) * 1000.0) as u64;
if dec.seek(time_ms).is_ok() {
player_state.current_frame = target_frame;
player_state.current_time_ms = time_ms;
info!(
"Seeked to frame {} ({:.1}%)",
target_frame,
ratio * 100.0
);
}
}
}
}
}
_ => {} _ => {}
} }
} }