diff options
-rw-r--r-- | apps/playlist.c | 39 | ||||
-rw-r--r-- | apps/playlist.h | 4 | ||||
-rw-r--r-- | apps/tree.c | 19 |
3 files changed, 41 insertions, 21 deletions
diff --git a/apps/playlist.c b/apps/playlist.c index 27665981f7..0ac848c59c 100644 --- a/apps/playlist.c +++ b/apps/playlist.c @@ -168,12 +168,16 @@ char* playlist_next(int steps, int* index) /* * This function is called to start playback of a given playlist. This * playlist may be stored in RAM (when using full-dir playback). + * + * Return: the new index (possibly different due to shuffle) */ -void play_list(char *dir, /* "current directory" */ - char *file, /* playlist */ - int start_index, /* index in the playlist */ - int start_offset, /* offset in the file */ - int random_seed ) /* used for shuffling */ +int play_list(char *dir, /* "current directory" */ + char *file, /* playlist */ + int start_index, /* index in the playlist */ + bool shuffled_index, /* if TRUE the specified index is for the + playlist AFTER the shuffle */ + int start_offset, /* offset in the file */ + int random_seed ) /* used for shuffling */ { char *sep=""; int dirlen; @@ -235,19 +239,22 @@ void play_list(char *dir, /* "current directory" */ /* now shuffle around the indices */ randomise_playlist( random_seed ); - /* Because the playlists in RAM is always dir-based playlists, - we want the selected file played first so we scan the list - for that file to be able to play that one first. */ + if(!shuffled_index) { + /* The given index was for the unshuffled list, so we need + to figure out the index AFTER the shuffle has been made. + We scan for the seek position we remmber from before. */ - for(i=0; i< playlist.amount; i++) { - if(seek_pos == playlist.indices[i]) { - /* here's the start song! yiepee! */ - playlist.index = i; - break; /* now stop searching */ + for(i=0; i< playlist.amount; i++) { + if(seek_pos == playlist.indices[i]) { + /* here's the start song! yiepee! */ + playlist.index = i; + break; /* now stop searching */ + } } + /* if we for any reason wouldn't find the index again, it + won't set the index again and we should start at index 0 + instead */ } - /* if we for any reason wouldn't find the index again, it won't - set the index again and we should start at index 0 instead */ } } @@ -258,6 +265,8 @@ void play_list(char *dir, /* "current directory" */ } /* also make the first song get playing */ mpeg_play(start_offset); + + return playlist.index; } /* diff --git a/apps/playlist.h b/apps/playlist.h index e0c0841207..f44372e76d 100644 --- a/apps/playlist.h +++ b/apps/playlist.h @@ -40,8 +40,8 @@ typedef struct extern playlist_info_t playlist; extern bool playlist_shuffle; -void play_list(char *dir, char *file, int start_index, - int start_offset, int random_seed ); +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); void randomise_playlist( unsigned int seed ); void sort_playlist(void); diff --git a/apps/tree.c b/apps/tree.c index 90e978a0ab..7f0bf4362b 100644 --- a/apps/tree.c +++ b/apps/tree.c @@ -351,6 +351,7 @@ void start_resume(void) play_list(global_settings.resume_file, slash+1, global_settings.resume_index, + true, /* the index is AFTER shuffle */ global_settings.resume_offset, global_settings.resume_seed ); *slash='/'; @@ -368,6 +369,7 @@ void start_resume(void) play_list("/", global_settings.resume_file, global_settings.resume_index, + true, global_settings.resume_offset, global_settings.resume_seed ); } @@ -381,7 +383,8 @@ void start_resume(void) build_playlist(global_settings.resume_index); play_list(global_settings.resume_file, NULL, - global_settings.resume_index, + global_settings.resume_index, + true, global_settings.resume_offset, global_settings.resume_seed); } @@ -505,8 +508,10 @@ bool dirbrowse(char *root) currdir, dircache[dircursor+start].name); play_list(currdir, - dircache[dircursor+start].name, - 0, 0, seed ); + dircache[dircursor+start].name, + 0, + false, + 0, seed ); start_index = 0; } else { @@ -514,10 +519,16 @@ bool dirbrowse(char *root) strncpy(global_settings.resume_file, currdir, MAX_PATH); start_index = build_playlist(dircursor+start); - play_list(currdir, NULL, start_index, 0, seed); + + /* it is important that we get back the index in + the (shuffled) list and stor that */ + start_index = play_list(currdir, NULL, + start_index, false, 0, seed); } if ( global_settings.resume ) { + /* the resume_index must always be the index in the + shuffled list in case shuffle is enabled */ global_settings.resume_index = start_index; global_settings.resume_offset = 0; global_settings.resume_seed = seed; |