Compare commits
No commits in common. "7f20e422d745b64455fb112fc3290525c48e3d29" and "8dc40ac3fb41209e98fc3d4e9eef7dea522858d4" have entirely different histories.
7f20e422d7
...
8dc40ac3fb
8 changed files with 67 additions and 290 deletions
64
Cargo.lock
generated
64
Cargo.lock
generated
|
@ -38,21 +38,6 @@ dependencies = [
|
|||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "android-tzdata"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0"
|
||||
|
||||
[[package]]
|
||||
name = "android_system_properties"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "async-broadcast"
|
||||
version = "0.7.1"
|
||||
|
@ -219,7 +204,6 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"async-channel",
|
||||
"bindgen",
|
||||
"chrono",
|
||||
"gettext-rs",
|
||||
"glib-build-tools",
|
||||
"gtk4",
|
||||
|
@ -413,21 +397,6 @@ version = "0.2.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
|
||||
|
||||
[[package]]
|
||||
name = "chrono"
|
||||
version = "0.4.38"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401"
|
||||
dependencies = [
|
||||
"android-tzdata",
|
||||
"iana-time-zone",
|
||||
"js-sys",
|
||||
"num-traits",
|
||||
"serde",
|
||||
"wasm-bindgen",
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cipher"
|
||||
version = "0.4.4"
|
||||
|
@ -1211,29 +1180,6 @@ dependencies = [
|
|||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "iana-time-zone"
|
||||
version = "0.1.61"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220"
|
||||
dependencies = [
|
||||
"android_system_properties",
|
||||
"core-foundation-sys",
|
||||
"iana-time-zone-haiku",
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
"windows-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "iana-time-zone-haiku"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
|
||||
dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "idna"
|
||||
version = "0.5.0"
|
||||
|
@ -2631,15 +2577,6 @@ version = "0.4.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
||||
[[package]]
|
||||
name = "windows-core"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9"
|
||||
dependencies = [
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-registry"
|
||||
version = "0.2.0"
|
||||
|
@ -2952,7 +2889,6 @@ version = "5.0.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c690a1da8858fd4377b8cc3134a753b0bea1d8ebd78ad6e5897fab821c5e184e"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"endi",
|
||||
"enumflags2",
|
||||
"serde",
|
||||
|
|
|
@ -6,7 +6,6 @@ edition = "2021"
|
|||
[dependencies]
|
||||
adw = { version = "0.7.0", package = "libadwaita", features = ["v1_6"] }
|
||||
async-channel = "2.3.1"
|
||||
chrono = { version = "0.4.38", features = ["serde"] }
|
||||
gettext-rs = { version = "0.7.2", features = ["gettext-system"] }
|
||||
gtk = { version = "0.9.2", package = "gtk4", features = ["v4_16"] }
|
||||
oo7 = "0.3.3"
|
||||
|
@ -15,7 +14,7 @@ reqwest = { version = "0.12.9", features = ["json"] }
|
|||
serde = { version = "1.0.214", features = ["derive"] }
|
||||
tokio = { version = "1", features = ["rt-multi-thread"] }
|
||||
url = "2.5.2"
|
||||
zbus = { version = "5.0.1", features = ["chrono"] }
|
||||
zbus = "5.0.1"
|
||||
|
||||
[build-dependencies]
|
||||
bindgen = "0.70.1"
|
||||
|
|
|
@ -8,88 +8,30 @@ const MICROSECONDS: f64 = 1e6; // in a second
|
|||
|
||||
#[derive(Default)]
|
||||
struct MetadataMap {
|
||||
// mpris
|
||||
track_id: Option<OwnedObjectPath>,
|
||||
length: Option<i64>,
|
||||
//art_url: Option<url::Url>,
|
||||
// xesam
|
||||
album: Option<String>,
|
||||
//album_artist: Option<Vec<String>>,
|
||||
artist: Option<Vec<String>>,
|
||||
//as_text: Option<String>,
|
||||
//audio_bpm: Option<i32>,
|
||||
//auto_rating: Option<f32>,
|
||||
//comment: Option<Vec<String>>,
|
||||
//composer: Option<Vec<String>>,
|
||||
content_created: Option<chrono::NaiveDateTime>,
|
||||
//disc_number: Option<i32>,
|
||||
//first_used: Option<chrono::DateTime>,
|
||||
genre: Option<Vec<String>>,
|
||||
//last_used: Option<chrono::DateTime>,
|
||||
//lyricist: Option<Vec<String>>,
|
||||
title: Option<String>,
|
||||
track_number: Option<i32>,
|
||||
//url: Option<String>,
|
||||
//use_count: Option<String>,
|
||||
user_rating: Option<f32>,
|
||||
pub track_id: Option<OwnedObjectPath>,
|
||||
// rest: TODO
|
||||
}
|
||||
|
||||
impl MetadataMap {
|
||||
fn from_playbin_song(song: Option<&crate::playbin::Song>) -> Self {
|
||||
song.map(|song| MetadataMap {
|
||||
// use a unique growing counter to identify tracks
|
||||
// FIXME: see if there's a better way to do this lol
|
||||
track_id: Some({
|
||||
format!("/eu/callcc/audrey/Track/{}", song.counter())
|
||||
let song_object_intptr =
|
||||
glib::translate::ToGlibPtr::<*const _>::to_glib_none(song).0 as usize;
|
||||
format!("/eu/callcc/audrey/TrackId/{song_object_intptr:x}")
|
||||
.try_into()
|
||||
.unwrap()
|
||||
}),
|
||||
length: Some(song.duration() * MICROSECONDS as i64),
|
||||
album: Some(song.album().into()),
|
||||
artist: Some(vec![song.artist().into()]),
|
||||
//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()),
|
||||
//track_number: song.track().map(|u| u as i32),
|
||||
//user_rating: Some(if song.starred().is_none() { 0.0 } else { 1.0 }),
|
||||
..Default::default()
|
||||
})
|
||||
.unwrap_or_else(Default::default)
|
||||
}
|
||||
|
||||
fn as_hash_map(&self) -> HashMap<&'static str, Value> {
|
||||
let mut map = HashMap::new();
|
||||
|
||||
if let Some(track_id) = &self.track_id {
|
||||
map.insert("mpris:trackid", Value::new(track_id.as_ref()));
|
||||
}
|
||||
if let Some(length) = &self.length {
|
||||
map.insert("mpris:length", Value::new(length));
|
||||
}
|
||||
if let Some(album) = &self.album {
|
||||
map.insert("xesam:album", Value::new(album));
|
||||
}
|
||||
if let Some(artist) = &self.artist {
|
||||
map.insert("xesam:artist", Value::new(artist));
|
||||
}
|
||||
if let Some(content_created) = &self.content_created {
|
||||
map.insert(
|
||||
"xesam:contentCreated",
|
||||
Value::new(content_created.format("%+").to_string()),
|
||||
);
|
||||
}
|
||||
if let Some(genre) = &self.genre {
|
||||
map.insert("xesam:genre", Value::new(genre));
|
||||
}
|
||||
if let Some(track_number) = self.track_number {
|
||||
map.insert("xesam:trackNumber", Value::new(track_number));
|
||||
}
|
||||
if let Some(title) = &self.title {
|
||||
map.insert("xesam:title", Value::new(title));
|
||||
}
|
||||
if let Some(user_rating) = self.user_rating {
|
||||
map.insert("xesam:userRating", Value::new(user_rating));
|
||||
}
|
||||
|
||||
map
|
||||
}
|
||||
}
|
||||
|
@ -97,6 +39,7 @@ impl MetadataMap {
|
|||
pub struct Player {
|
||||
playbin: SendWeakRef<crate::Playbin>,
|
||||
metadata: MetadataMap,
|
||||
volume: f64,
|
||||
}
|
||||
|
||||
impl Player {
|
||||
|
@ -109,6 +52,7 @@ impl Player {
|
|||
let player = Self {
|
||||
playbin: playbin.downgrade().into(),
|
||||
metadata: MetadataMap::from_playbin_song(None),
|
||||
volume: (playbin.volume() as f64) / 100.0,
|
||||
};
|
||||
|
||||
object_server.at("/org/mpris/MediaPlayer2", player).await?;
|
||||
|
@ -139,79 +83,18 @@ impl Player {
|
|||
),
|
||||
);
|
||||
|
||||
playbin.connect_closure(
|
||||
"seeked",
|
||||
false,
|
||||
glib::closure_local!(
|
||||
#[strong]
|
||||
player_ref,
|
||||
move |_playbin: &crate::Playbin, position: f64| {
|
||||
let player_ref = player_ref.clone();
|
||||
glib::spawn_future_local(async move {
|
||||
player_ref
|
||||
.seeked((position * MICROSECONDS) as i64)
|
||||
.await
|
||||
.unwrap();
|
||||
});
|
||||
}
|
||||
),
|
||||
);
|
||||
|
||||
playbin.connect_notify_local(
|
||||
Some("play-queue-length"),
|
||||
glib::clone!(
|
||||
#[strong]
|
||||
player_ref,
|
||||
move |_playbin: &crate::Playbin, _| {
|
||||
let player_ref = player_ref.clone();
|
||||
glib::spawn_future_local(async move {
|
||||
let player = player_ref.get_mut().await;
|
||||
// properties that depend on the play queue length
|
||||
player
|
||||
.can_go_next_changed(player_ref.signal_emitter())
|
||||
.await
|
||||
.unwrap();
|
||||
player
|
||||
.can_go_previous_changed(player_ref.signal_emitter())
|
||||
.await
|
||||
.unwrap();
|
||||
player
|
||||
.can_play_changed(player_ref.signal_emitter())
|
||||
.await
|
||||
.unwrap();
|
||||
});
|
||||
}
|
||||
),
|
||||
);
|
||||
|
||||
playbin.connect_notify_local(
|
||||
Some("state"),
|
||||
glib::clone!(
|
||||
#[strong]
|
||||
player_ref,
|
||||
move |_playbin: &crate::Playbin, _| {
|
||||
let player_ref = player_ref.clone();
|
||||
glib::spawn_future_local(async move {
|
||||
let player = player_ref.get_mut().await;
|
||||
// properties that depend on the playbin state
|
||||
player
|
||||
.playback_status_changed(player_ref.signal_emitter())
|
||||
.await
|
||||
.unwrap();
|
||||
});
|
||||
}
|
||||
),
|
||||
);
|
||||
|
||||
playbin.connect_notify_local(
|
||||
Some("volume"),
|
||||
glib::clone!(
|
||||
#[strong]
|
||||
player_ref,
|
||||
move |_playbin: &crate::Playbin, _| {
|
||||
move |playbin: &crate::Playbin, _| {
|
||||
let playbin_volume = playbin.volume();
|
||||
|
||||
let player_ref = player_ref.clone();
|
||||
glib::spawn_future_local(async move {
|
||||
let player = player_ref.get_mut().await;
|
||||
let mut player = player_ref.get_mut().await;
|
||||
player.volume = (playbin_volume as f64) / 100.0;
|
||||
player
|
||||
.volume_changed(player_ref.signal_emitter())
|
||||
.await
|
||||
|
@ -236,43 +119,32 @@ impl Player {
|
|||
let playbin = self.playbin.upgrade().unwrap();
|
||||
if playbin.play_queue_position() + 1 > playbin.play_queue_length() {
|
||||
// If there is no next track (and endless playback and track repeat are both off), stop playback.
|
||||
// (interpret this as something else than what Stop does)
|
||||
playbin.stop();
|
||||
self.stop();
|
||||
} else {
|
||||
playbin.go_to_next_track();
|
||||
}
|
||||
}
|
||||
|
||||
fn previous(&self) {
|
||||
let playbin = self.playbin.upgrade().unwrap();
|
||||
|
||||
// If CanGoPrevious is false, attempting to call this method should have no effect.
|
||||
if !self.can_go_previous() {
|
||||
return;
|
||||
}
|
||||
|
||||
let playbin = self.playbin.upgrade().unwrap();
|
||||
if playbin.play_queue_position() == 0 {
|
||||
// If there is no previous track (and endless playback and track repeat are both off), stop playback.
|
||||
// (interpret this as something else than what Stop does)
|
||||
playbin.stop();
|
||||
self.stop();
|
||||
} else {
|
||||
playbin.go_to_prev_track();
|
||||
}
|
||||
}
|
||||
|
||||
fn pause(&self) {
|
||||
let playbin = self.playbin.upgrade().unwrap();
|
||||
|
||||
// If CanPause is false, attempting to call this method should have no effect.
|
||||
if !self.can_pause() {
|
||||
return;
|
||||
}
|
||||
|
||||
// If playback is already paused, this has no effect.
|
||||
if playbin.state() != crate::playbin::State::Playing {
|
||||
return;
|
||||
}
|
||||
|
||||
self.playbin.upgrade().unwrap().pause();
|
||||
}
|
||||
|
||||
|
@ -286,31 +158,18 @@ impl Player {
|
|||
}
|
||||
|
||||
fn stop(&self) {
|
||||
let playbin = self.playbin.upgrade().unwrap();
|
||||
|
||||
// If playback is already stopped, this has no effect.
|
||||
if playbin.state() != crate::playbin::State::Playing {
|
||||
return;
|
||||
}
|
||||
|
||||
// Calling Play after this should cause playback to start again from the beginning of the track.
|
||||
playbin.pause();
|
||||
playbin.seek(0.0);
|
||||
// TODO: Calling Play after this should cause playback to start again from the beginning of the track.
|
||||
// (not the play queue!!)
|
||||
self.playbin.upgrade().unwrap().stop();
|
||||
}
|
||||
|
||||
fn play(&self) {
|
||||
let playbin = self.playbin.upgrade().unwrap();
|
||||
|
||||
// If CanPlay is false, attempting to call this method should have no effect.
|
||||
if !self.can_play() {
|
||||
return;
|
||||
}
|
||||
|
||||
// If already playing, this has no effect.
|
||||
if playbin.state() == crate::playbin::State::Playing {
|
||||
return;
|
||||
}
|
||||
|
||||
let playbin = self.playbin.upgrade().unwrap();
|
||||
// If there is no track to play, this has no effect.
|
||||
if playbin.play_queue_length() == 0 {
|
||||
return;
|
||||
|
@ -388,23 +247,18 @@ impl Player {
|
|||
}
|
||||
|
||||
#[zbus(property)]
|
||||
fn set_loop_status(&self, _loop_status: &str) -> zbus::Result<()> {
|
||||
Err(zbus::Error::Unsupported) // TODO
|
||||
fn set_loop_status(&self, _loop_status: &str) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
fn rate(&self) -> f64 {
|
||||
fn playback_rate(&self) -> f64 {
|
||||
1.0
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
fn set_rate(&self, rate: f64) {
|
||||
// A value of 0.0 should not be set by the client. If it is, the media player should act as though Pause was called.
|
||||
if rate == 0.0 {
|
||||
self.pause();
|
||||
}
|
||||
|
||||
// just ignore anything else
|
||||
fn set_playback_rate(&self, _playback_rate: f64) -> zbus::Result<()> {
|
||||
Err(zbus::Error::Unsupported)
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
|
@ -424,15 +278,11 @@ impl Player {
|
|||
|
||||
#[zbus(property)]
|
||||
fn volume(&self) -> f64 {
|
||||
self.playbin.upgrade().unwrap().volume() as f64 / 100.0
|
||||
1.0 // TODO
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
fn set_volume(&mut self, mut volume: f64) {
|
||||
// When setting, if a negative value is passed, the volume should be set to 0.0.
|
||||
if volume < 0.0 {
|
||||
volume = 0.0;
|
||||
}
|
||||
fn set_volume(&mut self, volume: f64) {
|
||||
let playbin = self.playbin.upgrade().unwrap();
|
||||
// FIXME: check if this is set by the notify callback: self.volume = volume;
|
||||
playbin.set_volume((volume * 100.0) as i32);
|
||||
|
@ -455,32 +305,27 @@ impl Player {
|
|||
|
||||
#[zbus(property)]
|
||||
fn can_go_next(&self) -> bool {
|
||||
// same as can_play
|
||||
self.playbin.upgrade().unwrap().play_queue_length() > 0
|
||||
self.playbin.upgrade().unwrap().state() != crate::playbin::State::Stopped
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
fn can_go_previous(&self) -> bool {
|
||||
// same as can_play
|
||||
self.playbin.upgrade().unwrap().play_queue_length() > 0
|
||||
self.playbin.upgrade().unwrap().state() != crate::playbin::State::Stopped
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
fn can_play(&self) -> bool {
|
||||
// it only makes sense to disallow "play" when the play queue is empty
|
||||
self.playbin.upgrade().unwrap().play_queue_length() > 0
|
||||
self.playbin.upgrade().unwrap().state() != crate::playbin::State::Stopped
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
fn can_pause(&self) -> bool {
|
||||
// we don't play anything that can't be paused
|
||||
true
|
||||
self.playbin.upgrade().unwrap().state() != crate::playbin::State::Stopped
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
fn can_seek(&self) -> bool {
|
||||
// we don't play anything that can't be seeked
|
||||
true
|
||||
self.playbin.upgrade().unwrap().state() != crate::playbin::State::Stopped
|
||||
}
|
||||
|
||||
#[zbus(property(emits_changed_signal = "const"))]
|
||||
|
|
|
@ -10,9 +10,6 @@ private struct Audrey.CommandCallback {
|
|||
}
|
||||
|
||||
public class Audrey.PlaybinSong : Object {
|
||||
private static int64 next_counter = 0;
|
||||
public int64 counter { get; private set; }
|
||||
|
||||
private Subsonic.Song inner;
|
||||
public string id { get { return inner.id; } }
|
||||
public string title { get { return inner.title; } }
|
||||
|
@ -30,9 +27,6 @@ public class Audrey.PlaybinSong : Object {
|
|||
public PlaybinSong (Subsonic.Client api, Subsonic.Song song) {
|
||||
this.api = api;
|
||||
this.inner = song;
|
||||
|
||||
this.counter = next_counter;
|
||||
next_counter += 1;
|
||||
}
|
||||
|
||||
private Subsonic.Client api;
|
||||
|
|
|
@ -13,9 +13,6 @@ pub mod ffi {
|
|||
|
||||
extern "C" {
|
||||
pub fn audrey_playbin_song_get_type() -> glib::ffi::GType;
|
||||
pub fn audrey_playbin_song_get_counter(self_: *mut AudreyPlaybinSong) -> i64;
|
||||
pub fn audrey_playbin_song_get_id(self_: *mut AudreyPlaybinSong)
|
||||
-> *const std::ffi::c_char;
|
||||
pub fn audrey_playbin_song_get_title(
|
||||
self_: *mut AudreyPlaybinSong,
|
||||
) -> *const std::ffi::c_char;
|
||||
|
@ -25,7 +22,6 @@ pub mod ffi {
|
|||
pub fn audrey_playbin_song_get_album(
|
||||
self_: *mut AudreyPlaybinSong,
|
||||
) -> *const std::ffi::c_char;
|
||||
pub fn audrey_playbin_song_get_duration(self_: *mut AudreyPlaybinSong) -> i64;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,14 +38,6 @@ glib::wrapper! {
|
|||
}
|
||||
|
||||
impl Song {
|
||||
pub fn counter(&self) -> i64 {
|
||||
unsafe { ffi::audrey_playbin_song_get_counter(self.to_glib_none().0) }
|
||||
}
|
||||
|
||||
pub fn id(&self) -> GString {
|
||||
unsafe { from_glib_none(ffi::audrey_playbin_song_get_id(self.to_glib_none().0)) }
|
||||
}
|
||||
|
||||
pub fn title(&self) -> GString {
|
||||
unsafe { from_glib_none(ffi::audrey_playbin_song_get_title(self.to_glib_none().0)) }
|
||||
}
|
||||
|
@ -61,8 +49,4 @@ impl Song {
|
|||
pub fn album(&self) -> GString {
|
||||
unsafe { from_glib_none(ffi::audrey_playbin_song_get_album(self.to_glib_none().0)) }
|
||||
}
|
||||
|
||||
pub fn duration(&self) -> i64 {
|
||||
unsafe { ffi::audrey_playbin_song_get_duration(self.to_glib_none().0) }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,8 +44,7 @@ pub struct Child {
|
|||
pub artist: String,
|
||||
pub track: Option<u32>,
|
||||
pub year: Option<u32>,
|
||||
pub starred: Option<chrono::DateTime<chrono::offset::Utc>>, // TODO: check which is best
|
||||
// applicable
|
||||
pub starred: Option<()>,
|
||||
pub duration: u64,
|
||||
pub play_count: Option<u32>,
|
||||
pub genre: Option<String>,
|
||||
|
|
|
@ -2,7 +2,7 @@ mod imp {
|
|||
use adw::prelude::*;
|
||||
use adw::subclass::prelude::*;
|
||||
use glib::subclass::InitializingObject;
|
||||
use glib::{gformat, GString, WeakRef};
|
||||
use glib::{gformat, GString};
|
||||
use gtk::{gdk, glib};
|
||||
use std::cell::{Cell, RefCell};
|
||||
|
||||
|
@ -15,12 +15,12 @@ mod imp {
|
|||
#[property(get, set)]
|
||||
playing_cover_art: RefCell<Option<gdk::Paintable>>,
|
||||
#[property(get, set)]
|
||||
playbin: WeakRef<crate::Playbin>,
|
||||
playbin: RefCell<Option<crate::Playbin>>, // TODO: weak
|
||||
#[property(get, set, default = true)]
|
||||
show_cover_art: Cell<bool>,
|
||||
|
||||
#[property(get, set)]
|
||||
volume: Cell<i32>,
|
||||
#[property(type = i32, get = Self::volume, set = Self::set_volume)]
|
||||
_volume: (),
|
||||
}
|
||||
|
||||
#[glib::object_subclass]
|
||||
|
@ -102,7 +102,8 @@ mod imp {
|
|||
value: f64,
|
||||
range: >k::Range,
|
||||
) -> bool {
|
||||
let playbin = self.playbin.upgrade().unwrap();
|
||||
let playbin = self.playbin.borrow();
|
||||
let playbin = playbin.as_ref().unwrap();
|
||||
if range.adjustment().lower() < range.adjustment().upper() {
|
||||
playbin.seek(value);
|
||||
}
|
||||
|
@ -111,19 +112,22 @@ mod imp {
|
|||
|
||||
#[template_callback]
|
||||
fn on_skip_forward_clicked(&self) {
|
||||
let playbin = self.playbin.upgrade().unwrap();
|
||||
let playbin = self.playbin.borrow();
|
||||
let playbin = playbin.as_ref().unwrap();
|
||||
playbin.go_to_next_track();
|
||||
}
|
||||
|
||||
#[template_callback]
|
||||
fn on_skip_backward_clicked(&self) {
|
||||
let playbin = self.playbin.upgrade().unwrap();
|
||||
let playbin = self.playbin.borrow();
|
||||
let playbin = playbin.as_ref().unwrap();
|
||||
playbin.go_to_prev_track();
|
||||
}
|
||||
|
||||
#[template_callback]
|
||||
fn seek_backward(&self) {
|
||||
let playbin = self.playbin.upgrade().unwrap();
|
||||
let playbin = self.playbin.borrow();
|
||||
let playbin = playbin.as_ref().unwrap();
|
||||
// 10 seconds
|
||||
let mut new_position = playbin.position() - 10.0;
|
||||
if new_position < 0.0 {
|
||||
|
@ -134,7 +138,8 @@ mod imp {
|
|||
|
||||
#[template_callback]
|
||||
fn seek_forward(&self) {
|
||||
let playbin = self.playbin.upgrade().unwrap();
|
||||
let playbin = self.playbin.borrow();
|
||||
let playbin = playbin.as_ref().unwrap();
|
||||
// 10 seconds
|
||||
let mut new_position = playbin.position() + 10.0;
|
||||
if new_position > playbin.duration() {
|
||||
|
@ -145,7 +150,8 @@ mod imp {
|
|||
|
||||
#[template_callback]
|
||||
fn on_play_pause_clicked(&self, _button: >k::Button) {
|
||||
let playbin = self.playbin.upgrade().unwrap();
|
||||
let playbin = self.playbin.borrow();
|
||||
let playbin = playbin.as_ref().unwrap();
|
||||
|
||||
if playbin.state() == crate::playbin::State::Playing {
|
||||
playbin.pause();
|
||||
|
@ -156,9 +162,25 @@ mod imp {
|
|||
|
||||
#[template_callback]
|
||||
fn on_mute_toggle(&self) {
|
||||
let playbin = self.playbin.upgrade().unwrap();
|
||||
let playbin = self.playbin.borrow();
|
||||
let playbin = playbin.as_ref().unwrap();
|
||||
playbin.set_mute(!playbin.mute());
|
||||
}
|
||||
|
||||
fn volume(&self) -> i32 {
|
||||
let playbin = self.playbin.borrow();
|
||||
|
||||
match playbin.as_ref() {
|
||||
None => 100,
|
||||
Some(playbin) => playbin.volume(),
|
||||
}
|
||||
}
|
||||
|
||||
fn set_volume(&self, value: i32) {
|
||||
let playbin = self.playbin.borrow();
|
||||
let playbin = playbin.as_ref().unwrap();
|
||||
playbin.set_volume(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,8 +27,6 @@ public class Audrey.Ui.Window : Adw.ApplicationWindow {
|
|||
|
||||
public Window (Gtk.Application app) {
|
||||
Object (application: app);
|
||||
|
||||
this.playbin.bind_property("volume", this.playbar, "volume", BindingFlags.BIDIRECTIONAL | BindingFlags.SYNC_CREATE);
|
||||
}
|
||||
|
||||
private void now_playing (PlaybinSong song) {
|
||||
|
|
Loading…
Reference in a new issue