You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.8 KiB
52 lines
1.8 KiB
|
|
|
|
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
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|