audio: Add a function to toggle playing

This will be used by the gui when the spacebar is pressed by the user.

Signed-off-by: Anna Schumaker <schumaker.anna@gmail.com>
This commit is contained in:
Anna Schumaker 2014-01-30 21:25:36 -05:00 committed by Anna Schumaker
parent e752e0f826
commit e8d63a15cf
2 changed files with 13 additions and 1 deletions

View File

@ -20,6 +20,7 @@ namespace audio
void play();
void pause();
void toggle_play();
void stop();
void next();
void previous();

View File

@ -11,11 +11,12 @@
static GstElement *ocarina_player;
static bool player_playing = false;
static bool track_loaded = false;
static unsigned int cur_trackid = 0;
static bool o_pause_enabled = false;
static unsigned int o_pause_count = 0;
static unsigned int o_pause_count = 0;
static bool o_should_pause = false;
static Playqueue o_recently_played(PQ_ENABLED);
@ -74,8 +75,10 @@ static bool change_state(GstState state)
switch (ret) {
case GST_STATE_CHANGE_SUCCESS:
case GST_STATE_CHANGE_ASYNC:
player_playing = (state == GST_STATE_PLAYING);
return true;
default:
player_playing = false;
return false;
}
}
@ -140,6 +143,14 @@ void audio :: pause()
get_callbacks()->on_pause();
}
void audio :: toggle_play()
{
if (player_playing == true)
pause();
else
play();
}
void audio :: stop()
{
pause();