diff options
-rw-r--r-- | apps/playlist.c | 33 | ||||
-rw-r--r-- | apps/playlist.h | 1 |
2 files changed, 17 insertions, 17 deletions
diff --git a/apps/playlist.c b/apps/playlist.c index ebe82cc457..4a06606509 100644 --- a/apps/playlist.c +++ b/apps/playlist.c | |||
@@ -58,6 +58,10 @@ static void empty_playlist(bool queue_resume) | |||
58 | int fd; | 58 | int fd; |
59 | 59 | ||
60 | playlist.filename[0] = '\0'; | 60 | playlist.filename[0] = '\0'; |
61 | if(-1 != playlist.fd) | ||
62 | /* If there is an already open playlist, close it. */ | ||
63 | close(playlist.fd); | ||
64 | playlist.fd = -1; | ||
61 | playlist.index = 0; | 65 | playlist.index = 0; |
62 | playlist.queue_index = 0; | 66 | playlist.queue_index = 0; |
63 | playlist.last_queue_index = 0; | 67 | playlist.last_queue_index = 0; |
@@ -390,8 +394,8 @@ char* playlist_peek(int steps) | |||
390 | { | 394 | { |
391 | int seek; | 395 | int seek; |
392 | int max; | 396 | int max; |
393 | int fd; | ||
394 | int i; | 397 | int i; |
398 | int fd; | ||
395 | char *buf; | 399 | char *buf; |
396 | char dir_buf[MAX_PATH+1]; | 400 | char dir_buf[MAX_PATH+1]; |
397 | char *dir_end; | 401 | char *dir_end; |
@@ -427,13 +431,14 @@ char* playlist_peek(int steps) | |||
427 | } | 431 | } |
428 | else | 432 | else |
429 | { | 433 | { |
430 | fd = open(playlist.filename, O_RDONLY); | 434 | if(-1 == playlist.fd) |
431 | if(-1 != fd) | 435 | playlist.fd = open(playlist.filename, O_RDONLY); |
436 | |||
437 | if(-1 != playlist.fd) | ||
432 | { | 438 | { |
433 | buf = playlist_buffer; | 439 | buf = playlist_buffer; |
434 | lseek(fd, seek, SEEK_SET); | 440 | lseek(playlist.fd, seek, SEEK_SET); |
435 | max = read(fd, buf, MAX_PATH); | 441 | max = read(playlist.fd, buf, MAX_PATH); |
436 | close(fd); | ||
437 | } | 442 | } |
438 | else | 443 | else |
439 | return NULL; | 444 | return NULL; |
@@ -642,7 +647,6 @@ int play_list(char *dir, /* "current directory" */ | |||
642 | void add_indices_to_playlist(void) | 647 | void add_indices_to_playlist(void) |
643 | { | 648 | { |
644 | int nread; | 649 | int nread; |
645 | int fd = -1; | ||
646 | int i = 0; | 650 | int i = 0; |
647 | int count = 0; | 651 | int count = 0; |
648 | unsigned char* buffer = playlist_buffer; | 652 | unsigned char* buffer = playlist_buffer; |
@@ -651,10 +655,11 @@ void add_indices_to_playlist(void) | |||
651 | unsigned char *p; | 655 | unsigned char *p; |
652 | 656 | ||
653 | if(!playlist.in_ram) { | 657 | if(!playlist.in_ram) { |
654 | fd = open(playlist.filename, O_RDONLY); | 658 | if(-1 == playlist.fd) |
655 | if(-1 == fd) | 659 | playlist.fd = open(playlist.filename, O_RDONLY); |
660 | if(-1 == playlist.fd) | ||
656 | return; /* failure */ | 661 | return; /* failure */ |
657 | 662 | ||
658 | #ifndef SIMULATOR | 663 | #ifndef SIMULATOR |
659 | /* use mp3 buffer for maximum load speed */ | 664 | /* use mp3 buffer for maximum load speed */ |
660 | buflen = (&mp3end - &mp3buf[0]); | 665 | buflen = (&mp3end - &mp3buf[0]); |
@@ -671,7 +676,7 @@ void add_indices_to_playlist(void) | |||
671 | if(playlist.in_ram) { | 676 | if(playlist.in_ram) { |
672 | nread = playlist_end_pos; | 677 | nread = playlist_end_pos; |
673 | } else { | 678 | } else { |
674 | nread = read(fd, buffer, buflen); | 679 | nread = read(playlist.fd, buffer, buflen); |
675 | /* Terminate on EOF */ | 680 | /* Terminate on EOF */ |
676 | if(nread <= 0) | 681 | if(nread <= 0) |
677 | break; | 682 | break; |
@@ -696,9 +701,6 @@ void add_indices_to_playlist(void) | |||
696 | playlist.indices[ playlist.amount ] = i+count; | 701 | playlist.indices[ playlist.amount ] = i+count; |
697 | playlist.amount++; | 702 | playlist.amount++; |
698 | if ( playlist.amount >= MAX_PLAYLIST_SIZE ) { | 703 | if ( playlist.amount >= MAX_PLAYLIST_SIZE ) { |
699 | if(!playlist.in_ram) | ||
700 | close(fd); | ||
701 | |||
702 | lcd_clear_display(); | 704 | lcd_clear_display(); |
703 | lcd_puts(0,0,str(LANG_PLAYINDICES_PLAYLIST)); | 705 | lcd_puts(0,0,str(LANG_PLAYINDICES_PLAYLIST)); |
704 | lcd_puts(0,1,str(LANG_PLAYINDICES_BUFFER)); | 706 | lcd_puts(0,1,str(LANG_PLAYINDICES_BUFFER)); |
@@ -717,9 +719,6 @@ void add_indices_to_playlist(void) | |||
717 | if(playlist.in_ram) | 719 | if(playlist.in_ram) |
718 | break; | 720 | break; |
719 | } | 721 | } |
720 | |||
721 | if(!playlist.in_ram) | ||
722 | close(fd); | ||
723 | } | 722 | } |
724 | 723 | ||
725 | /* | 724 | /* |
diff --git a/apps/playlist.h b/apps/playlist.h index ea77886bb7..9f70b469af 100644 --- a/apps/playlist.h +++ b/apps/playlist.h | |||
@@ -29,6 +29,7 @@ | |||
29 | struct playlist_info | 29 | struct playlist_info |
30 | { | 30 | { |
31 | char filename[MAX_PATH]; /* path name of m3u playlist on disk */ | 31 | char filename[MAX_PATH]; /* path name of m3u playlist on disk */ |
32 | int fd; /* file descriptor of the open playlist */ | ||
32 | int dirlen; /* Length of the path to the playlist file */ | 33 | int dirlen; /* Length of the path to the playlist file */ |
33 | int indices[MAX_PLAYLIST_SIZE]; /* array of indices */ | 34 | int indices[MAX_PLAYLIST_SIZE]; /* array of indices */ |
34 | int index; /* index of current playing track */ | 35 | int index; /* index of current playing track */ |