Player: implement mpris play/pause callbacks
This commit is contained in:
parent
e4c3435d34
commit
d066e8939d
20
Cargo.lock
generated
20
Cargo.lock
generated
@ -432,7 +432,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "encoding_rs"
|
name = "encoding_rs"
|
||||||
version = "0.8.7"
|
version = "0.8.8"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
"cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
@ -1274,7 +1274,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "mpris-player"
|
name = "mpris-player"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/haecker-felix/mpris-player#bca02c943dd7e98a5bebee46a7c5efb0aab92009"
|
source = "git+https://gitlab.gnome.org/World/Rust/mpris-player.git#15b9ebae9aec31b048ac3ccc062956fa51c9e511"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"dbus 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"dbus 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"glib 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"glib 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
@ -1598,7 +1598,7 @@ dependencies = [
|
|||||||
"libhandy 0.2.0 (git+https://gitlab.gnome.org/jsparber/libhandy-rs)",
|
"libhandy 0.2.0 (git+https://gitlab.gnome.org/jsparber/libhandy-rs)",
|
||||||
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"loggerv 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"loggerv 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"mpris-player 0.1.0 (git+https://github.com/haecker-felix/mpris-player)",
|
"mpris-player 0.1.0 (git+https://gitlab.gnome.org/World/Rust/mpris-player.git)",
|
||||||
"open 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"open 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"podcasts-data 0.1.0",
|
"podcasts-data 0.1.0",
|
||||||
"podcasts-downloader 0.1.0",
|
"podcasts-downloader 0.1.0",
|
||||||
@ -1645,7 +1645,7 @@ name = "quick-xml"
|
|||||||
version = "0.12.4"
|
version = "0.12.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"encoding_rs 0.8.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
"encoding_rs 0.8.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"failure 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"failure 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"memchr 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"memchr 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
@ -1798,7 +1798,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"bytes 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
"bytes 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"encoding_rs 0.8.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
"encoding_rs 0.8.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"futures 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)",
|
"futures 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"http 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
"http 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"hyper 0.12.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
"hyper 0.12.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
@ -1932,7 +1932,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
"proc-macro2 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"syn 0.15.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"syn 0.15.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -2061,7 +2061,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "0.15.6"
|
version = "0.15.7"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
"proc-macro2 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
@ -2522,7 +2522,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
"checksum difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198"
|
"checksum difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198"
|
||||||
"checksum dtoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6d301140eb411af13d3115f9a562c85cc6b541ade9dfa314132244aaee7489dd"
|
"checksum dtoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6d301140eb411af13d3115f9a562c85cc6b541ade9dfa314132244aaee7489dd"
|
||||||
"checksum either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3be565ca5c557d7f59e7cfcf1844f9e3033650c929c6566f511e8005f205c1d0"
|
"checksum either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3be565ca5c557d7f59e7cfcf1844f9e3033650c929c6566f511e8005f205c1d0"
|
||||||
"checksum encoding_rs 0.8.7 (registry+https://github.com/rust-lang/crates.io-index)" = "21a550ec129ca2f8593227888625c7c5331c6ad878e2cee6b7ac25e1c7d05746"
|
"checksum encoding_rs 0.8.8 (registry+https://github.com/rust-lang/crates.io-index)" = "cc9945e460ad969220c1061b9574fb02ed097c6f0704ce2f3e336cb443c40c73"
|
||||||
"checksum error-chain 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d9435d864e017c3c6afeac1654189b06cdb491cf2ff73dbf0d73b0f292f42ff8"
|
"checksum error-chain 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d9435d864e017c3c6afeac1654189b06cdb491cf2ff73dbf0d73b0f292f42ff8"
|
||||||
"checksum error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "07e791d3be96241c77c43846b665ef1384606da2cd2a48730abe606a12906e02"
|
"checksum error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "07e791d3be96241c77c43846b665ef1384606da2cd2a48730abe606a12906e02"
|
||||||
"checksum failure 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7efb22686e4a466b1ec1a15c2898f91fa9cb340452496dca654032de20ff95b9"
|
"checksum failure 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7efb22686e4a466b1ec1a15c2898f91fa9cb340452496dca654032de20ff95b9"
|
||||||
@ -2605,7 +2605,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
"checksum mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)" = "71646331f2619b1026cc302f87a2b8b648d5c6dd6937846a16cc8ce0f347f432"
|
"checksum mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)" = "71646331f2619b1026cc302f87a2b8b648d5c6dd6937846a16cc8ce0f347f432"
|
||||||
"checksum mio-uds 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)" = "966257a94e196b11bb43aca423754d87429960a768de9414f3691d6957abf125"
|
"checksum mio-uds 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)" = "966257a94e196b11bb43aca423754d87429960a768de9414f3691d6957abf125"
|
||||||
"checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919"
|
"checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919"
|
||||||
"checksum mpris-player 0.1.0 (git+https://github.com/haecker-felix/mpris-player)" = "<none>"
|
"checksum mpris-player 0.1.0 (git+https://gitlab.gnome.org/World/Rust/mpris-player.git)" = "<none>"
|
||||||
"checksum muldiv 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "451a9a05d2a32c566c897835e0ea95cf79ed2fdfe957924045a1721a36c9980f"
|
"checksum muldiv 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "451a9a05d2a32c566c897835e0ea95cf79ed2fdfe957924045a1721a36c9980f"
|
||||||
"checksum native-tls 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8b0a7bd714e83db15676d31caf968ad7318e9cc35f93c85a90231c8f22867549"
|
"checksum native-tls 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8b0a7bd714e83db15676d31caf968ad7318e9cc35f93c85a90231c8f22867549"
|
||||||
"checksum net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88"
|
"checksum net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88"
|
||||||
@ -2686,7 +2686,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
"checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad"
|
"checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad"
|
||||||
"checksum syn 0.13.11 (registry+https://github.com/rust-lang/crates.io-index)" = "14f9bf6292f3a61d2c716723fdb789a41bbe104168e6f496dc6497e531ea1b9b"
|
"checksum syn 0.13.11 (registry+https://github.com/rust-lang/crates.io-index)" = "14f9bf6292f3a61d2c716723fdb789a41bbe104168e6f496dc6497e531ea1b9b"
|
||||||
"checksum syn 0.14.9 (registry+https://github.com/rust-lang/crates.io-index)" = "261ae9ecaa397c42b960649561949d69311f08eeaea86a65696e6e46517cf741"
|
"checksum syn 0.14.9 (registry+https://github.com/rust-lang/crates.io-index)" = "261ae9ecaa397c42b960649561949d69311f08eeaea86a65696e6e46517cf741"
|
||||||
"checksum syn 0.15.6 (registry+https://github.com/rust-lang/crates.io-index)" = "854b08a640fc8f54728fb95321e3ec485b365a97fe47609797c671addd1dde69"
|
"checksum syn 0.15.7 (registry+https://github.com/rust-lang/crates.io-index)" = "455a6ec9b368f8c479b0ae5494d13b22dc00990d2f00d68c9dc6a2dc4f17f210"
|
||||||
"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6"
|
"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6"
|
||||||
"checksum synstructure 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "85bb9b7550d063ea184027c9b8c20ac167cd36d3e06b3a40bceb9d746dc1a7b7"
|
"checksum synstructure 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "85bb9b7550d063ea184027c9b8c20ac167cd36d3e06b3a40bceb9d746dc1a7b7"
|
||||||
"checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8"
|
"checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8"
|
||||||
|
|||||||
@ -29,7 +29,7 @@ serde_json = "1.0.31"
|
|||||||
# html2text = "0.1.8"
|
# html2text = "0.1.8"
|
||||||
html2text = { git = "https://github.com/alatiera/rust-html2text" }
|
html2text = { git = "https://github.com/alatiera/rust-html2text" }
|
||||||
gettext-rs = { git = "https://github.com/danigm/gettext-rs", branch = "no-gettext", features = ["gettext-system"] }
|
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]
|
[dependencies.gtk]
|
||||||
features = ["v3_22"]
|
features = ["v3_22"]
|
||||||
|
|||||||
@ -28,6 +28,7 @@ use i18n::i18n;
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use mpris_player::MprisPlayer;
|
use mpris_player::MprisPlayer;
|
||||||
use mpris_player::Metadata;
|
use mpris_player::Metadata;
|
||||||
|
use mpris_player::OrgMprisMediaPlayer2Player;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
enum SeekDirection {
|
enum SeekDirection {
|
||||||
@ -69,6 +70,7 @@ impl PlayerInfo {
|
|||||||
metadata.art_url = Some(value.to_string());
|
metadata.art_url = Some(value.to_string());
|
||||||
});
|
});
|
||||||
self.mpris.set_metadata(metadata);
|
self.mpris.set_metadata(metadata);
|
||||||
|
self.mpris.set_can_play(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_episode_title(&self, episode: &EpisodeWidgetModel) {
|
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());
|
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();
|
let mut config = player.get_config();
|
||||||
config.set_user_agent(USER_AGENT);
|
config.set_user_agent(USER_AGENT);
|
||||||
@ -281,6 +284,7 @@ impl PlayerWidget {
|
|||||||
fn init(s: &Rc<Self>, sender: &Sender<Action>) {
|
fn init(s: &Rc<Self>, sender: &Sender<Action>) {
|
||||||
Self::connect_control_buttons(s);
|
Self::connect_control_buttons(s);
|
||||||
Self::connect_rate_buttons(s);
|
Self::connect_rate_buttons(s);
|
||||||
|
Self::connect_mpris_buttons(s);
|
||||||
Self::connect_gst_signals(s, sender);
|
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)]
|
#[cfg_attr(rustfmt, rustfmt_skip)]
|
||||||
fn connect_gst_signals(s: &Rc<Self>, sender: &Sender<Action>) {
|
fn connect_gst_signals(s: &Rc<Self>, sender: &Sender<Action>) {
|
||||||
// Log gst warnings.
|
// Log gst warnings.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user