summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorPeter D'Hoye <peter.dhoye@gmail.com>2007-06-24 18:46:04 +0000
committerPeter D'Hoye <peter.dhoye@gmail.com>2007-06-24 18:46:04 +0000
commit12d2d0fbc22391b5f4a8d86965382ae58d38ef04 (patch)
tree698d973635977baecd5a3fda6f48e801c99c0ac1 /apps
parent78c45530fff6100240d08be77858350632000de9 (diff)
downloadrockbox-12d2d0fbc22391b5f4a8d86965382ae58d38ef04.zip
rockbox-12d2d0fbc22391b5f4a8d86965382ae58d38ef04.tar.gz
rockbox-12d2d0fbc22391b5f4a8d86965382ae58d38ef04.tar.bz2
rockbox-12d2d0fbc22391b5f4a8d86965382ae58d38ef04.tar.xz
A patch by Robert Keevil that's been in the tracker way to long, fixes FS #6213: Audioscrobbler incorrectly submits last song
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13699 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r--apps/misc.c2
-rw-r--r--apps/playback.c2
-rw-r--r--apps/scrobbler.c30
-rw-r--r--apps/scrobbler.h1
4 files changed, 27 insertions, 8 deletions
diff --git a/apps/misc.c b/apps/misc.c
index 6187cf4..08e699e 100644
--- a/apps/misc.c
+++ b/apps/misc.c
@@ -605,6 +605,8 @@ static bool clean_shutdown(void (*callback)(void *), void *parameter)
#else
int i;
+ scrobbler_poweroff();
+
#if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING)
if(!charger_inserted())
#endif
diff --git a/apps/playback.c b/apps/playback.c
index 329e8b8..6b4b371 100644
--- a/apps/playback.c
+++ b/apps/playback.c
@@ -3271,6 +3271,8 @@ static void audio_stop_playback(void)
/* Save the current playing spot, or NULL if the playlist has ended */
playlist_update_resume_info(id3);
+ prev_track_elapsed = CUR_TI->id3.elapsed;
+
/* Increment index so runtime info is saved in audio_clear_track_entries().
* Done here, as audio_stop_playback() may be called more than once.
* Don't update runtime unless playback is stopped because of end of playlist.
diff --git a/apps/scrobbler.c b/apps/scrobbler.c
index 07ba016..01c704a 100644
--- a/apps/scrobbler.c
+++ b/apps/scrobbler.c
@@ -139,7 +139,7 @@ static bool scrobbler_flush_callback(void)
return true;
}
-static void add_to_cache(void)
+static void add_to_cache(unsigned long play_length)
{
if ( cache_pos >= SCROBBLER_MAX_CACHE )
write_cache();
@@ -149,8 +149,7 @@ static void add_to_cache(void)
logf("SCROBBLER: add_to_cache[%d]", cache_pos);
- if ( audio_prev_elapsed() >
- (scrobbler_entry.length/2) )
+ if ( play_length > (scrobbler_entry.length/2) )
rating = 'L'; /* Listened */
if (scrobbler_entry.tracknum > 0)
@@ -193,7 +192,7 @@ void scrobbler_change_event(struct mp3entry *id)
{
/* add entry using the previous scrobbler_entry and timestamp */
if (pending)
- add_to_cache();
+ add_to_cache(audio_prev_elapsed());
/* check if track was resumed > %50 played
check for blank artist or track name */
@@ -219,7 +218,7 @@ void scrobbler_change_event(struct mp3entry *id)
int scrobbler_init(void)
{
logf("SCROBBLER: init %d", global_settings.audioscrobbler);
-
+
if(!global_settings.audioscrobbler)
return -1;
@@ -239,8 +238,8 @@ void scrobbler_flush_cache(void)
{
/* Add any pending entries to the cache */
if(pending)
- add_to_cache();
-
+ add_to_cache(audio_prev_elapsed());
+
/* Write the cache to disk if needed */
if (cache_pos)
write_cache();
@@ -257,7 +256,7 @@ void scrobbler_shutdown(void)
#endif
scrobbler_flush_cache();
-
+
if (scrobbler_initialised)
{
audio_set_track_changed_event(NULL);
@@ -265,6 +264,21 @@ void scrobbler_shutdown(void)
}
}
+void scrobbler_poweroff(void)
+{
+ if (scrobbler_initialised && pending)
+ {
+ if ( audio_status() )
+ add_to_cache(audio_current_track()->elapsed);
+ else
+ add_to_cache(audio_prev_elapsed());
+
+ /* scrobbler_shutdown is called later, the cache will be written
+ * make sure the final track isn't added twice when that happens */
+ pending = false;
+ }
+}
+
bool scrobbler_is_enabled(void)
{
return scrobbler_initialised;
diff --git a/apps/scrobbler.h b/apps/scrobbler.h
index 543a30e..6879075 100644
--- a/apps/scrobbler.h
+++ b/apps/scrobbler.h
@@ -21,4 +21,5 @@ void scrobbler_change_event(struct mp3entry *id);
int scrobbler_init(void);
void scrobbler_flush_cache(void);
void scrobbler_shutdown(void);
+void scrobbler_poweroff(void);
bool scrobbler_is_enabled(void);