ocarina/libsaria/audio/controls.cpp

45 lines
792 B
C++

#include <libsaria/audio.h>
#include <libsaria/print.h>
bool Audio::change_state(GstState new_state)
{
GstStateChangeReturn ret;
ret = gst_element_set_state(GST_ELEMENT(player), new_state);
switch(ret) {
case GST_STATE_CHANGE_SUCCESS:
case GST_STATE_CHANGE_ASYNC:
return true;
default:
return false;
}
}
void Audio::check_state(GstState state)
{
}
bool Audio::play()
{
return change_state(GST_STATE_PLAYING);
}
bool Audio::pause()
{
return change_state(GST_STATE_PAUSED);
}
/*
* Right now I just seek to the beginning of the song.
* Eventually I should allow the user to seek anywhere.
*/
void Audio::seek()
{
gst_element_seek_simple(GST_ELEMENT(player),
GST_FORMAT_TIME,
GST_SEEK_FLAG_FLUSH,
// Convert seconds to nano-seconds
0 * GST_SECOND);
}