Compare commits
2 commits
9ff36afb15
...
e2902e862d
Author | SHA1 | Date | |
---|---|---|---|
e2902e862d | |||
3c4d3fd80e |
5 changed files with 20 additions and 36 deletions
|
@ -17,7 +17,7 @@ pub use playbin_song::Song as PlaybinSong;
|
|||
pub mod subsonic;
|
||||
|
||||
pub mod playbin;
|
||||
pub type Playbin = playbin::Playbin<PlaybinSong>;
|
||||
pub use playbin::Playbin;
|
||||
|
||||
mod signal;
|
||||
pub use signal::{Signal, SignalEmitter, SignalHandler};
|
||||
|
|
|
@ -1,25 +1,14 @@
|
|||
use crate::mpv;
|
||||
use crate::signal::{Signal, SignalEmitter};
|
||||
use crate::Event;
|
||||
use crate::PlaybinSong as Song;
|
||||
use event_listener::EventListener;
|
||||
use std::cell::{Ref, RefCell};
|
||||
use tracing::{event, span, Level};
|
||||
use url::Url;
|
||||
|
||||
pub trait PlaybinEntry {
|
||||
fn url(&self) -> Url;
|
||||
}
|
||||
|
||||
impl PlaybinEntry for Url {
|
||||
fn url(&self) -> Url {
|
||||
self.clone()
|
||||
}
|
||||
}
|
||||
|
||||
// E: generic entry type
|
||||
pub struct Playbin<E> {
|
||||
pub struct Playbin {
|
||||
mpv: mpv::Handle,
|
||||
entries: RefCell<Vec<E>>,
|
||||
entries: RefCell<Vec<Song>>,
|
||||
|
||||
sender: async_broadcast::Sender<Event>,
|
||||
|
||||
|
@ -29,10 +18,7 @@ pub struct Playbin<E> {
|
|||
file_started: SignalEmitter<Self, ()>,
|
||||
}
|
||||
|
||||
impl<E> Playbin<E>
|
||||
where
|
||||
E: PlaybinEntry,
|
||||
{
|
||||
impl Playbin {
|
||||
pub fn new(sender: async_broadcast::Sender<Event>) -> Self {
|
||||
let mpv = mpv::Handle::new();
|
||||
mpv.set_property("audio-client-name", "audrey").unwrap();
|
||||
|
@ -116,14 +102,14 @@ where
|
|||
.unwrap();
|
||||
}
|
||||
|
||||
pub fn entries(&self) -> Ref<'_, [E]> {
|
||||
pub fn entries(&self) -> Ref<'_, [Song]> {
|
||||
Ref::map(self.entries.borrow(), Vec::as_ref)
|
||||
}
|
||||
|
||||
pub fn push_entry(&self, entry: E) {
|
||||
pub fn push_entry(&self, entry: Song) {
|
||||
let mut entries = self.entries.borrow_mut();
|
||||
self.mpv
|
||||
.command(["loadfile", entry.url().as_str(), "append-play"])
|
||||
.command(["loadfile", &entry.stream_url(), "append-play"])
|
||||
.unwrap();
|
||||
let index = entries.len();
|
||||
entries.push(entry);
|
||||
|
@ -134,10 +120,15 @@ where
|
|||
.unwrap();
|
||||
}
|
||||
|
||||
pub fn insert_entry(&self, index: usize, entry: E) {
|
||||
pub fn insert_entry(&self, index: usize, entry: Song) {
|
||||
let mut entries = self.entries.borrow_mut();
|
||||
self.mpv
|
||||
.command(["loadfile", entry.url().as_str(), "insert-at-play"])
|
||||
.command([
|
||||
"loadfile",
|
||||
&entry.stream_url(),
|
||||
"insert-at-play",
|
||||
index.to_string(),
|
||||
])
|
||||
.unwrap();
|
||||
entries.insert(index, entry);
|
||||
|
||||
|
@ -246,8 +237,8 @@ where
|
|||
|
||||
// sanity check
|
||||
assert_eq!(
|
||||
self.entries()[self.current_entry().unwrap()].url().as_str(),
|
||||
&self.mpv.get_property::<String>("path").unwrap()
|
||||
self.entries()[self.current_entry().unwrap()].stream_url(),
|
||||
self.mpv.get_property::<String>("path").unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -268,7 +259,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<E> Drop for Playbin<E> {
|
||||
impl Drop for Playbin {
|
||||
fn drop(&mut self) {
|
||||
event!(Level::DEBUG, "dropping Playbin2");
|
||||
self.mpv.command(["quit"]).unwrap();
|
||||
|
|
|
@ -73,9 +73,3 @@ impl Song {
|
|||
.build()
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::playbin::PlaybinEntry for Song {
|
||||
fn url(&self) -> url::Url {
|
||||
url::Url::parse(&self.stream_url()).unwrap()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -163,7 +163,6 @@ mod imp {
|
|||
}
|
||||
}
|
||||
|
||||
use crate::PlaybinSong;
|
||||
use adw::prelude::*;
|
||||
use glib::Object;
|
||||
use gtk::glib;
|
||||
|
|
|
@ -32,7 +32,7 @@ mod imp {
|
|||
pub(super) playbin: Rc<Playbin>,
|
||||
pub(super) api: RefCell<Option<Rc<crate::subsonic::Client>>>,
|
||||
|
||||
pub(super) sender: async_broadcast::Sender<crate::Event>,
|
||||
pub(super) _sender: async_broadcast::Sender<crate::Event>,
|
||||
pub(super) inactive_receiver: async_broadcast::InactiveReceiver<crate::Event>,
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,7 @@ mod imp {
|
|||
setup: Default::default(),
|
||||
playbin: Rc::new(Playbin::new(sender.clone())),
|
||||
api: Default::default(),
|
||||
sender,
|
||||
_sender: sender,
|
||||
inactive_receiver: receiver.deactivate(),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue