This commit is contained in:
Erica Z 2024-11-03 20:18:12 +01:00
parent fd88c54809
commit 6483f3dd17
8 changed files with 65 additions and 32 deletions

View file

@ -45,11 +45,11 @@ impl MetadataMap {
}),
length: Some(song.duration() * MICROSECONDS as i64),
//art_url: Some(song.cover_art_url()), // FIXME: this would leak credentials
album: Some(song.album().into()),
artist: Some(vec![song.artist().into()]),
album: Some(song.album()),
artist: Some(vec![song.artist()]),
//content_created: song.year().map(|year| chrono::NaiveDate::from_yo_opt(year, 1).unwrap()), // FIXME: replace this unwrap with Some(Err) -> None
//genre: Some(song.genre.iter().collect()),
title: Some(song.title().into()),
title: Some(song.title()),
//track_number: song.track().map(|u| u as i32),
//user_rating: Some(if song.starred().is_none() { 0.0 } else { 1.0 }),
..Default::default()
@ -273,6 +273,46 @@ impl Player {
.await
}
async fn previous(&self) -> zbus::fdo::Result<()> {
self.with_local(move |local| async move { local.previous() })
.await
}
async fn pause(&self) -> zbus::fdo::Result<()> {
self.with_local(move |local| async move { local.pause() })
.await
}
async fn play_pause(&self) -> zbus::fdo::Result<()> {
self.with_local(move |local| async move { local.play_pause() })
.await
}
async fn stop(&self) -> zbus::fdo::Result<()> {
self.with_local(move |local| async move { local.stop() })
.await
}
async fn play(&self) -> zbus::fdo::Result<()> {
self.with_local(move |local| async move { local.play() })
.await
}
async fn seek(&self, offset: i64) -> zbus::fdo::Result<()> {
self.with_local(move |local| async move { local.seek(offset) })
.await
}
async fn set_position(&self, track_id: ObjectPath<'_>, position: i64) -> zbus::fdo::Result<()> {
let track_id = track_id.to_owned();
self.with_local(move |local| async move { local.set_position(track_id, position) })
.await
}
async fn open_uri(&self, _s: String) -> zbus::fdo::Result<()> {
Err(zbus::fdo::Error::NotSupported("OpenUri".into()))
}
#[zbus(property)]
async fn playback_status(&self) -> zbus::fdo::Result<String> {
self.with_local(|local| async move { local.playback_status() })
@ -473,14 +513,14 @@ impl LocalPlayer {
todo!()
}
fn set_position(&self, _track_id: ObjectPath<'_>, _position: i64) -> zbus::fdo::Result<()> {
fn set_position(
&self,
_track_id: ObjectPath<'static>,
_position: i64,
) -> zbus::fdo::Result<()> {
todo!()
}
fn open_uri(&self, _s: &str) -> zbus::fdo::Result<()> {
Err(zbus::fdo::Error::NotSupported("OpenUri".into()))
}
fn playback_status(&self) -> zbus::fdo::Result<String> {
match self.playbin()?.paused() {
//crate::playbin::State::Stopped => Ok("Stopped".into()),
@ -532,10 +572,6 @@ impl LocalPlayer {
// we don't play anything that can't be seeked
true
}
fn can_control(&self) -> bool {
true
}
}
impl Drop for Player {

View file

@ -137,7 +137,7 @@ where
entries.push(entry);
drop(entries);
self.entry_inserted.emit(self, index as usize);
self.entry_inserted.emit(self, index);
}
pub fn insert_entry(&self, index: usize, entry: E) {
@ -145,7 +145,7 @@ where
self.mpv
.command(["loadfile", entry.url().as_str(), "insert-at-play"])
.unwrap();
entries.insert(index as usize, entry);
entries.insert(index, entry);
drop(entries);
self.entry_inserted.emit(self, index);
@ -166,7 +166,7 @@ where
self.mpv
.command(["playlist-remove", &index.to_string()])
.unwrap();
entries.remove(index as usize);
entries.remove(index);
drop(entries);
self.entry_removed.emit(self, index);

View file

@ -102,7 +102,6 @@ impl<E, T> SignalEmitter<E, T> {
handlers.append(self.just_connected.borrow_mut().as_mut());
let mut i = 0;
let mut skip = 0;
// FIXME: does not preserve ordering
while i < handlers.len() {
if handlers[i](emitter, f()) {

View file

@ -4,8 +4,8 @@ pub use song::Song;
mod imp {
use crate::{Playbin, PlaybinSong};
use adw::{gio, glib, prelude::*, subclass::prelude::*};
use glib::{subclass::InitializingObject, WeakRef};
use std::cell::{Cell, RefCell};
use glib::subclass::InitializingObject;
use std::cell::RefCell;
use std::rc::Rc;
#[derive(gtk::CompositeTemplate, glib::Properties, Default)]
@ -134,13 +134,13 @@ impl PlayQueue {
});
playbin
.stopped()
.connect_object(self, |playbin, play_queue, ()| {
.connect_object(self, |_playbin, play_queue, ()| {
play_queue.model().unwrap().remove_all();
true
});
playbin
.entry_removed()
.connect_object(self, |playbin, play_queue, index| {
.connect_object(self, |_playbin, play_queue, index| {
play_queue.model().unwrap().remove(index as u32);
true
});

View file

@ -1,7 +1,7 @@
mod imp {
use crate::signal::SignalHandler;
use crate::{Playbin, PlaybinSong};
use glib::{subclass::InitializingObject, WeakRef};
use glib::subclass::InitializingObject;
use gtk::{gdk, gio, glib, prelude::*, subclass::prelude::*};
use std::cell::{Cell, RefCell};
use std::rc::Rc;
@ -166,7 +166,6 @@ mod imp {
}
use crate::{Playbin, PlaybinSong};
use adw::prelude::*;
use adw::subclass::prelude::*;
use glib::Object;
use gtk::glib;

View file

@ -3,7 +3,6 @@ mod imp {
use adw::prelude::*;
use adw::subclass::prelude::*;
use glib::subclass::InitializingObject;
use glib::{gformat, GString, WeakRef};
use gtk::{gdk, glib};
use std::cell::{Cell, RefCell};
@ -86,8 +85,8 @@ mod imp {
fn on_play_position_seek(
&self,
_scroll_type: gtk::ScrollType,
value: f64,
range: &gtk::Range,
_value: f64,
_range: &gtk::Range,
) -> bool {
/*
let playbin = self.playbin.upgrade().unwrap();

View file

@ -1,10 +1,9 @@
mod imp {
use crate::signal::SignalEmitter;
use adw::{glib, prelude::*, subclass::prelude::*};
use glib::subclass::{InitializingObject, Signal};
use glib::subclass::InitializingObject;
use std::cell::{Cell, RefCell};
use std::rc::Rc;
use std::sync::OnceLock;
#[derive(gtk::CompositeTemplate, glib::Properties, Default)]
#[template(resource = "/eu/callcc/audrey/setup.ui")]

View file

@ -140,7 +140,7 @@ mod imp {
self.setup.present(Some(self.obj().as_ref()));
}
pub(super) fn now_playing(&self, _song: PlaybinSong) {
pub(super) fn now_playing(&self, _song: &PlaybinSong) {
/*
this.song = song;
// api.scrobble.begin (this.song.id); TODO
@ -177,10 +177,9 @@ mod imp {
}
}
use crate::PlaybinSong;
use adw::prelude::*;
use adw::subclass::prelude::*;
use gtk::{gdk, gio, glib};
use gtk::{gio, glib};
use std::rc::Rc;
glib::wrapper! {
@ -274,8 +273,10 @@ impl Window {
.imp()
.playbin2
.file_started()
.connect_object(&window, |_playbin, _window, ()| {
// TODO window.imp().now_playing(song);
.connect_object(&window, |playbin, window, ()| {
window
.imp()
.now_playing(&playbin.entries()[playbin.current_entry().unwrap()]);
true
});