playlist_control: use GTimer in previousSongInPlaylist()

To determine whether to rewind the current song or to go to the
previous song, use a GTimer instead of manually diffing time(NULL).
This commit is contained in:
Max Kellermann 2009-04-25 14:08:31 +02:00
parent d2010c0289
commit 616dc9d465
3 changed files with 15 additions and 6 deletions

View File

@ -61,12 +61,16 @@ playlist_init(struct playlist *playlist)
playlist->queued = -1; playlist->queued = -1;
playlist->current = -1; playlist->current = -1;
playlist->prev_elapsed = g_timer_new();
} }
void void
playlist_finish(struct playlist *playlist) playlist_finish(struct playlist *playlist)
{ {
queue_finish(&playlist->queue); queue_finish(&playlist->queue);
g_timer_destroy(playlist->prev_elapsed);
} }
/** /**

View File

@ -82,6 +82,13 @@ struct playlist {
* This variable is only valid if #playing is true. * This variable is only valid if #playing is true.
*/ */
int queued; int queued;
/**
* This timer tracks the time elapsed since the last "prev"
* command. If that is less than one second ago, "prev" jumps
* to the previous song instead of rewinding the current song.
*/
GTimer *prev_elapsed;
}; };
/** the global playlist object */ /** the global playlist object */

View File

@ -185,15 +185,11 @@ nextSongInPlaylist(struct playlist *playlist)
void previousSongInPlaylist(struct playlist *playlist) void previousSongInPlaylist(struct playlist *playlist)
{ {
static time_t lastTime;
time_t diff = time(NULL) - lastTime;
lastTime += diff;
if (!playlist->playing) if (!playlist->playing)
return; return;
if (diff && getPlayerElapsedTime() > PLAYLIST_PREV_UNLESS_ELAPSED) { if (g_timer_elapsed(playlist->prev_elapsed, NULL) >= 1.0 &&
getPlayerElapsedTime() > PLAYLIST_PREV_UNLESS_ELAPSED) {
/* re-start playing the current song (just like the /* re-start playing the current song (just like the
"prev" button on CD players) */ "prev" button on CD players) */
@ -213,6 +209,8 @@ void previousSongInPlaylist(struct playlist *playlist)
playPlaylistOrderNumber(playlist, playlist->current); playPlaylistOrderNumber(playlist, playlist->current);
} }
} }
g_timer_start(playlist->prev_elapsed);
} }
enum playlist_result enum playlist_result