libsaria: Call next() at the end of the stream
It's nice to pick another song after the end of the current one.
This commit is contained in:
parent
fffb9875ac
commit
6b58311e9e
|
@ -1,15 +1,41 @@
|
|||
|
||||
#include <libsaria/audio.h>
|
||||
#include <libsaria/controls.h>
|
||||
#include <libsaria/print.h>
|
||||
#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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue