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:
parent
e752e0f826
commit
e8d63a15cf
|
@ -20,6 +20,7 @@ namespace audio
|
||||||
|
|
||||||
void play();
|
void play();
|
||||||
void pause();
|
void pause();
|
||||||
|
void toggle_play();
|
||||||
void stop();
|
void stop();
|
||||||
void next();
|
void next();
|
||||||
void previous();
|
void previous();
|
||||||
|
|
|
@ -11,11 +11,12 @@
|
||||||
|
|
||||||
static GstElement *ocarina_player;
|
static GstElement *ocarina_player;
|
||||||
|
|
||||||
|
static bool player_playing = false;
|
||||||
static bool track_loaded = false;
|
static bool track_loaded = false;
|
||||||
static unsigned int cur_trackid = 0;
|
static unsigned int cur_trackid = 0;
|
||||||
|
|
||||||
static bool o_pause_enabled = false;
|
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 bool o_should_pause = false;
|
||||||
|
|
||||||
static Playqueue o_recently_played(PQ_ENABLED);
|
static Playqueue o_recently_played(PQ_ENABLED);
|
||||||
|
@ -74,8 +75,10 @@ static bool change_state(GstState state)
|
||||||
switch (ret) {
|
switch (ret) {
|
||||||
case GST_STATE_CHANGE_SUCCESS:
|
case GST_STATE_CHANGE_SUCCESS:
|
||||||
case GST_STATE_CHANGE_ASYNC:
|
case GST_STATE_CHANGE_ASYNC:
|
||||||
|
player_playing = (state == GST_STATE_PLAYING);
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
|
player_playing = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -140,6 +143,14 @@ void audio :: pause()
|
||||||
get_callbacks()->on_pause();
|
get_callbacks()->on_pause();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void audio :: toggle_play()
|
||||||
|
{
|
||||||
|
if (player_playing == true)
|
||||||
|
pause();
|
||||||
|
else
|
||||||
|
play();
|
||||||
|
}
|
||||||
|
|
||||||
void audio :: stop()
|
void audio :: stop()
|
||||||
{
|
{
|
||||||
pause();
|
pause();
|
||||||
|
|
Loading…
Reference in New Issue