Skip to content

Commit 9acf05c

Browse files
committed
Fix bitrate stream parse and add URL to Track Info pane
1 parent 420503f commit 9acf05c

3 files changed

Lines changed: 46 additions & 14 deletions

File tree

src/audio.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,21 @@ impl AudioSource for FfmpegSource {
10251025

10261026
fn get_video_info(&mut self) -> Option<String> { self.video_info.clone() }
10271027

1028+
fn get_bitrate(&mut self) -> Option<u32> {
1029+
if let Some(icy_br) = self.ictx.metadata().get("icy-br") {
1030+
if let Ok(br) = icy_br.parse::<u32>() {
1031+
return Some(br);
1032+
}
1033+
}
1034+
1035+
let br = self.ictx.bit_rate();
1036+
if br > 0 {
1037+
return Some((br / 1000) as u32);
1038+
}
1039+
1040+
None
1041+
}
1042+
10281043
fn attach_video_queue(&mut self, tx: crossbeam_channel::Sender<(u64, ffmpeg_next::Packet)>) {
10291044
self.video_tx = Some(tx);
10301045
}
@@ -1113,15 +1128,7 @@ impl AudioSource for VideoOnlySource {
11131128
fn get_current_row(&mut self) -> i32 { 0 }
11141129
fn get_video_info(&mut self) -> Option<String> { self.video_info.clone() }
11151130

1116-
fn get_bitrate(&mut self) -> Option<u32> {
1117-
let br = self.ictx.bit_rate();
1118-
if br > 0 {
1119-
Some((br / 1000) as u32)
1120-
} else {
1121-
None
1122-
}
1123-
}
1124-
1131+
11251132
fn attach_video_queue(&mut self, tx: crossbeam_channel::Sender<(u64, ffmpeg_next::Packet)>) {
11261133
self.video_tx = Some(tx);
11271134
}

src/engine.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1948,8 +1948,9 @@ impl<'a> VulkanEngine<'a> {
19481948
egui::RichText::new(format!("Visualization Shader (GPU): {:.2} ms", total_vis_us / 1000.0))
19491949
.color(egui::Color32::LIGHT_BLUE)
19501950
);
1951+
let buffer_label = if state.duration_seconds <= 0.0 { "Network Buffer" } else { "Audio Buffer" };
19511952
ui.label(
1952-
egui::RichText::new(format!("Audio Buffer: {:.1}%", state.stats.audio_buffer_fill_pct))
1953+
egui::RichText::new(format!("{}: {:.1}%", buffer_label, state.stats.audio_buffer_fill_pct))
19531954
.color(if state.stats.audio_buffer_fill_pct < 5.0 { egui::Color32::RED } else if state.stats.audio_buffer_fill_pct > 95.0 { egui::Color32::YELLOW } else { egui::Color32::GREEN })
19541955
);
19551956
if state.video_frame_rx.is_some() {
@@ -2937,12 +2938,27 @@ impl<'a> VulkanEngine<'a> {
29372938
columns[2].style_mut().visuals.override_text_color = Some(egui::Color32::from_gray(235)); // Slightly lighter for contrast
29382939
columns[2].heading("Track Info");
29392940
columns[2].separator();
2940-
let title_path = std::path::Path::new(&state.song_title);
2941-
let file_name = title_path.file_name().unwrap_or_default().to_string_lossy().to_string();
2942-
let file_dir = title_path.parent().unwrap_or(std::path::Path::new("")).to_string_lossy().to_string();
2941+
let current_path_str = if state.playlist_index < state.playlist.len() {
2942+
state.playlist[state.playlist_index].clone()
2943+
} else {
2944+
state.song_title.clone()
2945+
};
2946+
2947+
let is_network = current_path_str.starts_with("http://") || current_path_str.starts_with("https://");
2948+
let file_name = if is_network {
2949+
state.song_title.clone()
2950+
} else {
2951+
std::path::Path::new(&state.song_title).file_name().unwrap_or_default().to_string_lossy().to_string()
2952+
};
2953+
let file_dir = if is_network {
2954+
current_path_str
2955+
} else {
2956+
std::path::Path::new(&current_path_str).parent().unwrap_or(std::path::Path::new("")).to_string_lossy().to_string()
2957+
};
2958+
29432959
columns[2].horizontal(|ui| { ui.label("File/Title"); ui.label(&file_name); });
29442960
columns[2].horizontal(|ui| { ui.label("Artist"); ui.label(&state.artist); });
2945-
columns[2].horizontal(|ui| { ui.label("Path"); ui.label(&file_dir); });
2961+
columns[2].horizontal(|ui| { ui.label(if is_network { "URL" } else { "Path" }); ui.label(&file_dir); });
29462962
if state.playlist.len() > 1 {
29472963
columns[2].horizontal(|ui| { ui.label("Playlist"); ui.label(format!("{} / {}", state.playlist_index + 1, state.playlist.len())); });
29482964
}

src/ui.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,17 @@ pub fn draw(f: &mut Frame, state: &AppState) {
157157

158158

159159
// 3. Metadata
160+
let current_path_str = if state.playlist_index < state.playlist.len() {
161+
state.playlist[state.playlist_index].clone()
162+
} else {
163+
state.song_title.clone()
164+
};
165+
let is_network = current_path_str.starts_with("http://") || current_path_str.starts_with("https://");
166+
let path_label = if is_network { "URL".to_string() } else { "Path".to_string() };
167+
160168
let meta_table = Table::new(
161169
vec![
170+
Row::new(vec![path_label, current_path_str]),
162171
Row::new(vec!["Title".to_string(), state.song_title.clone()]),
163172
Row::new(vec!["Artist".to_string(), state.artist.clone()]),
164173
Row::new(vec!["Type".to_string(), state.module_type.clone()]),

0 commit comments

Comments
 (0)