From 8987dddade6a39654c3731d85e19550ff35c6b1a Mon Sep 17 00:00:00 2001 From: Bryan Schumaker Date: Sat, 29 Oct 2011 17:23:25 -0400 Subject: [PATCH] libsaria: Added a get_progress() function to the audio namespace This function is used to access how far into the song the current audio position is. The value is returned as a percentage of the total length for easy use by the UI. --- include/libsaria/audio.h | 1 + libsaria/audio/progress.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/include/libsaria/audio.h b/include/libsaria/audio.h index 428aed62..3827b207 100644 --- a/include/libsaria/audio.h +++ b/include/libsaria/audio.h @@ -20,6 +20,7 @@ namespace libsaria /* Position related functions */ bool seek(int); bool seek_to(double); + int get_progress(); /* Volume functions */ double get_volume(); diff --git a/libsaria/audio/progress.cpp b/libsaria/audio/progress.cpp index 6bb358b8..6050b9d2 100644 --- a/libsaria/audio/progress.cpp +++ b/libsaria/audio/progress.cpp @@ -57,4 +57,15 @@ namespace libsaria return ret; } + int audio::get_progress() + { + gint64 progress; + gint64 duration; + if (!get_position(progress)) + return 0; + if (!get_duration(duration)) + return 0; + return (progress * 100) / duration; + } + };