diff options
| author | Louis Burda <quent.burda@gmail.com> | 2021-12-16 18:32:50 +0100 |
|---|---|---|
| committer | Louis Burda <quent.burda@gmail.com> | 2021-12-20 15:32:22 +0100 |
| commit | 69e7a9341e811bf658f8d75bb43f6613d298c87d (patch) | |
| tree | 0fff59ab0bbc4a7af29079d611bf3cc4c2e8e2fd /player.c | |
| parent | 3eea7a245a7ed49127a222628543f9509a6ff2b6 (diff) | |
| download | tmus-69e7a9341e811bf658f8d75bb43f6613d298c87d.tar.gz tmus-69e7a9341e811bf658f8d75bb43f6613d298c87d.zip | |
Completion search into both directions, added delay to prevent pops when seeking, small refactor for readability
Diffstat (limited to 'player.c')
| -rw-r--r-- | player.c | 32 |
1 files changed, 30 insertions, 2 deletions
@@ -35,6 +35,8 @@ player_init(void) player->track = NULL; player->state = PLAYER_STATE_PAUSED; + player->seek_delay = 0; + player->volume = 0; player->time_pos = 0; player->time_end = 0; @@ -80,6 +82,12 @@ player_update(void) } player->volume = mpd_status_get_volume(status); + if (player->seek_delay) { + player->seek_delay -= 1; + if (!player->seek_delay) + player_play(); + } + song = mpd_run_current_song(player->conn); if (song) { player->loaded = true; @@ -181,6 +189,8 @@ player_resume(void) int player_next(void) { + if (!player->loaded) return PLAYER_ERR; + if (!mpd_run_next(player->conn)) { PLAYER_STATUS(PLAYER_MSG_ERR, "Playing next track failed"); mpd_run_clearerror(player->conn); @@ -193,6 +203,9 @@ player_next(void) int player_prev(void) { + /* TODO prevent mpd from dying on error, how to use properly */ + if (!player->loaded) return PLAYER_ERR; + if (!mpd_run_previous(player->conn)) { PLAYER_STATUS(PLAYER_MSG_ERR, "Playing prev track failed"); mpd_run_clearerror(player->conn); @@ -203,6 +216,18 @@ player_prev(void) } int +player_play(void) +{ + if (!mpd_run_play(player->conn)) { + PLAYER_STATUS(PLAYER_MSG_ERR, "Playing track failed"); + mpd_run_clearerror(player->conn); + return PLAYER_ERR; + } + + return PLAYER_OK; +} + +int player_stop(void) { if (!mpd_run_stop(player->conn)) { @@ -217,8 +242,8 @@ player_stop(void) int player_seek(int sec) { - if (player->state == PLAYER_STATE_STOPPED) { - PLAYER_STATUS(PLAYER_MSG_ERR, "Cannot seek stopped track"); + if (!player->loaded || player->state == PLAYER_STATE_STOPPED) { + PLAYER_STATUS(PLAYER_MSG_ERR, "No track loaded"); return PLAYER_ERR; } @@ -228,6 +253,9 @@ player_seek(int sec) return PLAYER_ERR; } + player->seek_delay = 8; + player_pause(); + return PLAYER_OK; } |
