[gthumb] slideshow: fixed audio playback



commit 8163fdee57da7700ba63986f133b2f6f81ad0a73
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Thu Mar 28 19:49:07 2013 +0100

    slideshow: fixed audio playback

 extensions/gstreamer_utils/gstreamer-utils.c |    8 ++++-
 extensions/slideshow/gth-slideshow.c         |   49 +++++++++++++++++--------
 2 files changed, 40 insertions(+), 17 deletions(-)
---
diff --git a/extensions/gstreamer_utils/gstreamer-utils.c b/extensions/gstreamer_utils/gstreamer-utils.c
index 101cedb..4865f66 100644
--- a/extensions/gstreamer_utils/gstreamer-utils.c
+++ b/extensions/gstreamer_utils/gstreamer-utils.c
@@ -108,8 +108,14 @@ gboolean
 gstreamer_init (void)
 {
        if (! gstreamer_initialized) {
-               if (! gst_init_check (NULL, NULL, NULL))
+               GError *error = NULL;
+
+               if (! gst_init_check (NULL, NULL, &error)) {
+                       g_warning ("%s", error->message);
+                       g_error_free (error);
                        return FALSE;
+               }
+
                gstreamer_initialized = TRUE;
        }
 
diff --git a/extensions/slideshow/gth-slideshow.c b/extensions/slideshow/gth-slideshow.c
index c4c1a2d..efb60c2 100644
--- a/extensions/slideshow/gth-slideshow.c
+++ b/extensions/slideshow/gth-slideshow.c
@@ -36,6 +36,7 @@
 #define HIDE_CURSOR_DELAY 1
 #define HIDE_PAUSED_SIGN_DELAY 1
 #define DEFAULT_DELAY 2000
+#define _GST_PLAY_FLAG_AUDIO (1 << 1)
 
 
 G_DEFINE_TYPE (GthSlideshow, gth_slideshow, GTK_TYPE_WINDOW)
@@ -353,25 +354,36 @@ _gth_slideshow_toggle_pause (GthSlideshow *self)
 
 
 #if HAVE_GSTREAMER
-static void
-bus_message_cb (GstBus     *bus,
-                GstMessage *message,
-                gpointer    user_data)
+
+
+static gboolean
+player_done_cb (gpointer user_data)
 {
        GthSlideshow *self = user_data;
 
-       if (GST_MESSAGE_TYPE (message) == GST_MESSAGE_EOS) {
-               self->priv->current_audio_file++;
-               if ((self->priv->audio_files[self->priv->current_audio_file] == NULL)
-                   && self->priv->audio_loop)
-               {
-                       self->priv->current_audio_file = 0;
-               }
-               gst_element_set_state (self->priv->playbin, GST_STATE_NULL);
-               g_object_set (G_OBJECT (self->priv->playbin), "uri", 
self->priv->audio_files[self->priv->current_audio_file], NULL);
-               gst_element_set_state (self->priv->playbin, GST_STATE_PLAYING);
+       self->priv->current_audio_file++;
+       if ((self->priv->audio_files[self->priv->current_audio_file] == NULL)
+           && self->priv->audio_loop)
+       {
+               self->priv->current_audio_file = 0;
        }
+       gst_element_set_state (self->priv->playbin, GST_STATE_READY);
+       g_object_set (G_OBJECT (self->priv->playbin), "uri", 
self->priv->audio_files[self->priv->current_audio_file], NULL);
+       gst_element_set_state (self->priv->playbin, GST_STATE_PLAYING);
+
+       return FALSE;
 }
+
+
+static void
+pipeline_eos_cb (GstBus     *bus,
+                 GstMessage *message,
+                 gpointer    user_data)
+{
+       g_idle_add (player_done_cb, user_data);
+}
+
+
 #endif
 
 
@@ -394,12 +406,17 @@ gth_slideshow_show_cb (GtkWidget    *widget,
                        GstBus *bus;
 
                        self->priv->playbin = gst_element_factory_make ("playbin", "playbin");
+                       g_object_set (self->priv->playbin,
+                                     "audio-sink", gst_element_factory_make ("gsettingsaudiosink", 
"audiosink"),
+                                     "flags", _GST_PLAY_FLAG_AUDIO,
+                                     "volume", 1.0,
+                                     NULL);
                        bus = gst_pipeline_get_bus (GST_PIPELINE (self->priv->playbin));
                        gst_bus_add_signal_watch (bus);
-                       g_signal_connect (bus, "message", G_CALLBACK (bus_message_cb), self);
+                       g_signal_connect (bus, "message::eos", G_CALLBACK (pipeline_eos_cb), self);
                }
                else
-                       gst_element_set_state (self->priv->playbin, GST_STATE_NULL);
+                       gst_element_set_state (self->priv->playbin, GST_STATE_READY);
                g_object_set (G_OBJECT (self->priv->playbin), "uri", 
self->priv->audio_files[self->priv->current_audio_file], NULL);
                gst_element_set_state (self->priv->playbin, GST_STATE_PLAYING);
        }


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