Search code examples
spotifylibspotify

Libspotfiy, registering mulitple callbacks on the same handle


Is it valid to add multiple callbacks to a libspotify handle? ie:

ie

sp_playlist_callbacks pl_callbacks1 = {
.tracks_added = &tracks_addedA,
};

sp_playlist_callbacks pl_callbacks2 = {
.tracks_added = &tracks_addedB,
};

sp_playlist_add_callbacks(pl, &pl_callbacks1, NULL);
sp_playlist_add_callbacks(pl, &pl_callbacks2, NULL);

Then, will both tracks_addedA and tracks_addedB be called by libspotify? This seems to work, but I don't know if it's working by chance or design? :)


Solution

  • Yes, this is fine — callbacks are keyed on the pointer of the callback and the userdata. An alternate approach that we use is to use the same callback pointer with different userdata values.