getting radio section dialed in

irc-tor
lza_menace 2 years ago
parent c74f60fb7e
commit 1b60fbe149

@ -1,4 +1,7 @@
use eframe::egui;
use egui::FontFamily::Proportional;
use egui::FontId;
use egui::TextStyle::*;
use crate::player::Player;
pub struct App {
@ -19,40 +22,27 @@ impl Default for App {
impl eframe::App for App {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
ui.heading("lza gui");
let mut style = (*ctx.style()).clone();
// style.visuals come to SD
style.text_styles = [
(Heading, FontId::new(30.0, Proportional)),
(Name("Heading2".into()), FontId::new(25.0, Proportional)),
(Name("Context".into()), FontId::new(23.0, Proportional)),
(Body, FontId::new(18.0, Proportional)),
(Monospace, FontId::new(14.0, Proportional)),
(Button, FontId::new(14.0, Proportional)),
(Small, FontId::new(10.0, Proportional)),
].into();
// style.spacing.item_spacing = egui::vec2(10.0, 20.0);
ctx.set_style(style);
ctx.set_visuals(egui::Visuals::dark());
// ctx.set_visuals(egui::Visuals::noninteractive(egui::style::WidgetVisuals::));
egui::TopBottomPanel::top("top").show(ctx, |ui| {
ui.heading("Wownero Operations Center");
ui.label("Made by ya boi, lza_menace");
ui.hyperlink("https://lzahq.tech");
ui.separator();
ui.horizontal(|ui| {
if ui.button("▶").clicked() {
// If stream thread is done, start again
if self.player.stream_thread.is_finished() {
self.player.stream_thread = self.player.start_radio_stream();
}
if self.player.sink.len() != 1 {
let source: rodio::Decoder<std::io::BufReader<std::fs::File>> = self.player.get_radio_source();
let _ = &self.player.sink.append(source);
}
let _ = &self.player.sink.play();
self.player.playing = true;
}
if ui.button("■").clicked() {
let _ = &self.player.sink.pause();
self.player.playing = false;
}
});
ui.add(egui::Slider::new(&mut self.player.volume, 0.0..=100.0).text("Volume"));
self.player.sink.set_volume(self.player.volume / 100.0);
if self.player.playing {
ui.label(format!("Now Playing: {:?}", self.player.get_song_meta()));
ui.label(format!("Stream URL: {:?}", self.player.stream_source));
}
});
egui::CentralPanel::default().show(ctx, |_ui| {
// ui.separator();
// ui.heading("Tor");
// if self.tor_started {
@ -73,5 +63,39 @@ impl eframe::App for App {
// }
// }
});
egui::TopBottomPanel::bottom("radio_player").show(ctx, |ui| {
ui.heading(egui::RichText::new("WOW!Radio").color(egui::Color32::GREEN));
ui.label(egui::RichText::new("Your home for the most diabolical playlist of the century, \nmade by the skeevers, scallywags, chupacabras, and whores\n of the Wownero community. Join da chat to peep da scoop.\n").color(egui::Color32::GREEN));
ui.horizontal(|ui| {
if self.player.playing {
if ui.button("⏸").clicked() {
let _ = &self.player.sink.pause();
self.player.playing = false;
}
} else {
if ui.button("▶").clicked() {
// If stream thread is done, start again
if self.player.stream_thread.is_finished() {
self.player.stream_thread = self.player.start_radio_stream();
}
if self.player.sink.len() != 1 {
let source: rodio::Decoder<std::io::BufReader<std::fs::File>> = self.player.get_radio_source();
let _ = &self.player.sink.append(source);
}
let _ = &self.player.sink.play();
self.player.playing = true;
}
}
if ! self.player.stream_thread.is_finished() {
ui.spinner();
ui.label(format!("{:?}", self.player.stream_source));
}
});
if self.player.playing {
ui.label(egui::RichText::new(format!("\n{:?}", self.player.get_song_meta())).color(egui::Color32::WHITE).size(24.0));
} else {
ui.label("\n");
}
});
}
}

@ -49,13 +49,18 @@ impl Player {
}
pub fn get_song_meta(&self) -> String {
let mut file = std::fs::File::open(&crate::RADIO_STREAM).unwrap();
let mut buffer = [0u8; 384];
file.read_exact(&mut buffer).unwrap();
let s = std::string::String::from_utf8_lossy(&buffer);
let re = regex::Regex::new(r"title=(.*).{4}server=").unwrap();
let caps = re.captures(&s).unwrap();
return caps.get(1).map_or("", |m| m.as_str()).to_owned();
let file = std::fs::File::open(&crate::RADIO_STREAM);
match file {
Ok(mut file) => {
let mut buffer = [0u8; 384];
file.read_exact(&mut buffer).unwrap();
let s = std::string::String::from_utf8_lossy(&buffer);
let re = regex::Regex::new(r"title=(.*).{4}server=").unwrap();
let caps = re.captures(&s).unwrap();
return caps.get(1).map_or("", |m| m.as_str()).to_owned();
},
Err(_e) => "".to_owned()
}
}
pub fn get_radio_source(&self) -> rodio::Decoder<std::io::BufReader<std::fs::File>> {