summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars-Dominik Braun <PromyLOPh@lavabit.com>2009-06-15 18:25:25 +0200
committerLars-Dominik Braun <PromyLOPh@lavabit.com>2009-06-15 18:25:25 +0200
commit5653b88ebe36635ea7ad6a4a525b6b86f90ca82a (patch)
tree14f80046ae5ef53ee362c4bb76f45ead6ba07680
parenta6c521fecd91867c6e184106f4e63445d1cb158a (diff)
downloadpianobar-5653b88ebe36635ea7ad6a4a525b6b86f90ca82a.tar.gz
pianobar-5653b88ebe36635ea7ad6a4a525b6b86f90ca82a.tar.bz2
pianobar-5653b88ebe36635ea7ad6a4a525b6b86f90ca82a.zip
Fix negative time display
-rw-r--r--src/main.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/main.c b/src/main.c
index 8965bb9..58007d8 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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);
}
}