[rygel] renderer: Add play_speed_to_double() to MediaPlayer
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel] renderer: Add play_speed_to_double() to MediaPlayer
- Date: Sun, 10 Nov 2013 13:55:52 +0000 (UTC)
commit d9e52441582026bc20e1e08a37a9186cf283e079
Author: Jussi Kukkonen <jussi kukkonen intel com>
Date: Wed Oct 30 14:30:15 2013 +0200
renderer: Add play_speed_to_double() to MediaPlayer
This can be useful for all player implementations.
https://bugzilla.gnome.org/show_bug.cgi?id=710368
src/librygel-renderer/rygel-media-player.vala | 19 ++++++++++++
src/plugins/mpris/rygel-mpris-player.vala | 38 ++++---------------------
2 files changed, 25 insertions(+), 32 deletions(-)
---
diff --git a/src/librygel-renderer/rygel-media-player.vala b/src/librygel-renderer/rygel-media-player.vala
index 877780a..181ffeb 100644
--- a/src/librygel-renderer/rygel-media-player.vala
+++ b/src/librygel-renderer/rygel-media-player.vala
@@ -104,4 +104,23 @@ public interface Rygel.MediaPlayer : GLib.Object {
/// Return the MIME types supported by this renderer.
/// The mime types in this list should be all lowercase.
public abstract string[] get_mime_types ();
+
+ /**
+ * Transform a fractional playspeed (e.g. "-1/4") to double.
+ * Input values are expected to be valid rational numbers.
+ */
+ protected double play_speed_to_double (string speed)
+ {
+ string[] rational = speed.split ("/", 2);
+
+ assert (rational[0] != "0");
+
+ if (rational[1] == null) {
+ return double.parse (rational[0]);
+ }
+
+ assert (rational[1] != "0");
+
+ return double.parse (rational[0]) / double.parse (rational[1]);
+ }
}
diff --git a/src/plugins/mpris/rygel-mpris-player.vala b/src/plugins/mpris/rygel-mpris-player.vala
index ef1914e..ba7afaf 100644
--- a/src/plugins/mpris/rygel-mpris-player.vala
+++ b/src/plugins/mpris/rygel-mpris-player.vala
@@ -72,19 +72,21 @@ public class Rygel.MPRIS.Player : GLib.Object, Rygel.MediaPlayer {
}
}
+ private string _playback_speed;
public string playback_speed {
owned get {
- return this.double_to_rational (this.actual_player.rate);
+ return this._playback_speed;
}
set {
- this.actual_player.rate = this.rational_to_double (value);
+ this.actual_player.rate = this.play_speed_to_double (value);
+ this._playback_speed = value;
}
}
public double minimum_rate {
get {
- return this.rational_to_double (_allowed_playback_speeds[0]);
+ return this.play_speed_to_double (_allowed_playback_speeds[0]);
}
}
@@ -94,7 +96,7 @@ public class Rygel.MPRIS.Player : GLib.Object, Rygel.MediaPlayer {
assert (i > 0);
- return this.rational_to_double (_allowed_playback_speeds[i-1]);
+ return this.play_speed_to_double (_allowed_playback_speeds[i-1]);
}
}
@@ -195,34 +197,6 @@ public class Rygel.MPRIS.Player : GLib.Object, Rygel.MediaPlayer {
}
}
- private double rational_to_double (string r)
- {
- string[] rational;
-
- rational = r.split("/", 2);
-
- assert (rational[0] != "0");
-
- if (rational[1] != null) {
- assert (rational[1] != "0");
- } else {
- return double.parse (rational[0]);
- }
-
- return double.parse (rational[0]) / double.parse (rational[1]);
- }
-
- private string double_to_rational (double d)
- {
- foreach (var r in _allowed_playback_speeds) {
- if (Math.fabs (rational_to_double (r) - d) < 0.1) {
- return r;
- }
- }
-
- return "";
- }
-
private void on_properties_changed (DBusProxy actual_player,
Variant changed,
string[] invalidated) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]