diff --git a/include/audio.h b/include/audio.h index 77f850a3..de0fafa8 100644 --- a/include/audio.h +++ b/include/audio.h @@ -20,6 +20,7 @@ namespace audio void play(); void pause(); + void toggle_play(); void stop(); void next(); void previous(); diff --git a/lib/audio.cpp b/lib/audio.cpp index 9930dd8e..a9d1b8d8 100644 --- a/lib/audio.cpp +++ b/lib/audio.cpp @@ -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();