forked from len0rd/rockbox
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
This commit is contained in:
parent
78c45530ff
commit
12d2d0fbc2
5 changed files with 32 additions and 8 deletions
|
|
@ -605,6 +605,8 @@ static bool clean_shutdown(void (*callback)(void *), void *parameter)
|
||||||
#else
|
#else
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
scrobbler_poweroff();
|
||||||
|
|
||||||
#if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING)
|
#if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING)
|
||||||
if(!charger_inserted())
|
if(!charger_inserted())
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -3271,6 +3271,8 @@ static void audio_stop_playback(void)
|
||||||
/* Save the current playing spot, or NULL if the playlist has ended */
|
/* Save the current playing spot, or NULL if the playlist has ended */
|
||||||
playlist_update_resume_info(id3);
|
playlist_update_resume_info(id3);
|
||||||
|
|
||||||
|
prev_track_elapsed = CUR_TI->id3.elapsed;
|
||||||
|
|
||||||
/* Increment index so runtime info is saved in audio_clear_track_entries().
|
/* Increment index so runtime info is saved in audio_clear_track_entries().
|
||||||
* Done here, as audio_stop_playback() may be called more than once.
|
* 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.
|
* Don't update runtime unless playback is stopped because of end of playlist.
|
||||||
|
|
|
||||||
|
|
@ -139,7 +139,7 @@ static bool scrobbler_flush_callback(void)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void add_to_cache(void)
|
static void add_to_cache(unsigned long play_length)
|
||||||
{
|
{
|
||||||
if ( cache_pos >= SCROBBLER_MAX_CACHE )
|
if ( cache_pos >= SCROBBLER_MAX_CACHE )
|
||||||
write_cache();
|
write_cache();
|
||||||
|
|
@ -149,8 +149,7 @@ static void add_to_cache(void)
|
||||||
|
|
||||||
logf("SCROBBLER: add_to_cache[%d]", cache_pos);
|
logf("SCROBBLER: add_to_cache[%d]", cache_pos);
|
||||||
|
|
||||||
if ( audio_prev_elapsed() >
|
if ( play_length > (scrobbler_entry.length/2) )
|
||||||
(scrobbler_entry.length/2) )
|
|
||||||
rating = 'L'; /* Listened */
|
rating = 'L'; /* Listened */
|
||||||
|
|
||||||
if (scrobbler_entry.tracknum > 0)
|
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 */
|
/* add entry using the previous scrobbler_entry and timestamp */
|
||||||
if (pending)
|
if (pending)
|
||||||
add_to_cache();
|
add_to_cache(audio_prev_elapsed());
|
||||||
|
|
||||||
/* check if track was resumed > %50 played
|
/* check if track was resumed > %50 played
|
||||||
check for blank artist or track name */
|
check for blank artist or track name */
|
||||||
|
|
@ -219,7 +218,7 @@ void scrobbler_change_event(struct mp3entry *id)
|
||||||
int scrobbler_init(void)
|
int scrobbler_init(void)
|
||||||
{
|
{
|
||||||
logf("SCROBBLER: init %d", global_settings.audioscrobbler);
|
logf("SCROBBLER: init %d", global_settings.audioscrobbler);
|
||||||
|
|
||||||
if(!global_settings.audioscrobbler)
|
if(!global_settings.audioscrobbler)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
|
@ -239,8 +238,8 @@ void scrobbler_flush_cache(void)
|
||||||
{
|
{
|
||||||
/* Add any pending entries to the cache */
|
/* Add any pending entries to the cache */
|
||||||
if(pending)
|
if(pending)
|
||||||
add_to_cache();
|
add_to_cache(audio_prev_elapsed());
|
||||||
|
|
||||||
/* Write the cache to disk if needed */
|
/* Write the cache to disk if needed */
|
||||||
if (cache_pos)
|
if (cache_pos)
|
||||||
write_cache();
|
write_cache();
|
||||||
|
|
@ -257,7 +256,7 @@ void scrobbler_shutdown(void)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
scrobbler_flush_cache();
|
scrobbler_flush_cache();
|
||||||
|
|
||||||
if (scrobbler_initialised)
|
if (scrobbler_initialised)
|
||||||
{
|
{
|
||||||
audio_set_track_changed_event(NULL);
|
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)
|
bool scrobbler_is_enabled(void)
|
||||||
{
|
{
|
||||||
return scrobbler_initialised;
|
return scrobbler_initialised;
|
||||||
|
|
|
||||||
|
|
@ -21,4 +21,5 @@ void scrobbler_change_event(struct mp3entry *id);
|
||||||
int scrobbler_init(void);
|
int scrobbler_init(void);
|
||||||
void scrobbler_flush_cache(void);
|
void scrobbler_flush_cache(void);
|
||||||
void scrobbler_shutdown(void);
|
void scrobbler_shutdown(void);
|
||||||
|
void scrobbler_poweroff(void);
|
||||||
bool scrobbler_is_enabled(void);
|
bool scrobbler_is_enabled(void);
|
||||||
|
|
|
||||||
|
|
@ -2727,6 +2727,11 @@ void audio_play(long offset)
|
||||||
void audio_stop(void)
|
void audio_stop(void)
|
||||||
{
|
{
|
||||||
#ifndef SIMULATOR
|
#ifndef SIMULATOR
|
||||||
|
if (playing)
|
||||||
|
{
|
||||||
|
struct trackdata *track = get_trackdata(0);
|
||||||
|
prev_track_elapsed = track->id3.elapsed;
|
||||||
|
}
|
||||||
mpeg_stop_done = false;
|
mpeg_stop_done = false;
|
||||||
queue_post(&mpeg_queue, MPEG_STOP, 0);
|
queue_post(&mpeg_queue, MPEG_STOP, 0);
|
||||||
while(!mpeg_stop_done)
|
while(!mpeg_stop_done)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue