diff options
-rw-r--r-- | apps/misc.c | 2 | ||||
-rw-r--r-- | apps/playback.c | 2 | ||||
-rw-r--r-- | apps/scrobbler.c | 30 | ||||
-rw-r--r-- | apps/scrobbler.h | 1 | ||||
-rw-r--r-- | firmware/mpeg.c | 5 |
5 files changed, 32 insertions, 8 deletions
diff --git a/apps/misc.c b/apps/misc.c index 6187cf425b..08e699e781 100644 --- a/apps/misc.c +++ b/apps/misc.c | |||
@@ -605,6 +605,8 @@ static bool clean_shutdown(void (*callback)(void *), void *parameter) | |||
605 | #else | 605 | #else |
606 | int i; | 606 | int i; |
607 | 607 | ||
608 | scrobbler_poweroff(); | ||
609 | |||
608 | #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING) | 610 | #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING) |
609 | if(!charger_inserted()) | 611 | if(!charger_inserted()) |
610 | #endif | 612 | #endif |
diff --git a/apps/playback.c b/apps/playback.c index 329e8b856b..6b4b37170d 100644 --- a/apps/playback.c +++ b/apps/playback.c | |||
@@ -3271,6 +3271,8 @@ static void audio_stop_playback(void) | |||
3271 | /* Save the current playing spot, or NULL if the playlist has ended */ | 3271 | /* Save the current playing spot, or NULL if the playlist has ended */ |
3272 | playlist_update_resume_info(id3); | 3272 | playlist_update_resume_info(id3); |
3273 | 3273 | ||
3274 | prev_track_elapsed = CUR_TI->id3.elapsed; | ||
3275 | |||
3274 | /* Increment index so runtime info is saved in audio_clear_track_entries(). | 3276 | /* Increment index so runtime info is saved in audio_clear_track_entries(). |
3275 | * Done here, as audio_stop_playback() may be called more than once. | 3277 | * Done here, as audio_stop_playback() may be called more than once. |
3276 | * Don't update runtime unless playback is stopped because of end of playlist. | 3278 | * Don't update runtime unless playback is stopped because of end of playlist. |
diff --git a/apps/scrobbler.c b/apps/scrobbler.c index 07ba016a51..01c704afab 100644 --- a/apps/scrobbler.c +++ b/apps/scrobbler.c | |||
@@ -139,7 +139,7 @@ static bool scrobbler_flush_callback(void) | |||
139 | return true; | 139 | return true; |
140 | } | 140 | } |
141 | 141 | ||
142 | static void add_to_cache(void) | 142 | static void add_to_cache(unsigned long play_length) |
143 | { | 143 | { |
144 | if ( cache_pos >= SCROBBLER_MAX_CACHE ) | 144 | if ( cache_pos >= SCROBBLER_MAX_CACHE ) |
145 | write_cache(); | 145 | write_cache(); |
@@ -149,8 +149,7 @@ static void add_to_cache(void) | |||
149 | 149 | ||
150 | logf("SCROBBLER: add_to_cache[%d]", cache_pos); | 150 | logf("SCROBBLER: add_to_cache[%d]", cache_pos); |
151 | 151 | ||
152 | if ( audio_prev_elapsed() > | 152 | if ( play_length > (scrobbler_entry.length/2) ) |
153 | (scrobbler_entry.length/2) ) | ||
154 | rating = 'L'; /* Listened */ | 153 | rating = 'L'; /* Listened */ |
155 | 154 | ||
156 | if (scrobbler_entry.tracknum > 0) | 155 | if (scrobbler_entry.tracknum > 0) |
@@ -193,7 +192,7 @@ void scrobbler_change_event(struct mp3entry *id) | |||
193 | { | 192 | { |
194 | /* add entry using the previous scrobbler_entry and timestamp */ | 193 | /* add entry using the previous scrobbler_entry and timestamp */ |
195 | if (pending) | 194 | if (pending) |
196 | add_to_cache(); | 195 | add_to_cache(audio_prev_elapsed()); |
197 | 196 | ||
198 | /* check if track was resumed > %50 played | 197 | /* check if track was resumed > %50 played |
199 | check for blank artist or track name */ | 198 | check for blank artist or track name */ |
@@ -219,7 +218,7 @@ void scrobbler_change_event(struct mp3entry *id) | |||
219 | int scrobbler_init(void) | 218 | int scrobbler_init(void) |
220 | { | 219 | { |
221 | logf("SCROBBLER: init %d", global_settings.audioscrobbler); | 220 | logf("SCROBBLER: init %d", global_settings.audioscrobbler); |
222 | 221 | ||
223 | if(!global_settings.audioscrobbler) | 222 | if(!global_settings.audioscrobbler) |
224 | return -1; | 223 | return -1; |
225 | 224 | ||
@@ -239,8 +238,8 @@ void scrobbler_flush_cache(void) | |||
239 | { | 238 | { |
240 | /* Add any pending entries to the cache */ | 239 | /* Add any pending entries to the cache */ |
241 | if(pending) | 240 | if(pending) |
242 | add_to_cache(); | 241 | add_to_cache(audio_prev_elapsed()); |
243 | 242 | ||
244 | /* Write the cache to disk if needed */ | 243 | /* Write the cache to disk if needed */ |
245 | if (cache_pos) | 244 | if (cache_pos) |
246 | write_cache(); | 245 | write_cache(); |
@@ -257,7 +256,7 @@ void scrobbler_shutdown(void) | |||
257 | #endif | 256 | #endif |
258 | 257 | ||
259 | scrobbler_flush_cache(); | 258 | scrobbler_flush_cache(); |
260 | 259 | ||
261 | if (scrobbler_initialised) | 260 | if (scrobbler_initialised) |
262 | { | 261 | { |
263 | audio_set_track_changed_event(NULL); | 262 | audio_set_track_changed_event(NULL); |
@@ -265,6 +264,21 @@ void scrobbler_shutdown(void) | |||
265 | } | 264 | } |
266 | } | 265 | } |
267 | 266 | ||
267 | void scrobbler_poweroff(void) | ||
268 | { | ||
269 | if (scrobbler_initialised && pending) | ||
270 | { | ||
271 | if ( audio_status() ) | ||
272 | add_to_cache(audio_current_track()->elapsed); | ||
273 | else | ||
274 | add_to_cache(audio_prev_elapsed()); | ||
275 | |||
276 | /* scrobbler_shutdown is called later, the cache will be written | ||
277 | * make sure the final track isn't added twice when that happens */ | ||
278 | pending = false; | ||
279 | } | ||
280 | } | ||
281 | |||
268 | bool scrobbler_is_enabled(void) | 282 | bool scrobbler_is_enabled(void) |
269 | { | 283 | { |
270 | return scrobbler_initialised; | 284 | return scrobbler_initialised; |
diff --git a/apps/scrobbler.h b/apps/scrobbler.h index 543a30ed13..6879075cce 100644 --- a/apps/scrobbler.h +++ b/apps/scrobbler.h | |||
@@ -21,4 +21,5 @@ void scrobbler_change_event(struct mp3entry *id); | |||
21 | int scrobbler_init(void); | 21 | int scrobbler_init(void); |
22 | void scrobbler_flush_cache(void); | 22 | void scrobbler_flush_cache(void); |
23 | void scrobbler_shutdown(void); | 23 | void scrobbler_shutdown(void); |
24 | void scrobbler_poweroff(void); | ||
24 | bool scrobbler_is_enabled(void); | 25 | bool scrobbler_is_enabled(void); |
diff --git a/firmware/mpeg.c b/firmware/mpeg.c index 0299d4d557..4ba3f7ead7 100644 --- a/firmware/mpeg.c +++ b/firmware/mpeg.c | |||
@@ -2727,6 +2727,11 @@ void audio_play(long offset) | |||
2727 | void audio_stop(void) | 2727 | void audio_stop(void) |
2728 | { | 2728 | { |
2729 | #ifndef SIMULATOR | 2729 | #ifndef SIMULATOR |
2730 | if (playing) | ||
2731 | { | ||
2732 | struct trackdata *track = get_trackdata(0); | ||
2733 | prev_track_elapsed = track->id3.elapsed; | ||
2734 | } | ||
2730 | mpeg_stop_done = false; | 2735 | mpeg_stop_done = false; |
2731 | queue_post(&mpeg_queue, MPEG_STOP, 0); | 2736 | queue_post(&mpeg_queue, MPEG_STOP, 0); |
2732 | while(!mpeg_stop_done) | 2737 | while(!mpeg_stop_done) |