48 lines
778 B
C++
48 lines
778 B
C++
|
|
#include <libsaria/audio.h>
|
|
#include <libsaria/libsaria.h>
|
|
|
|
static GstElement *player;
|
|
static string cur_file;
|
|
|
|
void change_state(GstState new_state)
|
|
{
|
|
gst_element_set_state(GST_ELEMENT(player), new_state);
|
|
}
|
|
|
|
void reset()
|
|
{
|
|
cur_file = "";
|
|
change_state(GST_STATE_NULL);
|
|
}
|
|
|
|
void load_file(string file)
|
|
{
|
|
string uri = "file://" + file;
|
|
cur_file = file;
|
|
g_object_set(G_OBJECT(player), "uri", uri.c_str(), NULL);
|
|
}
|
|
|
|
void gst_play()
|
|
{
|
|
print("Playing!");
|
|
change_state(GST_STATE_PLAYING);
|
|
}
|
|
|
|
void gst_pause()
|
|
{
|
|
print("Paused!");
|
|
change_state(GST_STATE_PAUSED);
|
|
}
|
|
|
|
void audio_init(int argc, char **argv)
|
|
{
|
|
print("Initializing audio...");
|
|
gst_init(&argc, &argv);
|
|
|
|
player = gst_element_factory_make("playbin2", "player");
|
|
if (argc > 1)
|
|
load_file(argv[1]);
|
|
gst_play();
|
|
}
|