diff options
Diffstat (limited to 'apps')
-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) | |||
168 | /* | 168 | /* |
169 | * This function is called to start playback of a given playlist. This | 169 | * This function is called to start playback of a given playlist. This |
170 | * playlist may be stored in RAM (when using full-dir playback). | 170 | * playlist may be stored in RAM (when using full-dir playback). |
171 | * | ||
172 | * Return: the new index (possibly different due to shuffle) | ||
171 | */ | 173 | */ |
172 | void play_list(char *dir, /* "current directory" */ | 174 | int play_list(char *dir, /* "current directory" */ |
173 | char *file, /* playlist */ | 175 | char *file, /* playlist */ |
174 | int start_index, /* index in the playlist */ | 176 | int start_index, /* index in the playlist */ |
175 | int start_offset, /* offset in the file */ | 177 | bool shuffled_index, /* if TRUE the specified index is for the |
176 | int random_seed ) /* used for shuffling */ | 178 | playlist AFTER the shuffle */ |
179 | int start_offset, /* offset in the file */ | ||
180 | int random_seed ) /* used for shuffling */ | ||
177 | { | 181 | { |
178 | char *sep=""; | 182 | char *sep=""; |
179 | int dirlen; | 183 | int dirlen; |
@@ -235,19 +239,22 @@ void play_list(char *dir, /* "current directory" */ | |||
235 | /* now shuffle around the indices */ | 239 | /* now shuffle around the indices */ |
236 | randomise_playlist( random_seed ); | 240 | randomise_playlist( random_seed ); |
237 | 241 | ||
238 | /* Because the playlists in RAM is always dir-based playlists, | 242 | if(!shuffled_index) { |
239 | we want the selected file played first so we scan the list | 243 | /* The given index was for the unshuffled list, so we need |
240 | for that file to be able to play that one first. */ | 244 | to figure out the index AFTER the shuffle has been made. |
245 | We scan for the seek position we remmber from before. */ | ||
241 | 246 | ||
242 | for(i=0; i< playlist.amount; i++) { | 247 | for(i=0; i< playlist.amount; i++) { |
243 | if(seek_pos == playlist.indices[i]) { | 248 | if(seek_pos == playlist.indices[i]) { |
244 | /* here's the start song! yiepee! */ | 249 | /* here's the start song! yiepee! */ |
245 | playlist.index = i; | 250 | playlist.index = i; |
246 | break; /* now stop searching */ | 251 | break; /* now stop searching */ |
252 | } | ||
247 | } | 253 | } |
254 | /* if we for any reason wouldn't find the index again, it | ||
255 | won't set the index again and we should start at index 0 | ||
256 | instead */ | ||
248 | } | 257 | } |
249 | /* if we for any reason wouldn't find the index again, it won't | ||
250 | set the index again and we should start at index 0 instead */ | ||
251 | } | 258 | } |
252 | } | 259 | } |
253 | 260 | ||
@@ -258,6 +265,8 @@ void play_list(char *dir, /* "current directory" */ | |||
258 | } | 265 | } |
259 | /* also make the first song get playing */ | 266 | /* also make the first song get playing */ |
260 | mpeg_play(start_offset); | 267 | mpeg_play(start_offset); |
268 | |||
269 | return playlist.index; | ||
261 | } | 270 | } |
262 | 271 | ||
263 | /* | 272 | /* |
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 | |||
40 | extern playlist_info_t playlist; | 40 | extern playlist_info_t playlist; |
41 | extern bool playlist_shuffle; | 41 | extern bool playlist_shuffle; |
42 | 42 | ||
43 | void play_list(char *dir, char *file, int start_index, | 43 | int play_list(char *dir, char *file, int start_index, |
44 | int start_offset, int random_seed ); | 44 | bool shuffled_index, int start_offset, int random_seed ); |
45 | char* playlist_next(int steps, int* id); | 45 | char* playlist_next(int steps, int* id); |
46 | void randomise_playlist( unsigned int seed ); | 46 | void randomise_playlist( unsigned int seed ); |
47 | void sort_playlist(void); | 47 | 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) | |||
351 | play_list(global_settings.resume_file, | 351 | play_list(global_settings.resume_file, |
352 | slash+1, | 352 | slash+1, |
353 | global_settings.resume_index, | 353 | global_settings.resume_index, |
354 | true, /* the index is AFTER shuffle */ | ||
354 | global_settings.resume_offset, | 355 | global_settings.resume_offset, |
355 | global_settings.resume_seed ); | 356 | global_settings.resume_seed ); |
356 | *slash='/'; | 357 | *slash='/'; |
@@ -368,6 +369,7 @@ void start_resume(void) | |||
368 | play_list("/", | 369 | play_list("/", |
369 | global_settings.resume_file, | 370 | global_settings.resume_file, |
370 | global_settings.resume_index, | 371 | global_settings.resume_index, |
372 | true, | ||
371 | global_settings.resume_offset, | 373 | global_settings.resume_offset, |
372 | global_settings.resume_seed ); | 374 | global_settings.resume_seed ); |
373 | } | 375 | } |
@@ -381,7 +383,8 @@ void start_resume(void) | |||
381 | build_playlist(global_settings.resume_index); | 383 | build_playlist(global_settings.resume_index); |
382 | play_list(global_settings.resume_file, | 384 | play_list(global_settings.resume_file, |
383 | NULL, | 385 | NULL, |
384 | global_settings.resume_index, | 386 | global_settings.resume_index, |
387 | true, | ||
385 | global_settings.resume_offset, | 388 | global_settings.resume_offset, |
386 | global_settings.resume_seed); | 389 | global_settings.resume_seed); |
387 | } | 390 | } |
@@ -505,8 +508,10 @@ bool dirbrowse(char *root) | |||
505 | currdir, | 508 | currdir, |
506 | dircache[dircursor+start].name); | 509 | dircache[dircursor+start].name); |
507 | play_list(currdir, | 510 | play_list(currdir, |
508 | dircache[dircursor+start].name, | 511 | dircache[dircursor+start].name, |
509 | 0, 0, seed ); | 512 | 0, |
513 | false, | ||
514 | 0, seed ); | ||
510 | start_index = 0; | 515 | start_index = 0; |
511 | } | 516 | } |
512 | else { | 517 | else { |
@@ -514,10 +519,16 @@ bool dirbrowse(char *root) | |||
514 | strncpy(global_settings.resume_file, | 519 | strncpy(global_settings.resume_file, |
515 | currdir, MAX_PATH); | 520 | currdir, MAX_PATH); |
516 | start_index = build_playlist(dircursor+start); | 521 | start_index = build_playlist(dircursor+start); |
517 | play_list(currdir, NULL, start_index, 0, seed); | 522 | |
523 | /* it is important that we get back the index in | ||
524 | the (shuffled) list and stor that */ | ||
525 | start_index = play_list(currdir, NULL, | ||
526 | start_index, false, 0, seed); | ||
518 | } | 527 | } |
519 | 528 | ||
520 | if ( global_settings.resume ) { | 529 | if ( global_settings.resume ) { |
530 | /* the resume_index must always be the index in the | ||
531 | shuffled list in case shuffle is enabled */ | ||
521 | global_settings.resume_index = start_index; | 532 | global_settings.resume_index = start_index; |
522 | global_settings.resume_offset = 0; | 533 | global_settings.resume_offset = 0; |
523 | global_settings.resume_seed = seed; | 534 | global_settings.resume_seed = seed; |