/** * This callback is called when an attempt to login has succeeded or failed. * * @sa sp_session_callbacks#logged_in */ static void logged_in(sp_session *sess, sp_error error) { sp_playlistcontainer *pc = sp_session_playlistcontainer(sess); int i; if (SP_ERROR_OK != error) { fprintf(stderr, "jukebox: Login failed: %s\n", sp_error_message(error)); exit(2); } sp_playlistcontainer_add_callbacks( pc, &pc_callbacks, NULL); printf("jukebox: Looking at %d playlists\n", sp_playlistcontainer_num_playlists(pc)); for (i = 0; i < sp_playlistcontainer_num_playlists(pc); ++i) { sp_playlist *pl = sp_playlistcontainer_playlist(pc, i); sp_playlist_add_callbacks(pl, &pl_callbacks, NULL); if (!strcasecmp(sp_playlist_name(pl), g_listname)) { g_jukeboxlist = pl; try_jukebox_start(); } } if (!g_jukeboxlist) { printf("jukebox: No such playlist. Waiting for one to pop up...\n"); fflush(stdout); } }
/** * Callback from libspotify, saying that a track has been added to a playlist. * * @param pl The playlist handle * @param tracks An array of track handles * @param num_tracks The number of tracks in the \c tracks array * @param position Where the tracks were inserted * @param userdata The opaque pointer */ static void tracks_added(sp_playlist *pl, sp_track * const *tracks, int num_tracks, int position, void *userdata) { if (pl != g_jukeboxlist) return; printf("jukebox: %d tracks were added\n", num_tracks); fflush(stdout); try_jukebox_start(); }
/** * Callback from libspotify, telling us a playlist was added to the playlist container. * * We add our playlist callbacks to the newly added playlist. * * @param pc The playlist container handle * @param pl The playlist handle * @param position Index of the added playlist * @param userdata The opaque pointer */ static void playlist_added(sp_playlistcontainer *pc, sp_playlist *pl, int position, void *userdata) { sp_playlist_add_callbacks(pl, &pl_callbacks, NULL); if (!strcasecmp(sp_playlist_name(pl), g_listname)) { g_jukeboxlist = pl; try_jukebox_start(); } }
/** * Callback from libspotify, telling when tracks have been moved around in a playlist. * * @param pl The playlist handle * @param tracks An array of track indices * @param num_tracks The number of tracks in the \c tracks array * @param new_position To where the tracks were moved * @param userdata The opaque pointer */ static void tracks_moved(sp_playlist *pl, const int *tracks, int num_tracks, int new_position, void *userdata) { if (pl != g_jukeboxlist) return; printf("jukebox: %d tracks were moved around\n", num_tracks); fflush(stdout); try_jukebox_start(); }
void start_playlist(char *uri) { printf("Start playlist: %s\n", uri); sp_link *link = sp_link_create_from_string(uri); sp_playlist *pl = sp_playlist_create(g_sess, link); sp_playlist_add_callbacks(pl, &pl_callbacks, NULL); sprintf(g_last_playlist_name, sp_playlist_name(pl)); // hardware_banner(sp_playlist_name(pl), 200); g_jukeboxlist = pl; try_jukebox_start(); }
/** * A track has ended. Remove it from the playlist. * * Called from the main loop when the music_delivery() callback has set g_playback_done. */ static void track_ended(void) { int tracks = 0; if (g_currenttrack) { g_currenttrack = NULL; sp_session_player_unload(g_sess); if (g_remove_tracks) { sp_playlist_remove_tracks(g_jukeboxlist, &tracks, 1); } else { ++g_track_index; try_jukebox_start(); } } }
/** * Callback from libspotify. Something renamed the playlist. * * @param pl The playlist handle * @param userdata The opaque pointer */ static void playlist_renamed(sp_playlist *pl, void *userdata) { const char *name = sp_playlist_name(pl); if (!strcasecmp(name, g_listname)) { g_jukeboxlist = pl; g_track_index = 0; try_jukebox_start(); } else if (g_jukeboxlist == pl) { printf("jukebox: current playlist renamed to \"%s\".\n", name); g_jukeboxlist = NULL; g_currenttrack = NULL; sp_session_player_unload(g_sess); } }
/** * Callback from libspotify, saying that a track has been added to a playlist. * * @param pl The playlist handle * @param tracks An array of track handles * @param num_tracks The number of tracks in the \c tracks array * @param position Where the tracks were inserted * @param userdata The opaque pointer */ static void tracks_added(sp_playlist *pl, sp_track * const *tracks, int num_tracks, int position, void *userdata) { printf("jukebox: %d tracks were added\n", num_tracks); fflush(stdout); if (pl != g_jukeboxlist) { printf("not correct playlist!\n"); return; } if (!g_is_playing) try_jukebox_start(); }
/** * Callback from libspotify, saying that a track has been added to a playlist. * * @param pl The playlist handle * @param tracks An array of track indices * @param num_tracks The number of tracks in the \c tracks array * @param userdata The opaque pointer */ static void tracks_removed(sp_playlist *pl, const int *tracks, int num_tracks, void *userdata) { int i, k = 0; if (pl != g_jukeboxlist) return; for (i = 0; i < num_tracks; ++i) if (tracks[i] < g_track_index) ++k; g_track_index -= k; printf("jukebox: %d tracks were removed\n", num_tracks); fflush(stdout); try_jukebox_start(); }
/** * A track has ended. Remove it from the playlist. * * Called from the main loop when the music_delivery() callback has set g_playback_done. */ static void track_ended(bool startNext) { printf("track_ended startNext=%d\n", startNext); int tracks = 0; if (g_currenttrack) { printf("track_ended: stopping current track.\n"); g_currenttrack = NULL; sp_session_player_unload(g_sess); g_is_playing = 0; } audio_fifo_flush(&g_musicfifo); notify_main_thread(g_sess); audio_fifo_flush(&g_musicfifo); usleep(50000); if (startNext) { printf("track_ended: play next track.\n"); try_jukebox_start(); usleep(50000); notify_main_thread(g_sess); banner_track(); } }
/** * Callback called when libspotify has new metadata available * * Not used in this example (but available to be able to reuse the session.c file * for other examples.) * * @sa sp_session_callbacks#metadata_updated */ static void metadata_updated(sp_session *sess) { try_jukebox_start(); }
/** * Callback called when libspotify has new metadata available * * Not used in this example (but available to be able to reuse the session.c file * for other examples.) * * @sa sp_session_callbacks#metadata_updated */ static void SP_CALLCONV metadata_updated(sp_session *sess) { try_jukebox_start(); }