[the-board: 6/8] [tb] Only run tick timeout while sound is playing



commit 4598c649ffb023fe453f1a22e2397145f5c8eded
Author: Lucas Rocha <lucasr gnome org>
Date:   Thu Jan 27 17:02:14 2011 +0000

    [tb] Only run tick timeout while sound is playing

 src/tb/tb-sound-player.c |   42 ++++++++++++++++++++++++------------------
 1 files changed, 24 insertions(+), 18 deletions(-)
---
diff --git a/src/tb/tb-sound-player.c b/src/tb/tb-sound-player.c
index 8bab376..d2d9a40 100644
--- a/src/tb/tb-sound-player.c
+++ b/src/tb/tb-sound-player.c
@@ -278,6 +278,16 @@ tb_sound_player_destroy_pipeline (TbSoundPlayer *player)
   g_object_notify (G_OBJECT (player), "progress");
 }
 
+static gboolean
+tb_sound_player_tick_timeout (gpointer user_data)
+{
+  GObject *player = user_data;
+
+  g_object_notify (player, "progress");
+
+  return TRUE;
+}
+
 static void
 tb_sound_player_on_state_changed (GstBus        *bus,
                                   GstMessage    *msg,
@@ -302,11 +312,25 @@ tb_sound_player_on_state_changed (GstBus        *bus,
     {
     case GST_STATE_PLAYING:
       tb_sound_player_set_state (player, TB_SOUND_PLAYER_STATE_PLAYING);
+
+      if (priv->tick_timeout_id == 0)
+        {
+          priv->tick_timeout_id =
+            g_timeout_add (TICK_TIMEOUT * 1000,
+                           tb_sound_player_tick_timeout,
+                           player);
+        }
       break;
 
     case GST_STATE_READY:
     case GST_STATE_PAUSED:
       tb_sound_player_set_state (player, TB_SOUND_PLAYER_STATE_IDLE);
+
+      if (priv->tick_timeout_id != 0)
+        {
+          g_source_remove (priv->tick_timeout_id);
+          priv->tick_timeout_id = 0;
+        }
       break;
 
     default:
@@ -374,16 +398,6 @@ tb_sound_player_on_duration (GstBus        *bus,
 }
 
 static gboolean
-tb_sound_player_tick_timeout (gpointer user_data)
-{
-  GObject *player = user_data;
-
-  g_object_notify (player, "progress");
-
-  return TRUE;
-}
-
-static gboolean
 tb_sound_player_ensure_pipeline (TbSoundPlayer *player)
 {
   TbSoundPlayerPrivate *priv;
@@ -457,14 +471,6 @@ tb_sound_player_ensure_pipeline (TbSoundPlayer *player)
                     G_CALLBACK (tb_sound_player_on_duration),
                     player);
 
-  if (priv->tick_timeout_id == 0)
-    {
-      priv->tick_timeout_id =
-        g_timeout_add (TICK_TIMEOUT * 1000,
-                       tb_sound_player_tick_timeout,
-                       player);
-    }
-
   return TRUE;
 }
 



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