[rhythmbox] shell-player: add dbus method for relative seeking



commit 95d082eda1042a5cbcaaba8aa0b3e60063ed312c
Author: Karl Ljungkvist <k ljungkvist gmail com>
Date:   Sun Aug 29 23:24:30 2010 +1000

    shell-player: add dbus method for relative seeking

 bindings/python/rb.defs           |    5 +++--
 plugins/lirc/rb-lirc-plugin.c     |    4 ++--
 plugins/mmkeys/rb-mmkeys-plugin.c |    4 ++--
 plugins/mpris/rb-mpris-plugin.c   |    2 +-
 remote/dbus/rb-client.c           |   11 ++++++++++-
 shell/rb-shell-player.c           |   31 ++++++++++++++++++++++---------
 shell/rb-shell-player.h           |    4 +++-
 shell/rb-shell-player.xml         |    5 +++++
 8 files changed, 48 insertions(+), 18 deletions(-)
---
diff --git a/bindings/python/rb.defs b/bindings/python/rb.defs
index 8c20dca..d7a9913 100644
--- a/bindings/python/rb.defs
+++ b/bindings/python/rb.defs
@@ -736,9 +736,10 @@
 (define-method seek
   (of-object "RBShellPlayer")
   (c-name "rb_shell_player_seek")
-  (return-type "none")
+  (return-type "gboolean")
   (parameters
-    '("long" "offset")
+    '("gint32" "offset")
+    '("GError**" "error")
   )
 )
 
diff --git a/plugins/lirc/rb-lirc-plugin.c b/plugins/lirc/rb-lirc-plugin.c
index 44f6879..c506e4a 100644
--- a/plugins/lirc/rb-lirc-plugin.c
+++ b/plugins/lirc/rb-lirc-plugin.c
@@ -163,9 +163,9 @@ rb_lirc_plugin_read_code (GIOChannel *source,
 		} else if (strcmp (str, RB_IR_COMMAND_PREVIOUS) == 0) {
 			rb_shell_player_do_previous (plugin->shell_player, NULL);
 		} else if (strcmp (str, RB_IR_COMMAND_SEEK_FORWARD) == 0) {
-			rb_shell_player_seek (plugin->shell_player, FFWD_OFFSET);
+			rb_shell_player_seek (plugin->shell_player, FFWD_OFFSET, NULL);
 		} else if (strcmp (str, RB_IR_COMMAND_SEEK_BACKWARD) == 0) {
-			rb_shell_player_seek (plugin->shell_player, -RWD_OFFSET);
+			rb_shell_player_seek (plugin->shell_player, -RWD_OFFSET, NULL);
 		} else if (strcmp (str, RB_IR_COMMAND_VOLUME_UP) == 0) {
 			rb_shell_player_set_volume_relative (plugin->shell_player, 0.1, NULL);
 		} else if (strcmp (str, RB_IR_COMMAND_VOLUME_DOWN) == 0) {
diff --git a/plugins/mmkeys/rb-mmkeys-plugin.c b/plugins/mmkeys/rb-mmkeys-plugin.c
index 1efb054..148c75e 100644
--- a/plugins/mmkeys/rb-mmkeys-plugin.c
+++ b/plugins/mmkeys/rb-mmkeys-plugin.c
@@ -129,9 +129,9 @@ media_player_key_pressed (DBusGProxy *proxy,
 			rb_shell_player_set_playback_state (plugin->shell_player, !shuffle, repeat);
 		}
 	} else if (strcmp (key, "FastForward") == 0) {
-		rb_shell_player_seek (plugin->shell_player, FFWD_OFFSET);
+		rb_shell_player_seek (plugin->shell_player, FFWD_OFFSET, NULL);
 	} else if (strcmp (key, "Rewind") == 0) {
-		rb_shell_player_seek (plugin->shell_player, -RWD_OFFSET);
+		rb_shell_player_seek (plugin->shell_player, -RWD_OFFSET, NULL);
 	}
 }
 
