From e4c3435d34946db8ae87b01cdea9ae03f829d51d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20H=C3=A4cker?= Date: Wed, 26 Sep 2018 20:04:13 +0200 Subject: [PATCH 1/9] Player: add basic mpris support --- Cargo.lock | 31 ++++++++++++++++++++++++++++++ org.gnome.PodcastsDevel.json | 3 ++- podcasts-gtk/Cargo.toml | 1 + podcasts-gtk/src/main.rs | 1 + podcasts-gtk/src/widgets/player.rs | 22 +++++++++++++++++++++ 5 files changed, 57 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 32093e9..6928ee2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -326,6 +326,15 @@ dependencies = [ "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "dbus" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", + "libdbus-sys 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "debug_unreachable" version = "0.1.1" @@ -1008,6 +1017,14 @@ name = "libc" version = "0.2.43" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "libdbus-sys" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "libflate" version = "0.1.18" @@ -1254,6 +1271,16 @@ dependencies = [ "ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "mpris-player" +version = "0.1.0" +source = "git+https://github.com/haecker-felix/mpris-player#bca02c943dd7e98a5bebee46a7c5efb0aab92009" +dependencies = [ + "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)", + "gtk 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "muldiv" version = "0.2.0" @@ -1571,6 +1598,7 @@ dependencies = [ "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)", "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)", "open 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "podcasts-data 0.1.0", "podcasts-downloader 0.1.0", @@ -2482,6 +2510,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum darling_core 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "5d844ad185d7f9bfd072914584649741768151c4131f6ae59f282889f7a1e450" "checksum darling_macro 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "280207f9bd6f6fd58acd08ed722fb9a75412ad9b1fd9b6a8fbfc55410aca2c2c" "checksum dbus 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "58ec7b4cac6f79f36af1cd9cfdb9b935fc5a4e899f494ee03a3a6165f7d10b4b" +"checksum dbus 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3e34c238dfb3f5881d46ad301403cd8f8ecf946e2a4e89bdd1166728b68b5008" "checksum debug_unreachable 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9a032eac705ca39214d169f83e3d3da290af06d8d1d344d1baad2fd002dca4b3" "checksum derive_builder 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c998e6ab02a828dd9735c18f154e14100e674ed08cb4e1938f0e4177543f439" "checksum derive_builder 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "583a8f76cd41ae6303aca0db4539b90b4fcb289f75467d0c3905781dc670621b" @@ -2550,6 +2579,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca488b89a5657b0a2ecd45b95609b3e848cf1755da332a0da46e2b2b1cb371a7" "checksum lazycell 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ddba4c30a78328befecec92fc94970e53b3ae385827d28620f0f5bb2493081e0" "checksum libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)" = "76e3a3ef172f1a0b9a9ff0dd1491ae5e6c948b94479a3021819ba7d860c8645d" +"checksum libdbus-sys 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8720f9274907052cb50313f91201597868da9d625f8dd125f2aca5bddb7e83a1" "checksum libflate 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)" = "21138fc6669f438ed7ae3559d5789a5f0ba32f28c1f0608d1e452b0bb06ee936" "checksum libhandy 0.2.0 (git+https://gitlab.gnome.org/jsparber/libhandy-rs)" = "" "checksum libsqlite3-sys 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d3711dfd91a1081d2458ad2d06ea30a8755256e74038be2ad927d94e1c955ca8" @@ -2575,6 +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-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 mpris-player 0.1.0 (git+https://github.com/haecker-felix/mpris-player)" = "" "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 net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88" diff --git a/org.gnome.PodcastsDevel.json b/org.gnome.PodcastsDevel.json index 88805e8..1acfafb 100644 --- a/org.gnome.PodcastsDevel.json +++ b/org.gnome.PodcastsDevel.json @@ -21,7 +21,8 @@ "--socket=x11", "--socket=wayland", "--socket=pulseaudio", - "--device=dri" + "--device=dri", + "--own-name=org.mpris.MediaPlayer2.Podcasts" ], "build-options" : { "append-path" : "/usr/lib/sdk/rust-stable/bin", diff --git a/podcasts-gtk/Cargo.toml b/podcasts-gtk/Cargo.toml index c953e4e..0df2d37 100644 --- a/podcasts-gtk/Cargo.toml +++ b/podcasts-gtk/Cargo.toml @@ -29,6 +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" } [dependencies.gtk] features = ["v3_22"] diff --git a/podcasts-gtk/src/main.rs b/podcasts-gtk/src/main.rs index 6184fd0..32ce1e0 100644 --- a/podcasts-gtk/src/main.rs +++ b/podcasts-gtk/src/main.rs @@ -74,6 +74,7 @@ extern crate regex; extern crate reqwest; extern crate serde_json; extern crate url; +extern crate mpris_player; use log::Level; diff --git a/podcasts-gtk/src/widgets/player.rs b/podcasts-gtk/src/widgets/player.rs index b2687d1..085ab08 100644 --- a/podcasts-gtk/src/widgets/player.rs +++ b/podcasts-gtk/src/widgets/player.rs @@ -25,6 +25,10 @@ use std::rc::Rc; use i18n::i18n; +use std::sync::Arc; +use mpris_player::MprisPlayer; +use mpris_player::Metadata; + #[derive(Debug, Clone, Copy)] enum SeekDirection { Backwards, @@ -47,6 +51,7 @@ struct PlayerInfo { show: gtk::Label, episode: gtk::Label, cover: gtk::Image, + mpris: Arc, } impl PlayerInfo { @@ -55,6 +60,15 @@ impl PlayerInfo { self.set_cover_image(podcast); self.set_show_title(podcast); self.set_episode_title(episode); + + let mut metadata = Metadata::new(); + metadata.artist = Some(vec![podcast.title().to_string()]); + metadata.title = Some(episode.title().to_string()); + + podcast.image_uri().map(|value|{ + metadata.art_url = Some(value.to_string()); + }); + self.mpris.set_metadata(metadata); } fn set_episode_title(&self, episode: &EpisodeWidgetModel) { @@ -161,6 +175,7 @@ struct PlayerControls { pub(crate) struct PlayerWidget { pub(crate) action_bar: gtk::ActionBar, player: gst_player::Player, + mpris: Arc, controls: PlayerControls, timer: PlayerTimes, info: PlayerInfo, @@ -176,6 +191,8 @@ impl Default for PlayerWidget { Some(&dispatcher.upcast::()), ); + let mpris = MprisPlayer::new("Podcasts".to_string(), "GNOME Podcasts".to_string(), "org.gnome.Podcasts.desktop".to_string()); + let mut config = player.get_config(); config.set_user_agent(USER_AGENT); config.set_position_update_interval(250); @@ -220,6 +237,7 @@ impl Default for PlayerWidget { let episode = builder.get_object("episode_label").unwrap(); let cover = builder.get_object("show_cover").unwrap(); let info = PlayerInfo { + mpris: mpris.clone(), container: labels, show, episode, @@ -243,6 +261,7 @@ impl Default for PlayerWidget { PlayerWidget { player, + mpris, action_bar, controls, timer, @@ -410,6 +429,7 @@ impl PlayerExt for PlayerWidget { self.controls.play.hide(); self.player.play(); + self.mpris.set_playback_status(::mpris_player::PlaybackStatus::Playing); } fn pause(&self) { @@ -417,6 +437,7 @@ impl PlayerExt for PlayerWidget { self.controls.play.show(); self.player.pause(); + self.mpris.set_playback_status(::mpris_player::PlaybackStatus::Paused); // Only rewind on pause if the stream position is passed a certain point. if let Some(sec) = self.player.get_position().seconds() { @@ -432,6 +453,7 @@ impl PlayerExt for PlayerWidget { self.controls.play.show(); self.player.stop(); + self.mpris.set_playback_status(::mpris_player::PlaybackStatus::Paused); // Reset the slider bar to the start self.timer.on_position_updated(Position(ClockTime::from_seconds(0))); From d066e8939de5703a1f7eed4fb245d66bfb108a75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20H=C3=A4cker?= Date: Tue, 2 Oct 2018 21:59:45 +0200 Subject: [PATCH 2/9] Player: implement mpris play/pause callbacks --- Cargo.lock | 20 ++++++++++---------- podcasts-gtk/Cargo.toml | 2 +- podcasts-gtk/src/widgets/player.rs | 16 ++++++++++++++++ 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6928ee2..0a66882 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -432,7 +432,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "encoding_rs" -version = "0.8.7" +version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1274,7 +1274,7 @@ dependencies = [ [[package]] name = "mpris-player" 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 = [ "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)", @@ -1598,7 +1598,7 @@ dependencies = [ "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)", "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)", "podcasts-data 0.1.0", "podcasts-downloader 0.1.0", @@ -1645,7 +1645,7 @@ name = "quick-xml" version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" 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)", "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)", @@ -1798,7 +1798,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "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)", - "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)", "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)", @@ -1932,7 +1932,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "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)", - "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]] @@ -2061,7 +2061,7 @@ dependencies = [ [[package]] name = "syn" -version = "0.15.6" +version = "0.15.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "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 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 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.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" @@ -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-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 mpris-player 0.1.0 (git+https://github.com/haecker-felix/mpris-player)" = "" +"checksum mpris-player 0.1.0 (git+https://gitlab.gnome.org/World/Rust/mpris-player.git)" = "" "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 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.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.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 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" diff --git a/podcasts-gtk/Cargo.toml b/podcasts-gtk/Cargo.toml index 0df2d37..38829ed 100644 --- a/podcasts-gtk/Cargo.toml +++ b/podcasts-gtk/Cargo.toml @@ -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"] diff --git a/podcasts-gtk/src/widgets/player.rs b/podcasts-gtk/src/widgets/player.rs index 085ab08..6650db7 100644 --- a/podcasts-gtk/src/widgets/player.rs +++ b/podcasts-gtk/src/widgets/player.rs @@ -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, sender: &Sender) { 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) { + 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, sender: &Sender) { // Log gst warnings. From 1f18d4291f7014c77e6691f944ebd32e10b7042a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20H=C3=A4cker?= Date: Wed, 3 Oct 2018 11:27:42 +0200 Subject: [PATCH 3/9] Player: implement fast forward / rewind for mpris --- podcasts-gtk/src/widgets/player.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/podcasts-gtk/src/widgets/player.rs b/podcasts-gtk/src/widgets/player.rs index 6650db7..f4399ec 100644 --- a/podcasts-gtk/src/widgets/player.rs +++ b/podcasts-gtk/src/widgets/player.rs @@ -315,6 +315,7 @@ impl PlayerWidget { fn connect_mpris_buttons(s: &Rc) { 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() { @@ -323,6 +324,14 @@ impl PlayerWidget { _ => weak.upgrade().map(|p| p.pause()), }; })); + + s.mpris.connect_next(clone!(weak => move || { + weak.upgrade().map(|p| p.fast_forward()); + })); + + s.mpris.connect_previous(clone!(weak => move || { + weak.upgrade().map(|p| p.rewind()); + })); } #[cfg_attr(rustfmt, rustfmt_skip)] From ede91da6f8c78b0f6c2f971a45cdc534ef12f5e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20H=C3=A4cker?= Date: Wed, 3 Oct 2018 11:51:32 +0200 Subject: [PATCH 4/9] cargo fmt --- podcasts-gtk/src/widgets/player.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/podcasts-gtk/src/widgets/player.rs b/podcasts-gtk/src/widgets/player.rs index f4399ec..ada8698 100644 --- a/podcasts-gtk/src/widgets/player.rs +++ b/podcasts-gtk/src/widgets/player.rs @@ -26,9 +26,7 @@ use std::rc::Rc; use i18n::i18n; use std::sync::Arc; -use mpris_player::MprisPlayer; -use mpris_player::Metadata; -use mpris_player::OrgMprisMediaPlayer2Player; +use mpris_player::{PlaybackStatus, MprisPlayer, Metadata, OrgMprisMediaPlayer2Player}; #[derive(Debug, Clone, Copy)] enum SeekDirection { @@ -66,7 +64,7 @@ impl PlayerInfo { metadata.artist = Some(vec![podcast.title().to_string()]); metadata.title = Some(episode.title().to_string()); - podcast.image_uri().map(|value|{ + podcast.image_uri().map(|value| { metadata.art_url = Some(value.to_string()); }); self.mpris.set_metadata(metadata); @@ -193,8 +191,14 @@ impl Default for PlayerWidget { Some(&dispatcher.upcast::()), ); - 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); + mpris.set_can_seek(false); + mpris.set_can_set_fullscreen(false); let mut config = player.get_config(); config.set_user_agent(USER_AGENT); @@ -332,6 +336,10 @@ impl PlayerWidget { s.mpris.connect_previous(clone!(weak => move || { weak.upgrade().map(|p| p.rewind()); })); + + //s.mpris.connect_raise(clone!(weak => move || { + // TODO: Do something here + //})); } #[cfg_attr(rustfmt, rustfmt_skip)] @@ -454,7 +462,7 @@ impl PlayerExt for PlayerWidget { self.controls.play.hide(); self.player.play(); - self.mpris.set_playback_status(::mpris_player::PlaybackStatus::Playing); + self.mpris.set_playback_status(PlaybackStatus::Playing); } fn pause(&self) { @@ -462,7 +470,7 @@ impl PlayerExt for PlayerWidget { self.controls.play.show(); self.player.pause(); - self.mpris.set_playback_status(::mpris_player::PlaybackStatus::Paused); + self.mpris.set_playback_status(PlaybackStatus::Paused); // Only rewind on pause if the stream position is passed a certain point. if let Some(sec) = self.player.get_position().seconds() { @@ -478,7 +486,7 @@ impl PlayerExt for PlayerWidget { self.controls.play.show(); self.player.stop(); - self.mpris.set_playback_status(::mpris_player::PlaybackStatus::Paused); + self.mpris.set_playback_status(PlaybackStatus::Paused); // Reset the slider bar to the start self.timer.on_position_updated(Position(ClockTime::from_seconds(0))); From fed0edbf16657230ec4823f7329c176e4755a646 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20H=C3=A4cker?= Date: Wed, 3 Oct 2018 12:15:02 +0200 Subject: [PATCH 5/9] Player: use crates.io package of mpris --- Cargo.lock | 6 +++--- podcasts-gtk/Cargo.toml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0a66882..29319a2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1274,7 +1274,7 @@ dependencies = [ [[package]] name = "mpris-player" version = "0.1.0" -source = "git+https://gitlab.gnome.org/World/Rust/mpris-player.git#15b9ebae9aec31b048ac3ccc062956fa51c9e511" +source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "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)", @@ -1598,7 +1598,7 @@ dependencies = [ "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)", "loggerv 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "mpris-player 0.1.0 (git+https://gitlab.gnome.org/World/Rust/mpris-player.git)", + "mpris-player 0.1.0 (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-downloader 0.1.0", @@ -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-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 mpris-player 0.1.0 (git+https://gitlab.gnome.org/World/Rust/mpris-player.git)" = "" +"checksum mpris-player 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "efbc8651bf94296cce16f4b69c6e8687304e24a14551018a97044123b2eb5f43" "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 net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88" diff --git a/podcasts-gtk/Cargo.toml b/podcasts-gtk/Cargo.toml index 38829ed..6e88382 100644 --- a/podcasts-gtk/Cargo.toml +++ b/podcasts-gtk/Cargo.toml @@ -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://gitlab.gnome.org/World/Rust/mpris-player.git" } +mpris-player = "0.1.0" [dependencies.gtk] features = ["v3_22"] From 654c0e5e569ed570cea8b32525d4444672b52f8e Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Wed, 3 Oct 2018 14:40:22 +0300 Subject: [PATCH 6/9] Player: Remove Initialization test When constucting Player in the Sandbox, it tries to use X-11 for dbus-autolaunch which is disabled in the flatpak environment. It fails with the following error: D-Bus error: Using X11 for dbus-daemon autolaunch was disabled at compile time, set your DBUS_SESSION_BUS_ADDRESS instead (org.freedesktop.DBus.Error.NotSupported) --- podcasts-gtk/src/main.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/podcasts-gtk/src/main.rs b/podcasts-gtk/src/main.rs index 32ce1e0..6d33831 100644 --- a/podcasts-gtk/src/main.rs +++ b/podcasts-gtk/src/main.rs @@ -171,7 +171,6 @@ fn test_stuff() -> Result<(), failure::Error> { appnotif::InAppNotification::default(); show_menu::ShowMenu::default(); - player::PlayerWidget::default(); Ok(()) } From 986d898217a3846ddb9e65decfcca17f1e731dc1 Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Wed, 3 Oct 2018 15:57:50 +0300 Subject: [PATCH 7/9] Player: Remove an unwrap --- podcasts-gtk/src/widgets/player.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/podcasts-gtk/src/widgets/player.rs b/podcasts-gtk/src/widgets/player.rs index ada8698..b61ae32 100644 --- a/podcasts-gtk/src/widgets/player.rs +++ b/podcasts-gtk/src/widgets/player.rs @@ -320,13 +320,20 @@ impl PlayerWidget { fn connect_mpris_buttons(s: &Rc) { 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()), + let mpris = s.info.mpris.clone(); + s.info.mpris.connect_play_pause(clone!(weak => move || { + let player = match weak.upgrade() { + Some(s) => s, + None => return }; + + if let Ok(status) = mpris.get_playback_status() { + match status.as_ref() { + "Paused" => player.play(), + "Stopped" => player.play(), + _ => player.pause(), + }; + } })); s.mpris.connect_next(clone!(weak => move || { From 23aa8c05ab6bc3e532150fa067cea5a7821cb098 Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Wed, 3 Oct 2018 15:58:12 +0300 Subject: [PATCH 8/9] Player: Do not duplicate the mpris instance --- podcasts-gtk/src/widgets/player.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/podcasts-gtk/src/widgets/player.rs b/podcasts-gtk/src/widgets/player.rs index b61ae32..3173102 100644 --- a/podcasts-gtk/src/widgets/player.rs +++ b/podcasts-gtk/src/widgets/player.rs @@ -175,7 +175,6 @@ struct PlayerControls { pub(crate) struct PlayerWidget { pub(crate) action_bar: gtk::ActionBar, player: gst_player::Player, - mpris: Arc, controls: PlayerControls, timer: PlayerTimes, info: PlayerInfo, @@ -244,7 +243,7 @@ impl Default for PlayerWidget { let episode = builder.get_object("episode_label").unwrap(); let cover = builder.get_object("show_cover").unwrap(); let info = PlayerInfo { - mpris: mpris.clone(), + mpris, container: labels, show, episode, @@ -268,7 +267,6 @@ impl Default for PlayerWidget { PlayerWidget { player, - mpris, action_bar, controls, timer, @@ -336,15 +334,15 @@ impl PlayerWidget { } })); - s.mpris.connect_next(clone!(weak => move || { + s.info.mpris.connect_next(clone!(weak => move || { weak.upgrade().map(|p| p.fast_forward()); })); - s.mpris.connect_previous(clone!(weak => move || { + s.info.mpris.connect_previous(clone!(weak => move || { weak.upgrade().map(|p| p.rewind()); })); - //s.mpris.connect_raise(clone!(weak => move || { + //s.info.mpris.connect_raise(clone!(weak => move || { // TODO: Do something here //})); } @@ -469,7 +467,7 @@ impl PlayerExt for PlayerWidget { self.controls.play.hide(); self.player.play(); - self.mpris.set_playback_status(PlaybackStatus::Playing); + self.info.mpris.set_playback_status(PlaybackStatus::Playing); } fn pause(&self) { @@ -477,7 +475,7 @@ impl PlayerExt for PlayerWidget { self.controls.play.show(); self.player.pause(); - self.mpris.set_playback_status(PlaybackStatus::Paused); + self.info.mpris.set_playback_status(PlaybackStatus::Paused); // Only rewind on pause if the stream position is passed a certain point. if let Some(sec) = self.player.get_position().seconds() { @@ -493,7 +491,7 @@ impl PlayerExt for PlayerWidget { self.controls.play.show(); self.player.stop(); - self.mpris.set_playback_status(PlaybackStatus::Paused); + self.info.mpris.set_playback_status(PlaybackStatus::Paused); // Reset the slider bar to the start self.timer.on_position_updated(Position(ClockTime::from_seconds(0))); From bcc6ab50e2a4561a73b884d7e7a05b0c686aa8de Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Thu, 4 Oct 2018 04:05:05 +0300 Subject: [PATCH 9/9] PlayerInfo: Minor refactor of the mpris cover --- podcasts-gtk/src/widgets/player.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/podcasts-gtk/src/widgets/player.rs b/podcasts-gtk/src/widgets/player.rs index 3173102..e2d994f 100644 --- a/podcasts-gtk/src/widgets/player.rs +++ b/podcasts-gtk/src/widgets/player.rs @@ -63,10 +63,10 @@ impl PlayerInfo { let mut metadata = Metadata::new(); metadata.artist = Some(vec![podcast.title().to_string()]); metadata.title = Some(episode.title().to_string()); + // FIXME: .image_uri() returns an http url, we should instead + // pass it the local path to the downloaded cover image. + metadata.art_url = podcast.image_uri().clone().map(From::from); - podcast.image_uri().map(|value| { - metadata.art_url = Some(value.to_string()); - }); self.mpris.set_metadata(metadata); self.mpris.set_can_play(true); }