libsaria: Cleanup audio progress code

This commit is contained in:
Bryan Schumaker 2011-12-23 21:14:14 -05:00
parent 0e983e4043
commit 1dc9df80e1
1 changed files with 29 additions and 35 deletions

View File

@ -21,20 +21,24 @@ static bool get_position(gint64 &position)
&position);
}
static string to_string(gint64 &time)
{
stringstream stream;
int minutes, seconds;
static string to_string(gint64 time)
{
stringstream stream;
int minutes, seconds;
if (time == 0)
return "";
time = time / GST_SECOND;
minutes = time / 60;
seconds = time - (minutes * 60);
stream << minutes << ":";
if (seconds < 10)
stream << "0";
stream << seconds;
return stream.str();
}
time = time / GST_SECOND;
minutes = time / 60;
seconds = time - (minutes * 60);
stream << minutes << ":";
if (seconds < 10)
stream << "0";
stream << seconds;
return stream.str();
}
namespace libsaria
{
@ -54,19 +58,15 @@ namespace libsaria
bool audio::seek(int dt)
{
bool ret;
gint64 cur_pos;
gint64 new_pos;
gint64 pos;
ret = get_position(cur_pos);
ret = get_position(pos);
if (ret == true) {
/* Convert seconds to nano-seconds */
new_pos = cur_pos + (dt * GST_SECOND);
if (new_pos < 0)
new_pos = 0;
gst_element_seek_simple(GST_ELEMENT(player),
GST_FORMAT_TIME,
GST_SEEK_FLAG_FLUSH,
new_pos);
pos += (dt * GST_SECOND);
if (pos < 0)
pos = 0;
seek_to(pos);
}
return ret;
}
@ -79,6 +79,11 @@ namespace libsaria
return duration;
}
string audio::durstr()
{
return to_string(duration());
}
gint64 audio::position()
{
gint64 position;
@ -89,18 +94,7 @@ namespace libsaria
string audio::posstr()
{
gint64 pos;
if (!get_position(pos))
return "";
return to_string(pos);
}
string audio::durstr()
{
gint64 dur;
if (!get_duration(dur))
return "";
return to_string(dur);
return to_string(position());
}
};