diff --git a/plugins/mpris/rb-mpris-plugin.c b/plugins/mpris/rb-mpris-plugin.c
index 879e107..aca8f27 100644
--- a/plugins/mpris/rb-mpris-plugin.c
+++ b/plugins/mpris/rb-mpris-plugin.c
@@ -570,7 +570,7 @@ handle_player_method_call (GDBusConnection *connection,
 	} else if (g_strcmp0 (method_name, "Seek") == 0) {
 		gint64 offset;
 		g_variant_get (parameters, "(x)", &offset);
-		rb_shell_player_seek (plugin->player, offset / G_USEC_PER_SEC);
+		rb_shell_player_seek (plugin->player, offset / G_USEC_PER_SEC, NULL);
 		g_dbus_method_invocation_return_value (invocation, NULL);
 	} else if (g_strcmp0 (method_name, "SetPosition") == 0) {
 		RhythmDBEntry *playing_entry;
diff --git a/remote/dbus/rb-client.c b/remote/dbus/rb-client.c
index f2fca52..57ec7e6 100644
--- a/remote/dbus/rb-client.c
+++ b/remote/dbus/rb-client.c
@@ -50,6 +50,7 @@ static gboolean hide = FALSE;
 
 static gboolean next = FALSE;
 static gboolean previous = FALSE;
+static gint32 seek = 0;
 
 static gboolean notify = FALSE;
 
@@ -90,6 +91,7 @@ static GOptionEntry args[] = {
 
 	{ "next", 0, 0, G_OPTION_ARG_NONE, &next, N_("Jump to next song"), NULL },
 	{ "previous", 0, 0, G_OPTION_ARG_NONE, &previous, N_("Jump to previous song"), NULL },
+	{ "seek", 0, 0, G_OPTION_ARG_INT64, &seek, N_("Seek in current track"), NULL },
 
 	{ "notify", 0, 0, G_OPTION_ARG_NONE, &notify, N_("Show notification of the playing song"), NULL },
 
@@ -654,7 +656,7 @@ main (int argc, char **argv)
 	}
 
 	/* don't present if we're doing something else */
-	if (next || previous ||
+	if (next || previous || (seek != 0) ||
 	    clear_queue ||
 	    play_uri || other_stuff ||
 	    play || do_pause || play_pause || stop ||
@@ -692,6 +694,13 @@ main (int argc, char **argv)
 		annoy (&error);
 	}
 
+	/* seek in track */
+	if (seek != 0) {
+		rb_debug ("seek");
+		org_gnome_Rhythmbox_Player_seek (player_proxy, seek, &error);
+		annoy (&error);
+	}
+
 	/* 4. add/enqueue */
 	if (clear_queue) {
 		org_gnome_Rhythmbox_Shell_clear_queue (shell_proxy, &error);
diff --git a/shell/rb-shell-player.c b/shell/rb-shell-player.c
index faba668..a544f5a 100644
--- a/shell/rb-shell-player.c
+++ b/shell/rb-shell-player.c
@@ -3333,20 +3333,33 @@ rb_shell_player_set_playing_time (RBShellPlayer *player,
  * rb_shell_player_seek:
  * @player: the #RBShellPlayer
  * @offset: relative seek target (in seconds)
+ * @error: returns error information
+ *
+ * Seeks forwards or backwards in the current playing
+ * song. Fails if the current song is not seekable.
  *
- * Seeks forwards or backwards in the current playing song.
- * Does not return error information.
+ * Return value: %TRUE if successful
  */
-void
-rb_shell_player_seek (RBShellPlayer *player, glong offset)
+gboolean
+rb_shell_player_seek (RBShellPlayer *player,
+		      gint32 offset,
+		      GError **error)
 {
-	g_return_if_fail (RB_IS_SHELL_PLAYER (player));
+	g_return_val_if_fail (RB_IS_SHELL_PLAYER (player), FALSE);
 
 	if (rb_player_seekable (player->priv->mmplayer)) {
-		gint64 t = rb_player_get_time (player->priv->mmplayer);
-		if (t < 0)
-			t = 0;
-		rb_player_set_time (player->priv->mmplayer, t + (offset * RB_PLAYER_SECOND));
+		gint64 target_time = rb_player_get_time (player->priv->mmplayer) +
+			(((gint64)offset) * RB_PLAYER_SECOND);
+		if (target_time < 0)
+			target_time = 0;
+		rb_player_set_time (player->priv->mmplayer, target_time);
+		return TRUE;
+	} else {
+		g_set_error (error,
+			     RB_SHELL_PLAYER_ERROR,
+			     RB_SHELL_PLAYER_ERROR_NOT_SEEKABLE,
+			     _("Current song is not seekable"));
+		return FALSE;
 	}
 }
 
diff --git a/shell/rb-shell-player.h b/shell/rb-shell-player.h
index 6dd6e3b..f8340fe 100644
--- a/shell/rb-shell-player.h
+++ b/shell/rb-shell-player.h
@@ -120,7 +120,9 @@ gboolean		rb_shell_player_get_playing_time(RBShellPlayer *player,
 gboolean		rb_shell_player_set_playing_time(RBShellPlayer *player,
                                                          guint time,
                                                          GError **error);
-void			rb_shell_player_seek		(RBShellPlayer *player, glong offset);
+gboolean		rb_shell_player_seek		(RBShellPlayer *player,
+							 gint32 offset,
+							 GError **error);
 long			rb_shell_player_get_playing_song_duration (RBShellPlayer *player);
 
 gboolean		rb_shell_player_get_playing	(RBShellPlayer *player,
diff --git a/shell/rb-shell-player.xml b/shell/rb-shell-player.xml
index 2f986ec..1111f1b 100644
--- a/shell/rb-shell-player.xml
+++ b/shell/rb-shell-player.xml
@@ -16,6 +16,11 @@
       <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="rb_shell_player_do_next"/>
     </method>
 
+    <method name="seek">
+      <annotation name="org.freedestop.DBus.GLib.CSymbol" value="rb_shell_player_seek"/>
+      <arg type="u" name="offset" direction="in"/>
+    </method>
+
     <method name="getPlaying">
       <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="rb_shell_player_get_playing"/>
       <arg type="b" name="playing" direction="out"/>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]