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