Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ffe7cd0090 | |||
| 907a734be3 | |||
| 135700ce02 | |||
| ea72368841 |
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "cm-player"
|
||||
version = "0.1.14"
|
||||
version = "0.1.18"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
||||
10
src/main.rs
10
src/main.rs
@ -183,8 +183,10 @@ async fn run_app<B: ratatui::backend::Backend>(
|
||||
let new_position = player.get_position().unwrap_or(0.0);
|
||||
let new_duration = player.get_duration().unwrap_or(0.0);
|
||||
|
||||
// Only mark as changed if position moved by at least 0.5 seconds
|
||||
if (new_position - last_position).abs() >= 0.5 {
|
||||
// Only update if displayed value (rounded to seconds) changed
|
||||
let old_display_secs = last_position as u32;
|
||||
let new_display_secs = new_position as u32;
|
||||
if new_display_secs != old_display_secs {
|
||||
state.current_position = new_position;
|
||||
last_position = new_position;
|
||||
state_changed = true;
|
||||
@ -348,7 +350,7 @@ async fn handle_key_event<B: ratatui::backend::Backend>(terminal: &mut Terminal<
|
||||
let max_items = match menu.menu_type {
|
||||
ContextMenuType::FilePanel => 2,
|
||||
ContextMenuType::Playlist => 2,
|
||||
ContextMenuType::TitleBar => 3,
|
||||
ContextMenuType::TitleBar => 4,
|
||||
};
|
||||
if menu.selected_index < max_items - 1 {
|
||||
menu.selected_index += 1;
|
||||
@ -700,7 +702,7 @@ fn handle_mouse_event(state: &mut AppState, mouse: MouseEvent, title_bar_area: r
|
||||
let items = match menu.menu_type {
|
||||
ContextMenuType::FilePanel => 2,
|
||||
ContextMenuType::Playlist => 2,
|
||||
ContextMenuType::TitleBar => 3,
|
||||
ContextMenuType::TitleBar => 4,
|
||||
};
|
||||
let popup_width = 13;
|
||||
let popup_height = items as u16 + 2; // +2 for borders
|
||||
|
||||
@ -21,6 +21,7 @@ pub struct Player {
|
||||
pub audio_codec: Option<String>,
|
||||
pub audio_bitrate: Option<f64>,
|
||||
pub sample_rate: Option<i64>,
|
||||
pub cache_duration: Option<f64>,
|
||||
}
|
||||
|
||||
impl Player {
|
||||
@ -62,6 +63,7 @@ impl Player {
|
||||
audio_codec: None,
|
||||
audio_bitrate: None,
|
||||
sample_rate: None,
|
||||
cache_duration: None,
|
||||
})
|
||||
}
|
||||
|
||||
@ -119,6 +121,7 @@ impl Player {
|
||||
self.audio_codec = None;
|
||||
self.audio_bitrate = None;
|
||||
self.sample_rate = None;
|
||||
self.cache_duration = None;
|
||||
|
||||
// Wait for socket to be created and mpv to be ready
|
||||
std::thread::sleep(Duration::from_millis(800));
|
||||
@ -303,6 +306,13 @@ impl Player {
|
||||
if let Some(val) = self.get_property("audio-params/samplerate") {
|
||||
self.sample_rate = val.as_i64();
|
||||
}
|
||||
|
||||
// Update cache duration (how many seconds are buffered ahead)
|
||||
if let Some(val) = self.get_property("demuxer-cache-duration") {
|
||||
self.cache_duration = val.as_f64();
|
||||
} else {
|
||||
self.cache_duration = None;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_position(&self) -> Option<f64> {
|
||||
|
||||
@ -34,7 +34,7 @@ pub fn render(frame: &mut Frame, state: &mut AppState, player: &Player) -> (Rect
|
||||
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)])
|
||||
.split(main_chunks[1]);
|
||||
|
||||
render_title_bar(frame, state, main_chunks[0]);
|
||||
render_title_bar(frame, state, player, main_chunks[0]);
|
||||
render_file_panel(frame, state, content_chunks[0]);
|
||||
render_right_panel(frame, state, content_chunks[1]);
|
||||
render_status_bar(frame, state, player, main_chunks[2]);
|
||||
@ -349,7 +349,7 @@ fn render_right_panel(frame: &mut Frame, state: &mut AppState, area: Rect) {
|
||||
frame.render_stateful_widget(playlist_widget, area, &mut playlist_state);
|
||||
}
|
||||
|
||||
fn render_title_bar(frame: &mut Frame, state: &AppState, area: Rect) {
|
||||
fn render_title_bar(frame: &mut Frame, state: &AppState, _player: &Player, area: Rect) {
|
||||
let background_color = match state.player_state {
|
||||
PlayerState::Playing => Theme::success(), // Green for playing
|
||||
PlayerState::Paused => Theme::highlight(), // Blue for paused
|
||||
@ -521,7 +521,7 @@ fn render_status_bar(frame: &mut Frame, state: &AppState, player: &Player, area:
|
||||
left_parts.push(title.clone());
|
||||
}
|
||||
|
||||
// Right side: Bitrate | Codec | Sample rate
|
||||
// Right side: Bitrate | Codec | Sample rate | Cache
|
||||
if let Some(bitrate) = player.audio_bitrate {
|
||||
right_parts.push(format!("{:.0} kbps", bitrate));
|
||||
}
|
||||
@ -534,6 +534,12 @@ fn render_status_bar(frame: &mut Frame, state: &AppState, player: &Player, area:
|
||||
right_parts.push(format!("{} Hz", samplerate));
|
||||
}
|
||||
|
||||
if let Some(cache_dur) = player.cache_duration {
|
||||
if cache_dur > 0.0 {
|
||||
right_parts.push(format!("{:.1}s", cache_dur));
|
||||
}
|
||||
}
|
||||
|
||||
// Create layout for left and right sections
|
||||
let chunks = Layout::default()
|
||||
.direction(Direction::Horizontal)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user