summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/playlist.c39
-rw-r--r--apps/playlist.h2
-rw-r--r--apps/tree.c2
3 files changed, 24 insertions, 19 deletions
diff --git a/apps/playlist.c b/apps/playlist.c
index 4a2a6fdab2..2d8bbd3a33 100644
--- a/apps/playlist.c
+++ b/apps/playlist.c
@@ -33,14 +33,15 @@
33 33
34playlist_info_t playlist; 34playlist_info_t playlist;
35 35
36char now_playing[256]; 36char now_playing[MAX_PATH+1];
37 37
38char* playlist_next(int steps) 38char* playlist_next(int steps, char *dirname)
39{ 39{
40 int seek; 40 int seek;
41 int max; 41 int max;
42 int fd; 42 int fd;
43 int i; 43 int i;
44 char buf[MAX_PATH+1];
44 45
45 playlist.index = (playlist.index+steps) % playlist.amount; 46 playlist.index = (playlist.index+steps) % playlist.amount;
46 seek = playlist.indices[playlist.index]; 47 seek = playlist.indices[playlist.index];
@@ -48,36 +49,40 @@ char* playlist_next(int steps)
48 fd = open(playlist.filename, O_RDONLY); 49 fd = open(playlist.filename, O_RDONLY);
49 if(-1 != fd) { 50 if(-1 != fd) {
50 lseek(fd, seek, SEEK_SET); 51 lseek(fd, seek, SEEK_SET);
51 max = read(fd, now_playing+1, sizeof(now_playing)-1); 52 max = read(fd, buf, sizeof(buf)-1);
52 close(fd); 53 close(fd);
53 54
54 /* Zero-terminate the file name */ 55 /* Zero-terminate the file name */
55 seek=0; 56 seek=0;
56 while((now_playing[seek] != '\n') && 57 while((buf[seek] != '\n') &&
57 (now_playing[seek] != '\r') && 58 (buf[seek] != '\r') &&
58 (seek < max)) 59 (seek < max))
59 seek++; 60 seek++;
60 61
61 /* Now work back killing white space */ 62 /* Now work back killing white space */
62 while((now_playing[seek-1] == ' ') || 63 while((buf[seek-1] == ' ') ||
63 (now_playing[seek-1] == '\t')) 64 (buf[seek-1] == '\t'))
64 seek--; 65 seek--;
65 66
66 now_playing[seek]=0; 67 buf[seek]=0;
67 68
68 /* replace backslashes with forward slashes */ 69 /* replace backslashes with forward slashes */
69 for ( i=1; i<seek; i++ ) 70 for ( i=1; i<seek; i++ )
70 if ( now_playing[i] == '\\' ) 71 if ( buf[i] == '\\' )
71 now_playing[i] = '/'; 72 buf[i] = '/';
72 73
73 if('/' == now_playing[1]) 74 if('/' == buf[0]) {
74 return &now_playing[1]; 75 strcpy(now_playing, &buf[0]);
76 return now_playing;
77 }
75 else { 78 else {
76 /* handle dos style drive letter */ 79 /* handle dos style drive letter */
77 if ( ':' == now_playing[2] ) 80 if ( ':' == buf[1] ) {
78 return &now_playing[3]; 81 strcpy(now_playing, &buf[2]);
82 return now_playing;
83 }
79 else { 84 else {
80 now_playing[0]='/'; 85 snprintf(now_playing, MAX_PATH+1, "%s/%s", dirname, buf);
81 return now_playing; 86 return now_playing;
82 } 87 }
83 } 88 }
@@ -116,7 +121,7 @@ void play_list(char *dir, char *file)
116 lcd_puts(0,0,"Playing... "); 121 lcd_puts(0,0,"Playing... ");
117 lcd_update(); 122 lcd_update();
118 /* also make the first song get playing */ 123 /* also make the first song get playing */
119 mpeg_play(playlist_next(0)); 124 mpeg_play(playlist_next(0, dir));
120 sleep(HZ); 125 sleep(HZ);
121} 126}
122 127
@@ -172,7 +177,7 @@ void add_indices_to_playlist( playlist_info_t *playlist )
172 } 177 }
173 else if(store_index) 178 else if(store_index)
174 { 179 {
175 180
176 /* Store a new entry */ 181 /* Store a new entry */
177 playlist->indices[ playlist->amount ] = i+count; 182 playlist->indices[ playlist->amount ] = i+count;
178 playlist->amount++; 183 playlist->amount++;
diff --git a/apps/playlist.h b/apps/playlist.h
index 273a612da0..f352cb8422 100644
--- a/apps/playlist.h
+++ b/apps/playlist.h
@@ -38,7 +38,7 @@ extern playlist_info_t playlist;
38extern bool playlist_shuffle; 38extern bool playlist_shuffle;
39 39
40void play_list(char *dir, char *file); 40void play_list(char *dir, char *file);
41char* playlist_next(int steps); 41char* playlist_next(int steps, char *dirname);
42void randomise_playlist( playlist_info_t *playlist, unsigned int seed ); 42void randomise_playlist( playlist_info_t *playlist, unsigned int seed );
43void empty_playlist( playlist_info_t *playlist ); 43void empty_playlist( playlist_info_t *playlist );
44void add_indices_to_playlist( playlist_info_t *playlist ); 44void add_indices_to_playlist( playlist_info_t *playlist );
diff --git a/apps/tree.c b/apps/tree.c
index 0d583a7a6e..0e56a2c177 100644
--- a/apps/tree.c
+++ b/apps/tree.c
@@ -245,7 +245,7 @@ char* peek_next_track(int steps)
245 245
246 case 2: 246 case 2:
247 /* playlist mode */ 247 /* playlist mode */
248 return playlist_next(steps); 248 return playlist_next(steps, currdir);
249 } 249 }
250 250
251 return NULL; 251 return NULL;