libsaria: Improved audio file loading
I look for an audio-changed signal and push this to the message bus. I then use the message to send out the TRACK_LOADED callback to the UI. This should be even more useful for gapless playback.
This commit is contained in:
parent
5e20a26dbf
commit
2783b8d995
|
@ -2,6 +2,7 @@
|
|||
#include <libsaria/audio.h>
|
||||
#include <libsaria/controls.h>
|
||||
#include <libsaria/print.h>
|
||||
#include <libsaria/callback.h>
|
||||
#include "audio.h"
|
||||
|
||||
GstElement *player = NULL;
|
||||
|
@ -18,9 +19,26 @@ static void parse_error(GstMessage *error)
|
|||
g_free(debug);
|
||||
}
|
||||
|
||||
static void notify_audio_changed()
|
||||
{
|
||||
println("Notify audio changed");
|
||||
if (libsaria::get_pause_after()) {
|
||||
libsaria::audio::pause();
|
||||
libsaria::set_pause_after(false);
|
||||
}
|
||||
trigger_callback(TRACK_LOADED);
|
||||
}
|
||||
|
||||
static gboolean on_message(GstBus *bus, GstMessage *message, gpointer data)
|
||||
{
|
||||
switch (GST_MESSAGE_TYPE(message)) {
|
||||
/*
|
||||
* The application message is only sent
|
||||
* when the audio changes
|
||||
*/
|
||||
case GST_MESSAGE_APPLICATION:
|
||||
notify_audio_changed();
|
||||
break;
|
||||
case GST_MESSAGE_ERROR:
|
||||
parse_error(message);
|
||||
case GST_MESSAGE_EOS:
|
||||
|
@ -31,6 +49,16 @@ static gboolean on_message(GstBus *bus, GstMessage *message, gpointer data)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static void audio_changed(GstElement *playbin, gpointer data)
|
||||
{
|
||||
GQuark quark = g_quark_from_string("audio-changed");
|
||||
GstStructure *msg_struct = gst_structure_id_empty_new(quark);
|
||||
GstMessage *message = gst_message_new_application(GST_OBJECT(playbin), msg_struct);
|
||||
|
||||
println("Audio changed!");
|
||||
gst_bus_post(bus, message);
|
||||
}
|
||||
|
||||
namespace libsaria
|
||||
{
|
||||
|
||||
|
@ -43,6 +71,8 @@ namespace libsaria
|
|||
bus = gst_pipeline_get_bus(GST_PIPELINE(player));
|
||||
|
||||
gst_bus_add_watch(bus, on_message, NULL);
|
||||
g_signal_connect(player, "audio-changed", G_CALLBACK(audio_changed), NULL);
|
||||
|
||||
set_volume(1.0);
|
||||
}
|
||||
|
||||
|
|
|
@ -11,4 +11,6 @@ extern "C" {
|
|||
extern GstElement *player;
|
||||
extern GstBus *bus;
|
||||
|
||||
void load_file(GstElement *, string);
|
||||
|
||||
#endif /* LIBSARIA_AUDIO_PRIVATE_H */
|
||||
|
|
|
@ -28,6 +28,16 @@ static void reset()
|
|||
change_state(GST_STATE_NULL);
|
||||
}
|
||||
|
||||
void load_file(GstElement *playbin, string file)
|
||||
{
|
||||
if (file == "")
|
||||
return;
|
||||
string uri = "file://" + file;
|
||||
println("Loading uri: " + uri);
|
||||
g_object_set(G_OBJECT(playbin), "uri", uri.c_str(), NULL);
|
||||
cur_file = file;
|
||||
}
|
||||
|
||||
namespace libsaria
|
||||
{
|
||||
|
||||
|
@ -54,23 +64,12 @@ namespace libsaria
|
|||
seek_to(0);
|
||||
}
|
||||
|
||||
void audio::load_file(string file)
|
||||
{
|
||||
if (file == "")
|
||||
return;
|
||||
string uri = "file://" + file;
|
||||
println("Loading uri: " + uri);
|
||||
g_object_set(G_OBJECT(player), "uri", uri.c_str(), NULL);
|
||||
cur_file = file;
|
||||
trigger_callback(TRACK_LOADED);
|
||||
}
|
||||
|
||||
void audio::load(string file)
|
||||
{
|
||||
if (file == "")
|
||||
return;
|
||||
reset();
|
||||
load_file(file);
|
||||
load_file(player, file);
|
||||
}
|
||||
|
||||
string audio::get_current_file()
|
||||
|
|
Loading…
Reference in New Issue