Player: implement mpris play/pause callbacks
This commit is contained in:
committed by
Jordan Petridis
parent
e4c3435d34
commit
d066e8939d
@@ -29,7 +29,7 @@ serde_json = "1.0.31"
|
||||
# html2text = "0.1.8"
|
||||
html2text = { git = "https://github.com/alatiera/rust-html2text" }
|
||||
gettext-rs = { git = "https://github.com/danigm/gettext-rs", branch = "no-gettext", features = ["gettext-system"] }
|
||||
mpris-player = { git = "https://github.com/haecker-felix/mpris-player" }
|
||||
mpris-player = { git = "https://gitlab.gnome.org/World/Rust/mpris-player.git" }
|
||||
|
||||
[dependencies.gtk]
|
||||
features = ["v3_22"]
|
||||
|
||||
@@ -28,6 +28,7 @@ use i18n::i18n;
|
||||
use std::sync::Arc;
|
||||
use mpris_player::MprisPlayer;
|
||||
use mpris_player::Metadata;
|
||||
use mpris_player::OrgMprisMediaPlayer2Player;
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
enum SeekDirection {
|
||||
@@ -69,6 +70,7 @@ impl PlayerInfo {
|
||||
metadata.art_url = Some(value.to_string());
|
||||
});
|
||||
self.mpris.set_metadata(metadata);
|
||||
self.mpris.set_can_play(true);
|
||||
}
|
||||
|
||||
fn set_episode_title(&self, episode: &EpisodeWidgetModel) {
|
||||
@@ -192,6 +194,7 @@ impl Default for PlayerWidget {
|
||||
);
|
||||
|
||||
let mpris = MprisPlayer::new("Podcasts".to_string(), "GNOME Podcasts".to_string(), "org.gnome.Podcasts.desktop".to_string());
|
||||
mpris.set_can_play(false);
|
||||
|
||||
let mut config = player.get_config();
|
||||
config.set_user_agent(USER_AGENT);
|
||||
@@ -281,6 +284,7 @@ impl PlayerWidget {
|
||||
fn init(s: &Rc<Self>, sender: &Sender<Action>) {
|
||||
Self::connect_control_buttons(s);
|
||||
Self::connect_rate_buttons(s);
|
||||
Self::connect_mpris_buttons(s);
|
||||
Self::connect_gst_signals(s, sender);
|
||||
}
|
||||
|
||||
@@ -309,6 +313,18 @@ impl PlayerWidget {
|
||||
}));
|
||||
}
|
||||
|
||||
fn connect_mpris_buttons(s: &Rc<Self>) {
|
||||
let weak = Rc::downgrade(s);
|
||||
let mpris = s.mpris.clone();
|
||||
s.mpris.connect_play_pause(clone!(weak => move || {
|
||||
match mpris.get_playback_status().unwrap().as_ref() {
|
||||
"Paused" => weak.upgrade().map(|p| p.play()),
|
||||
"Stopped" => weak.upgrade().map(|p| p.play()),
|
||||
_ => weak.upgrade().map(|p| p.pause()),
|
||||
};
|
||||
}));
|
||||
}
|
||||
|
||||
#[cfg_attr(rustfmt, rustfmt_skip)]
|
||||
fn connect_gst_signals(s: &Rc<Self>, sender: &Sender<Action>) {
|
||||
// Log gst warnings.
|
||||
|
||||
Reference in New Issue
Block a user