Skip to content

Commit 0333b4f

Browse files
committed
Mid-way MPRIS refactor and permissions
Not working yet. Need to debug
1 parent 217d9d2 commit 0333b4f

File tree

13 files changed

+634
-424
lines changed

13 files changed

+634
-424
lines changed

docs/specbook/src/mpris.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Sources:
77

88
- Some desktop environments natively support image data URLs in `mpris:artUrl`,
99
but we have no way to verify this via the specification as it is.
10-
Using HTTP URLs or local file URLs is safer.
10+
Using local file URLs or alternatively HTTP URLs may be safer.
1111

1212
## org.mpris.MediaPlayer2
1313

examples/player.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,25 @@ fn main() {
103103
let (config, permissions) = {
104104
(
105105
souvlaki::platform::mpris::MprisConfig {
106-
display_name: "Souvlaki Player".to_owned(),
106+
identity: "Souvlaki Player".to_owned(),
107107
dbus_name: "souvlaki_player".to_owned(),
108+
desktop_entry: "souvlaki".to_owned(),
109+
},
110+
souvlaki::platform::mpris::MprisPermissions {
111+
can_quit: true,
112+
can_set_fullscreen: false,
113+
can_raise: true,
114+
supported_uri_schemes: vec![],
115+
supported_mime_types: vec![],
116+
can_go_next: true,
117+
can_go_previous: true,
118+
can_play: true,
119+
can_pause: true,
120+
can_seek: true,
121+
can_control: true,
122+
min_rate: 1.0,
123+
max_rate: 1.0,
108124
},
109-
(),
110125
)
111126
};
112127

@@ -295,6 +310,7 @@ fn main() {
295310
eprintln!("Quitting...");
296311
return;
297312
}
313+
SetFullscreen(_) => todo!(),
298314
FastForward => todo!(),
299315
Rewind => todo!(),
300316
ChannelUp => todo!(),

examples/print_events.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,25 @@ fn main() {
1111
let (config, permissions) = {
1212
(
1313
souvlaki::platform::mpris::MprisConfig {
14-
display_name: "Souvlaki Player".to_owned(),
14+
identity: "Souvlaki Player".to_owned(),
1515
dbus_name: "souvlaki_player".to_owned(),
16+
desktop_entry: "souvlaki".to_owned(),
17+
},
18+
souvlaki::platform::mpris::MprisPermissions {
19+
can_quit: true,
20+
can_set_fullscreen: true,
21+
can_raise: true,
22+
supported_uri_schemes: vec![],
23+
supported_mime_types: vec![],
24+
can_go_next: true,
25+
can_go_previous: true,
26+
can_play: true,
27+
can_pause: true,
28+
can_seek: true,
29+
can_control: true,
30+
min_rate: 1.0,
31+
max_rate: 1.0,
1632
},
17-
(),
1833
)
1934
};
2035

src/controls.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,8 @@ pub trait MediaControls: Sized + Debug {
3434
fn set_volume(&mut self, volume: f64) -> Result<(), Self::Error>;
3535
/// Set the playback rate, e.g. 0.5x, 1.0x, 2.0x.
3636
fn set_rate(&mut self, rate: f64) -> Result<(), Self::Error>;
37-
/// Set the maximum allowed playback rate.
38-
/// - max: should always be 1.0 or more
39-
/// - min: should always be 1.0 or less
40-
/// Only events received within these limits will be sent to the application handler.
41-
fn set_rate_limits(&mut self, min: f64, max: f64) -> Result<(), Self::Error>;
37+
/// Set whether the app is fullscreen.
38+
fn set_fullscreen(&mut self, rate: bool) -> Result<(), Self::Error>;
4239
}
4340

4441
/// NOTE: Use this wrapper instead of the platform-specific control structs.
@@ -93,8 +90,8 @@ impl<T: MediaControls> MediaControls for MediaControlsWrapper<T> {
9390
fn set_rate(&mut self, rate: f64) -> Result<(), T::Error> {
9491
self.inner.set_rate(rate)
9592
}
96-
fn set_rate_limits(&mut self, min: f64, max: f64) -> Result<(), T::Error> {
97-
self.inner.set_rate_limits(min, max)
93+
fn set_fullscreen(&mut self, fullscreen: bool) -> Result<(), T::Error> {
94+
self.inner.set_fullscreen(fullscreen)
9895
}
9996
}
10097

src/lib.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![doc = include_str!("../README.md")]
22

3+
use std::convert::TryFrom;
34
use std::{fmt::Debug, time::Duration};
45

56
mod controls;
@@ -28,6 +29,9 @@ pub enum MediaControlEvent {
2829
/// Seek forward or backward by a certain amount.
2930
SeekBy(SeekDirection, Duration),
3031
/// Set the position/progress of the currently playing media item.
32+
/// **NOTE**: If the request was handled, and the property
33+
/// was changed, [`MediaControls::set_playback`] must be called
34+
/// with the new progress value.
3135
SetPosition(MediaPosition),
3236
/// Set the volume. The value is intended to be from 0.0 to 1.0.
3337
/// But other values are also accepted. **It is up to the
@@ -59,6 +63,11 @@ pub enum MediaControlEvent {
5963
Raise,
6064
/// Shut down the media player.
6165
Quit,
66+
/// Control whether the app is fullscreen or not
67+
/// **NOTE**: If the request was handled, and the property
68+
/// was changed, [`MediaControls::set_fullscreen`] must be called
69+
/// with the new value.
70+
SetFullscreen(bool),
6271

6372
/// Windows-specific
6473
FastForward,
@@ -87,6 +96,18 @@ impl MediaPlayback {
8796
Stopped => "Stopped",
8897
}
8998
}
99+
pub fn to_micros(&self) -> i64 {
100+
i64::try_from(match self {
101+
MediaPlayback::Playing {
102+
progress: Some(progress),
103+
}
104+
| MediaPlayback::Paused {
105+
progress: Some(progress),
106+
} => progress.0.as_micros(),
107+
_ => 0,
108+
})
109+
.unwrap_or(0)
110+
}
90111
}
91112

92113
/// A repeat/loop status

src/platform/apple/mod.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,6 @@ impl MediaControls for Apple {
199199
// unsupported, ignoring.
200200
Ok(())
201201
}
202-
203-
fn set_rate_limits(&mut self, _min: f64, _max: f64) -> Result<(), Self::Error> {
204-
// unsupported, ignoring.
205-
Ok(())
206-
}
207202
}
208203

209204
// MPNowPlayingPlaybackState

0 commit comments

Comments
 (0)