parent
190bf16af7
commit
6a193faf8e
@ -0,0 +1,80 @@
|
||||
use eframe::egui;
|
||||
use crate::player::Player;
|
||||
|
||||
pub struct App {
|
||||
pub player: Player,
|
||||
pub tor_started: bool,
|
||||
pub to_data: String
|
||||
}
|
||||
|
||||
impl Default for App {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
tor_started: false,
|
||||
to_data: "".to_owned(),
|
||||
player: Player::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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");
|
||||
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() {
|
||||
ui.label("Starting stream...");
|
||||
std::thread::sleep(std::time::Duration::from_secs(3));
|
||||
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();
|
||||
}
|
||||
|
||||
if ui.button("■").clicked() {
|
||||
let _ = &self.player.sink.pause();
|
||||
}
|
||||
|
||||
if ui.button("status").clicked() {
|
||||
println!(
|
||||
"is_paused: {}. empty: {}. len: {}. volume: {}.",
|
||||
&self.player.sink.is_paused(),
|
||||
&self.player.sink.empty(),
|
||||
&self.player.sink.len(),
|
||||
&self.player.sink.volume()
|
||||
)
|
||||
}
|
||||
});
|
||||
|
||||
// ui.separator();
|
||||
// ui.heading("Tor");
|
||||
// if self.tor_started {
|
||||
// ui.label("Tor started.");
|
||||
// if ui.button("Clear Tor logs").clicked() {
|
||||
// let _r: std::io::Result<()> = clear_tor_log();
|
||||
// }
|
||||
// ui.collapsing("View Tor logs:", |ui| {
|
||||
// egui::ScrollArea::vertical().stick_to_bottom(true).show(ui, |ui| {
|
||||
// let contents = std::fs::read_to_string(TOR_LOG.to_string()).unwrap();
|
||||
// ui.label(contents);
|
||||
// });
|
||||
// });
|
||||
// } else {
|
||||
// if ui.button("Start Tor").clicked() {
|
||||
// let _t: std::thread::JoinHandle<Result<u8, libtorError>> = start_tor();
|
||||
// self.tor_started = true;
|
||||
// }
|
||||
// }
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
|
||||
|
||||
pub struct Player {
|
||||
pub sink: rodio::Sink,
|
||||
pub stream_thread: std::thread::JoinHandle<()>,
|
||||
pub stream_handle: rodio::OutputStreamHandle,
|
||||
pub volume: f32
|
||||
}
|
||||
|
||||
impl Player {
|
||||
pub fn new(sink: rodio::Sink, stream_handle: rodio::OutputStreamHandle) -> Self {
|
||||
Self {
|
||||
sink,
|
||||
stream_handle,
|
||||
stream_thread: std::thread::spawn(|| {}),
|
||||
volume: 1.0
|
||||
}
|
||||
}
|
||||
|
||||
pub fn default() -> Self {
|
||||
let (_stream, stream_handle) = rodio::OutputStream::try_default().unwrap();
|
||||
let sink = rodio::Sink::try_new(&stream_handle).unwrap();
|
||||
Self::new(sink, stream_handle)
|
||||
}
|
||||
|
||||
pub fn start_radio_stream(&self) -> std::thread::JoinHandle<()> {
|
||||
let t: Result<std::thread::JoinHandle<()>, std::io::Error> = std::thread::Builder::new().name("radio_stream".to_string()).spawn(move || {
|
||||
let mut res: reqwest::blocking::Response = reqwest::blocking::get("https://radio.wownero.com/wow.ogg").expect("request failed");
|
||||
let mut out: std::fs::File = std::fs::File::create(crate::RADIO_STREAM).expect("failed to create file");
|
||||
std::io::copy(&mut res, &mut out).expect("failed to copy content");
|
||||
});
|
||||
return t.unwrap()
|
||||
}
|
||||
|
||||
pub fn get_radio_source(&self) -> rodio::Decoder<std::io::BufReader<std::fs::File>> {
|
||||
let file: std::io::BufReader<std::fs::File> = std::io::BufReader::new(std::fs::File::open(crate::RADIO_STREAM).unwrap());
|
||||
let source: rodio::Decoder<std::io::BufReader<std::fs::File>> = rodio::Decoder::new(file).unwrap();
|
||||
return source
|
||||
}
|
||||
|
||||
pub fn get_radio_sink(&self) -> rodio::Sink {
|
||||
let (_stream, stream_handle) = rodio::OutputStream::try_default().unwrap();
|
||||
let sink: rodio::Sink = rodio::Sink::try_new(&stream_handle).unwrap();
|
||||
return sink
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in new issue