2024-11-03 12:41:02 +00:00
|
|
|
use crate::mpv;
|
|
|
|
use event_listener::EventListener;
|
|
|
|
|
|
|
|
pub struct Playbin {
|
|
|
|
mpv: mpv::Handle,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Playbin {
|
|
|
|
fn default() -> Self {
|
|
|
|
let mpv = mpv::Handle::new();
|
|
|
|
mpv.set_property("audio-client-name", "audrey").unwrap();
|
|
|
|
mpv.set_property("user-agent", crate::USER_AGENT).unwrap();
|
|
|
|
mpv.set_property("video", false).unwrap();
|
|
|
|
mpv.set_property("prefetch-playlist", true).unwrap();
|
|
|
|
mpv.set_property("gapless-audio", true).unwrap();
|
|
|
|
|
|
|
|
mpv.command(["loadfile", "https://www.youtube.com/watch?v=19y8YTbvri8"])
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
Self { mpv }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Playbin {
|
|
|
|
pub fn tick(&self) -> EventListener {
|
|
|
|
let listener = self.mpv.wakeup_listener();
|
|
|
|
while let Some(event) = self.mpv.wait_event(0.0) {
|
|
|
|
self.handle_event(event);
|
|
|
|
}
|
|
|
|
listener
|
|
|
|
}
|
|
|
|
|
|
|
|
fn handle_event(&self, event: mpv::Event) {
|
|
|
|
println!("mpv event {:?}", event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Drop for Playbin {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
println!("dropping Playbin2");
|
|
|
|
self.mpv.command(["quit"]).unwrap();
|
|
|
|
}
|
|
|
|
}
|