
#include <libsaria/print.h>
#include "audio.h"

static bool initialized = false;
static void init_gstreamer(int argc, char **argv)
{
	if (initialized == true)
		return;
	gst_init(&argc, &argv);
	initialized = true;
}

Audio::Audio()
{
	println("Creating audio driver");
}

Audio::~Audio()
{
}

void Audio::init(int argc, char **argv)
{
	println("Initializing gstreamer");
	init_gstreamer(argc, argv);
	player = gst_element_factory_make("playbin2", "player");
	set_volume(1.0);
}

void Audio::reset()
{
	cur_file = "";
	change_state(GST_STATE_NULL);
}

void Audio::load(string file)
{
	string uri = "file://" + file;
	reset();
	cur_file = file;
	g_object_set(G_OBJECT(player), "uri", uri.c_str(), NULL);
}
