From 6b58311e9e86da117d3df7620841fbb57f834668 Mon Sep 17 00:00:00 2001 From: Bryan Schumaker Date: Sun, 6 Nov 2011 19:44:16 -0500 Subject: [PATCH] libsaria: Call next() at the end of the stream It's nice to pick another song after the end of the current one. --- libsaria/audio/audio.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/libsaria/audio/audio.cpp b/libsaria/audio/audio.cpp index 8b951cac..718c3b35 100644 --- a/libsaria/audio/audio.cpp +++ b/libsaria/audio/audio.cpp @@ -1,15 +1,41 @@ #include +#include #include #include "audio.h" static GstElement *player = NULL; +static GstBus *bus = NULL; GstElement *get_player() { return player; } +static void parse_error(GstMessage *error) +{ + GError *err; + gchar *debug; + + gst_message_parse_error(error, &err, &debug); + g_print("Error: %s\n", err->message); + g_error_free(err); + g_free(debug); +} + +static gboolean on_message(GstBus *bus, GstMessage *message, gpointer data) +{ + switch (GST_MESSAGE_TYPE(message)) { + case GST_MESSAGE_ERROR: + parse_error(message); + case GST_MESSAGE_EOS: + libsaria::next(); + default: + break; + } + return TRUE; +} + namespace libsaria { @@ -17,7 +43,11 @@ namespace libsaria { println("Initializing audio driver"); gst_init(&argc, &argv); + player = gst_element_factory_make("playbin2", "player"); + bus = gst_pipeline_get_bus(GST_PIPELINE(player)); + + gst_bus_add_watch(bus, on_message, NULL); set_volume(1.0); }