Merge branch 'mpris' into 'master'

Implement MPRIS, Close #68

See merge request World/podcasts!74
This commit is contained in:
Jordan Petridis 2018-10-04 03:26:03 +00:00
commit 7856f0d602
5 changed files with 102 additions and 9 deletions

45
Cargo.lock generated
View File

@ -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"
@ -423,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)",
@ -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 = "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)",
"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 (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",
@ -1617,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)",
@ -1770,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)",
@ -1904,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]]
@ -2033,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)",
@ -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"
@ -2493,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"
@ -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)" = "<none>"
"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 (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"
@ -2655,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"

View File

@ -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",

View File

@ -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 = "0.1.0"
[dependencies.gtk]
features = ["v3_22"]

View File

@ -74,6 +74,7 @@ extern crate regex;
extern crate reqwest;
extern crate serde_json;
extern crate url;
extern crate mpris_player;
use log::Level;
@ -170,7 +171,6 @@ fn test_stuff() -> Result<(), failure::Error> {
appnotif::InAppNotification::default();
show_menu::ShowMenu::default();
player::PlayerWidget::default();
Ok(())
}

View File

@ -25,6 +25,9 @@ use std::rc::Rc;
use i18n::i18n;
use std::sync::Arc;
use mpris_player::{PlaybackStatus, MprisPlayer, Metadata, OrgMprisMediaPlayer2Player};
#[derive(Debug, Clone, Copy)]
enum SeekDirection {
Backwards,
@ -47,6 +50,7 @@ struct PlayerInfo {
show: gtk::Label,
episode: gtk::Label,
cover: gtk::Image,
mpris: Arc<MprisPlayer>,
}
impl PlayerInfo {
@ -55,6 +59,16 @@ 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());
// 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);
self.mpris.set_metadata(metadata);
self.mpris.set_can_play(true);
}
fn set_episode_title(&self, episode: &EpisodeWidgetModel) {
@ -176,6 +190,15 @@ impl Default for PlayerWidget {
Some(&dispatcher.upcast::<gst_player::PlayerSignalDispatcher>()),
);
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);
config.set_position_update_interval(250);
@ -220,6 +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,
container: labels,
show,
episode,
@ -262,6 +286,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);
}
@ -290,6 +315,38 @@ impl PlayerWidget {
}));
}
fn connect_mpris_buttons(s: &Rc<Self>) {
let weak = Rc::downgrade(s);
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.info.mpris.connect_next(clone!(weak => move || {
weak.upgrade().map(|p| p.fast_forward());
}));
s.info.mpris.connect_previous(clone!(weak => move || {
weak.upgrade().map(|p| p.rewind());
}));
//s.info.mpris.connect_raise(clone!(weak => move || {
// TODO: Do something here
//}));
}
#[cfg_attr(rustfmt, rustfmt_skip)]
fn connect_gst_signals(s: &Rc<Self>, sender: &Sender<Action>) {
// Log gst warnings.
@ -410,6 +467,7 @@ impl PlayerExt for PlayerWidget {
self.controls.play.hide();
self.player.play();
self.info.mpris.set_playback_status(PlaybackStatus::Playing);
}
fn pause(&self) {
@ -417,6 +475,7 @@ impl PlayerExt for PlayerWidget {
self.controls.play.show();
self.player.pause();
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() {
@ -432,6 +491,7 @@ impl PlayerExt for PlayerWidget {
self.controls.play.show();
self.player.stop();
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)));