feat(player): add click-to-seek on progress bar
This commit is contained in:
28
src/main.rs
28
src/main.rs
@@ -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
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user