diff --git a/apps/playlist.c b/apps/playlist.c index 0052672e25..3dbbc9ea2d 100644 --- a/apps/playlist.c +++ b/apps/playlist.c @@ -64,7 +64,19 @@ int playlist_add(char *filename) return 0; } -char* playlist_next(int steps, int* index) +int playlist_next(int steps) +{ + playlist.index = (playlist.index+steps) % playlist.amount; + while ( playlist.index < 0 ) { + if ( global_settings.loop_playlist ) + playlist.index += playlist.amount; + else + playlist.index = 0; + } + return playlist.index; +} + +char* playlist_peek(int steps) { int seek; int max; @@ -73,19 +85,20 @@ char* playlist_next(int steps, int* index) char *buf; char dir_buf[MAX_PATH+1]; char *dir_end; + int index; if(abs(steps) > playlist.amount) /* prevent madness when all files are empty/bad */ return NULL; - playlist.index = (playlist.index+steps) % playlist.amount; - while ( playlist.index < 0 ) { + index = (playlist.index+steps) % playlist.amount; + while ( index < 0 ) { if ( global_settings.loop_playlist ) - playlist.index += playlist.amount; + index += playlist.amount; else - playlist.index = 0; + index = 0; } - seek = playlist.indices[playlist.index]; + seek = playlist.indices[index]; if(playlist.in_ram) { @@ -106,9 +119,6 @@ char* playlist_next(int steps, int* index) return NULL; } - if (index) - *index = playlist.index; - /* Zero-terminate the file name */ seek=0; while((buf[seek] != '\n') && diff --git a/apps/playlist.h b/apps/playlist.h index 5abeec3176..a18240db7f 100644 --- a/apps/playlist.h +++ b/apps/playlist.h @@ -42,7 +42,8 @@ extern bool playlist_shuffle; int play_list(char *dir, char *file, int start_index, bool shuffled_index, int start_offset, int random_seed ); -char* playlist_next(int steps, int* id); +char* playlist_peek(int steps); +int playlist_next(int steps); void randomise_playlist( unsigned int seed ); void sort_playlist(bool start_current); void empty_playlist(void);