playlist: track song metadata changes

When the tag of the current song changes (e.g. a new tag was sent in
the stream), update the playlist, so clients pick up the new tag.
This commit is contained in:
Max Kellermann 2008-11-11 20:46:55 +01:00
parent 81d2076bcf
commit acf0d141be
2 changed files with 14 additions and 12 deletions

View File

@ -830,13 +830,8 @@ enum playlist_result playPlaylistById(int id, int stopOnError)
static void syncCurrentPlayerDecodeMetadata(void) static void syncCurrentPlayerDecodeMetadata(void)
{ {
struct song *songPlayer = playerCurrentDecodeSong();
struct song *song; struct song *song;
int songNum; int songNum;
char path_max_tmp[MPD_PATH_MAX];
if (!songPlayer)
return;
if (playlist_state != PLAYLIST_STATE_PLAY) if (playlist_state != PLAYLIST_STATE_PLAY)
return; return;
@ -844,16 +839,18 @@ static void syncCurrentPlayerDecodeMetadata(void)
songNum = playlist.order[playlist.current]; songNum = playlist.order[playlist.current];
song = playlist.songs[songNum]; song = playlist.songs[songNum];
if (!song_is_file(song) && if (song != playlist.prev_song) {
0 == strcmp(song_get_url(song, path_max_tmp), songPlayer->url) && /* song change: initialize playlist.prev_{song,tag} */
!tag_equal(song->tag, songPlayer->tag)) {
assert(!song_in_database(song)); playlist.prev_song = song;
playlist.prev_tag = song->tag;
} else if (song->tag != playlist.prev_tag) {
/* tag change: update playlist */
if (song->tag)
tag_free(song->tag);
song->tag = tag_dup(songPlayer->tag);
playlist.songMod[songNum] = playlist.version; playlist.songMod[songNum] = playlist.version;
incrPlaylistVersion(); incrPlaylistVersion();
playlist.prev_tag = song->tag;
} }
} }

View File

@ -54,6 +54,11 @@ typedef struct _Playlist {
bool repeat; bool repeat;
bool random; bool random;
uint32_t version; uint32_t version;
/** used by syncCurrentPlayerDecodeMetadata() to detect tag changes */
const struct song *prev_song;
/** used by syncCurrentPlayerDecodeMetadata() to detect tag changes */
const struct tag *prev_tag;
} Playlist; } Playlist;
extern bool playlist_saveAbsolutePaths; extern bool playlist_saveAbsolutePaths;