[monkey-bubble: 740/753] re-implement looping



commit 2d1f56aa0c4e3624ca0cf129c8788b9f0a506379
Author: Sven Herzberg <herzi gnome-de org>
Date:   Wed Jul 14 14:40:46 2010 +0200

    re-implement looping
    
    * src/audio/sound-manager.c: re-implement the old loop behavior

 src/audio/sound-manager.c |   53 +++++++++++++++++++++++++++++++++++++-------
 1 files changed, 44 insertions(+), 9 deletions(-)
---
diff --git a/src/audio/sound-manager.c b/src/audio/sound-manager.c
index a551c4d..250643b 100644
--- a/src/audio/sound-manager.c
+++ b/src/audio/sound-manager.c
@@ -172,6 +172,26 @@ static SoundManager * sound_manager_new( void ) {
   return sound_manager;
 }
 
+static gboolean
+replay_music (gpointer  user_data)
+{
+  /* FIXME: there is no proper bookkeeping */
+  sound_manager_play_music (user_data, PRIVATE (SOUND_MANAGER (user_data))->current_music_id);
+
+  return FALSE;
+}
+
+static void
+finished_cb (ca_context* c,
+             guint32     id,
+             int         error_code,
+             gpointer    user_data)
+{
+  if (error_code != CA_ERROR_CANCELED)
+    {
+      g_idle_add (replay_music, user_data);
+    }
+}
 
 void
 sound_manager_play_music (SoundManager* m,
@@ -198,19 +218,34 @@ sound_manager_play_music (SoundManager* m,
           DATADIR "/monkey-bubble/sounds/splash.ogg",
           DATADIR "/monkey-bubble/sounds/game.ogg"
         };
-      int result = ca_context_play (PRIVATE (m)->context,
-                                    PLAY_ID_MUSIC,
-                                    CA_PROP_MEDIA_FILENAME, paths[PRIVATE (m)->current_music_id],
-                                    NULL);
-
-      g_print ("trying to play %s\n", paths[PRIVATE (m)->current_music_id]);
-
-      /* FIXME: set up the looping */
-
+      ca_proplist* properties = NULL;
+      int result = ca_proplist_create (&properties);
+      if (result != CA_SUCCESS)
+        {
+          g_warning ("ca_proplist_create(): %d", result);
+        }
+      result = ca_proplist_sets (properties,
+                                 CA_PROP_MEDIA_FILENAME,
+                                 paths[PRIVATE (m)->current_music_id]);
+      if (result != CA_SUCCESS)
+        {
+          g_warning ("ca_proplist_sets(): %d", result);
+        }
+      result = ca_context_play_full (PRIVATE (m)->context,
+                                     PLAY_ID_MUSIC,
+                                     properties,
+                                     finished_cb,
+                                     m);
       if (result != CA_SUCCESS)
         {
           g_warning ("ca_context_play(): %d", result);
         }
+
+      result = ca_proplist_destroy (properties);
+      if (result != CA_SUCCESS)
+        {
+          g_warning ("ca_proplist_destroy(): %d", result);
+        }
     }
 }
 



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