libsaria: Created a seek_to() function

This function will seek to an absolute percentage of a song, rather than
by some displaced amount.
This commit is contained in:
Bryan Schumaker 2011-09-03 22:32:12 -04:00
parent 4b3b1babbc
commit 77a7f84110
6 changed files with 38 additions and 6 deletions

View File

@ -31,7 +31,11 @@ class Audio
/* Control functions */
bool play();
bool pause();
/* Functions related to position in the song */
void seek();
bool seek_to(double);
bool get_duration(gint64 &);
};
#endif /* LIBSARIA_AUDIO_H */

View File

@ -25,7 +25,10 @@ class Libsaria
void play();
void pause();
void stop();
void seek();
/* Functions related to position in the song */
void seek(int);
void seek_to(double);
};
class Libsaria *libsaria_get();

View File

@ -1,3 +1,3 @@
void libsaria_seek();
void libsaria_seek(int);

View File

@ -1,6 +1,26 @@
#include <libsaria/audio.h>
bool Audio::get_duration(gint64 &duration)
{
GstFormat format;
return gst_element_query_duration(GST_ELEMENT(player),
&format,
&duration);
}
bool Audio::seek_to(double prcnt)
{
bool ret;
gint64 duration;
ret = get_duration(duration);
gst_element_seek_simple(GST_ELEMENT(player),
GST_FORMAT_TIME,
GST_SEEK_FLAG_FLUSH,
duration * prcnt);
return ret;
}
/*
* Right now I just seek to the beginning of the song.
* Eventually I should allow the user to seek anywhere.

View File

@ -21,7 +21,7 @@ void Libsaria::pause()
void Libsaria::stop()
{
pause();
seek();
seek_to(0);
}
/*

View File

@ -5,7 +5,12 @@
* Implementations of functions defined in the libsaria class
*/
void Libsaria::seek()
void Libsaria::seek_to(double prcnt)
{
audio.seek_to(prcnt);
}
void Libsaria::seek(int dt)
{
audio.seek();
}
@ -14,8 +19,8 @@ void Libsaria::seek()
* Convenience functions for accessing libsaria class functions
*/
void libsaria_seek()
void libsaria_seek(int dt)
{
libsaria_get()->seek();
libsaria_get()->seek(dt);
}