diff options
author | Lars-Dominik Braun <PromyLOPh@lavabit.com> | 2009-06-15 18:25:25 +0200 |
---|---|---|
committer | Lars-Dominik Braun <PromyLOPh@lavabit.com> | 2009-06-15 18:25:25 +0200 |
commit | 5653b88ebe36635ea7ad6a4a525b6b86f90ca82a (patch) | |
tree | 14f80046ae5ef53ee362c4bb76f45ead6ba07680 /src | |
parent | a6c521fecd91867c6e184106f4e63445d1cb158a (diff) | |
download | pianobar-windows-5653b88ebe36635ea7ad6a4a525b6b86f90ca82a.tar.gz pianobar-windows-5653b88ebe36635ea7ad6a4a525b6b86f90ca82a.tar.bz2 pianobar-windows-5653b88ebe36635ea7ad6a4a525b6b86f90ca82a.zip |
Fix negative time display
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 20 |
1 files changed, 14 insertions, 6 deletions
@@ -282,12 +282,20 @@ int main (int argc, char **argv) { /* show time */ if (player.mode >= PLAYER_SAMPLESIZE_INITIALIZED && player.mode < PLAYER_FINISHED_PLAYBACK) { - long int songRemaining = player.songDuration - player.songPlayed; - BarUiMsg (MSG_TIME, "-%02i:%02i/%02i:%02i\r", - (int) songRemaining / BAR_PLAYER_MS_TO_S_FACTOR / 60, - (int) songRemaining / BAR_PLAYER_MS_TO_S_FACTOR % 60, - (int) player.songDuration / BAR_PLAYER_MS_TO_S_FACTOR / 60, - (int) player.songDuration / BAR_PLAYER_MS_TO_S_FACTOR % 60); + /* Ugly: songDuration is unsigned _long_ int! Lets hope this won't + * overflow */ + int songRemaining = (signed long int) (player.songDuration - player.songPlayed) + / BAR_PLAYER_MS_TO_S_FACTOR; + char pos = 0; + if (songRemaining < 0) { + /* Use plus sign if song is longer than expected */ + pos = 1; + songRemaining = -songRemaining; + } + BarUiMsg (MSG_TIME, "%c%02i:%02i/%02i:%02i\r", (pos ? '+' : '-'), + songRemaining / 60, songRemaining % 60, + player.songDuration / BAR_PLAYER_MS_TO_S_FACTOR / 60, + player.songDuration / BAR_PLAYER_MS_TO_S_FACTOR % 60); } } |