Commit e4c3435d authored by Felix Häcker's avatar Felix Häcker Committed by Jordan Petridis

Player: add basic mpris support

parent fc80b180
......@@ -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)" = "<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 (git+https://github.com/haecker-felix/mpris-player)" = "<none>"
"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"
......
......@@ -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",
......
......@@ -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"]
......
......@@ -74,6 +74,7 @@ extern crate regex;
extern crate reqwest;
extern crate serde_json;
extern crate url;
extern crate mpris_player;
use log::Level;
......
......@@ -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<MprisPlayer>,
}
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<MprisPlayer>,
controls: PlayerControls,
timer: PlayerTimes,
info: PlayerInfo,
......@@ -176,6 +191,8 @@ 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());
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)));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment