libsaria: Create a durstr() function

Call this to get a string representation of the pipeline's current
duration.
This commit is contained in:
Bryan Schumaker 2011-12-23 20:31:07 -05:00
parent e509d4e723
commit 7711b354cb
2 changed files with 23 additions and 11 deletions

View File

@ -29,6 +29,7 @@ namespace libsaria
gint64 duration();
gint64 position();
string posstr();
string durstr();
/* Volume functions */
double get_volume();

View File

@ -21,6 +21,20 @@ static bool get_position(gint64 &position)
&position);
}
static string to_string(gint64 &time)
{
stringstream stream;
int minutes, seconds;
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
{
@ -75,21 +89,18 @@ namespace libsaria
string audio::posstr()
{
stringstream stream;
gint64 pos;
int minutes, seconds;
if (!get_position(pos))
return "";
return to_string(pos);
}
pos = pos / GST_SECOND;
minutes = pos / 60;
seconds = pos - (minutes * 60);
stream << minutes << ":";
if (seconds < 10)
stream << "0";
stream << seconds;
return stream.str();
string audio::durstr()
{
gint64 dur;
if (!get_duration(dur))
return "";
return to_string(dur);
}
};