Skip to content

Commit

Permalink
event_command: add songpause and songresume events
Browse files Browse the repository at this point in the history
This adds code to invoke the event_command handler when playback
is paused or resumed.  This makes it possible to write an event_command
handler that reports the current playback status.
  • Loading branch information
simpkins committed Apr 2, 2024
1 parent 237ac78 commit 2dcc03d
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions src/ui_act.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,28 +429,54 @@ BarUiActCallback(BarUiActSkipSong) {
/* play
*/
BarUiActCallback(BarUiActPlay) {
bool tookAction = false;
PianoReturn_t pRet = PIANO_RET_OK;;
CURLcode wRet = CURLE_OK;

pthread_mutex_lock (&app->player.lock);
app->player.doPause = false;
pthread_cond_broadcast (&app->player.cond);
if (app->player.doPause) {
tookAction = true;
app->player.doPause = false;
pthread_cond_broadcast (&app->player.cond);
}
pthread_mutex_unlock (&app->player.lock);
if (tookAction) {
BarUiActDefaultEventcmd("songresume");
}
}

/* pause
*/
BarUiActCallback(BarUiActPause) {
bool tookAction = false;
PianoReturn_t pRet = PIANO_RET_OK;;
CURLcode wRet = CURLE_OK;

pthread_mutex_lock (&app->player.lock);
app->player.doPause = true;
pthread_cond_broadcast (&app->player.cond);
if (!app->player.doPause) {
tookAction = true;
app->player.doPause = true;
pthread_cond_broadcast (&app->player.cond);
}
pthread_mutex_unlock (&app->player.lock);
if (tookAction) {
BarUiActDefaultEventcmd("songpause");
}
}

/* toggle pause
*/
BarUiActCallback(BarUiActTogglePause) {
bool paused;
PianoReturn_t pRet = PIANO_RET_OK;;
CURLcode wRet = CURLE_OK;

pthread_mutex_lock (&app->player.lock);
app->player.doPause = !app->player.doPause;
paused = app->player.doPause;
pthread_cond_broadcast (&app->player.cond);
pthread_mutex_unlock (&app->player.lock);
BarUiActDefaultEventcmd(paused ? "songpause" : "songresume");
}

/* rename current station
Expand Down

0 comments on commit 2dcc03d

Please sign in to comment.