libsaria: Simplify finding audio position and duration
I don't need the extra static function calls since they're only called once. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
e16b70fd81
commit
57bf98972d
|
@ -6,6 +6,7 @@
|
|||
using namespace std;
|
||||
|
||||
static GstElement *player = NULL;
|
||||
static GstFormat fmt_time = GST_FORMAT_TIME;
|
||||
static GstState cur_state = GST_STATE_READY;
|
||||
|
||||
static void notify_state_change(GstState state)
|
||||
|
@ -45,22 +46,6 @@ void load_file(GstElement *playbin, string file, GstState state)
|
|||
change_state(state);
|
||||
}
|
||||
|
||||
static bool get_duration(gint64 &duration)
|
||||
{
|
||||
GstFormat fmt = GST_FORMAT_TIME;
|
||||
return gst_element_query_duration(GST_ELEMENT(player),
|
||||
&fmt,
|
||||
&duration);
|
||||
}
|
||||
|
||||
static bool get_position(gint64 &position)
|
||||
{
|
||||
GstFormat fmt = GST_FORMAT_TIME;
|
||||
return gst_element_query_position(GST_ELEMENT(player),
|
||||
&fmt,
|
||||
&position);
|
||||
}
|
||||
|
||||
static string to_string(gint64 time)
|
||||
{
|
||||
stringstream stream;
|
||||
|
@ -155,7 +140,7 @@ namespace libsaria
|
|||
gint64 audio::duration()
|
||||
{
|
||||
gint64 duration;
|
||||
if (!get_duration(duration))
|
||||
if (!gst_element_query_duration(player, &fmt_time, &duration))
|
||||
return 0;
|
||||
if (duration < 0)
|
||||
duration = 0;
|
||||
|
@ -165,7 +150,7 @@ namespace libsaria
|
|||
gint64 audio::position()
|
||||
{
|
||||
gint64 position;
|
||||
if (!get_position(position))
|
||||
if (!gst_element_query_position(player, &fmt_time, &position))
|
||||
return 0;
|
||||
return position;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue