Compare commits
No commits in common. "e2902e862deb5a1928b5c29fd351715c7f4b1134" and "9ff36afb150f4f65779fbe429fe776bb0314fd9b" have entirely different histories.
e2902e862d
...
9ff36afb15
5 changed files with 36 additions and 20 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 use playbin::Playbin;
|
pub type Playbin = playbin::Playbin<PlaybinSong>;
|
||||||
|
|
||||||
mod signal;
|
mod signal;
|
||||||
pub use signal::{Signal, SignalEmitter, SignalHandler};
|
pub use signal::{Signal, SignalEmitter, SignalHandler};
|
||||||
|
|
|
@ -1,14 +1,25 @@
|
||||||
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 struct Playbin {
|
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> {
|
||||||
mpv: mpv::Handle,
|
mpv: mpv::Handle,
|
||||||
entries: RefCell<Vec<Song>>,
|
entries: RefCell<Vec<E>>,
|
||||||
|
|
||||||
sender: async_broadcast::Sender<Event>,
|
sender: async_broadcast::Sender<Event>,
|
||||||
|
|
||||||
|
@ -18,7 +29,10 @@ pub struct Playbin {
|
||||||
file_started: SignalEmitter<Self, ()>,
|
file_started: SignalEmitter<Self, ()>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Playbin {
|
impl<E> Playbin<E>
|
||||||
|
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();
|
||||||
|
@ -102,14 +116,14 @@ impl Playbin {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn entries(&self) -> Ref<'_, [Song]> {
|
pub fn entries(&self) -> Ref<'_, [E]> {
|
||||||
Ref::map(self.entries.borrow(), Vec::as_ref)
|
Ref::map(self.entries.borrow(), Vec::as_ref)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn push_entry(&self, entry: Song) {
|
pub fn push_entry(&self, entry: E) {
|
||||||
let mut entries = self.entries.borrow_mut();
|
let mut entries = self.entries.borrow_mut();
|
||||||
self.mpv
|
self.mpv
|
||||||
.command(["loadfile", &entry.stream_url(), "append-play"])
|
.command(["loadfile", entry.url().as_str(), "append-play"])
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let index = entries.len();
|
let index = entries.len();
|
||||||
entries.push(entry);
|
entries.push(entry);
|
||||||
|
@ -120,15 +134,10 @@ impl Playbin {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert_entry(&self, index: usize, entry: Song) {
|
pub fn insert_entry(&self, index: usize, entry: E) {
|
||||||
let mut entries = self.entries.borrow_mut();
|
let mut entries = self.entries.borrow_mut();
|
||||||
self.mpv
|
self.mpv
|
||||||
.command([
|
.command(["loadfile", entry.url().as_str(), "insert-at-play"])
|
||||||
"loadfile",
|
|
||||||
&entry.stream_url(),
|
|
||||||
"insert-at-play",
|
|
||||||
index.to_string(),
|
|
||||||
])
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
entries.insert(index, entry);
|
entries.insert(index, entry);
|
||||||
|
|
||||||
|
@ -237,8 +246,8 @@ impl Playbin {
|
||||||
|
|
||||||
// sanity check
|
// sanity check
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
self.entries()[self.current_entry().unwrap()].stream_url(),
|
self.entries()[self.current_entry().unwrap()].url().as_str(),
|
||||||
self.mpv.get_property::<String>("path").unwrap()
|
&self.mpv.get_property::<String>("path").unwrap()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,7 +268,7 @@ impl Playbin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for Playbin {
|
impl<E> Drop for Playbin<E> {
|
||||||
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,3 +73,9 @@ impl Song {
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl crate::playbin::PlaybinEntry for Song {
|
||||||
|
fn url(&self) -> url::Url {
|
||||||
|
url::Url::parse(&self.stream_url()).unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -163,6 +163,7 @@ 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