#define SPOTIFY_API_VERSION 1 |
Current version of the application interface, that is, the API described by this file.
This value should be set in the sp_session_config struct passed to sp_session_init().
If an (upgraded) library is no longer compatible with this version the error SP_ERROR_BAD_API_VERSION will be returned from sp_session_init(). Future versions of the library will provide you with some kind of mechanism to request an updated version of the library.
enum sp_connectionstate |
Describes the current state of the connection
enum sp_sampletype |
sp_connectionstate sp_session_connectionstate | ( | sp_session * | session | ) |
The connection state of the specified session.
[in] | session | Your session object |
sp_error sp_session_init | ( | const sp_session_config * | config, | |
sp_session ** | sess | |||
) |
Initialize a session. The session returned will be initialized, but you will need to log in before you can perform any other operation
In the future, this will be renamed to sp_session_create() and will have a corresponding sp_session_release() function.
Here is a snippet from session.c:
config.api_version = SPOTIFY_API_VERSION; // The path of the directory to store the cache. This must be specified. // Please read the documentation on preferred values. config.cache_location = "tmp"; // The path of the directory to store the settings. This must be specified. // Please read the documentation on preferred values. config.settings_location = "tmp"; // The key of the application. They are generated by Spotify, // and are specific to each application using libspotify. config.application_key = g_appkey; config.application_key_size = g_appkey_size; // This identifies the application using some // free-text string [1, 255] characters. config.user_agent = "spotify-session-example"; // Register the callbacks. config.callbacks = &g_callbacks; error = sp_session_init(&config, &session); if (SP_ERROR_OK != error) { fprintf(stderr, "failed to create session: %s\n", sp_error_message(error)); return 2; }
[in] | config | The configuration to use for the session |
[out] | sess | If successful, a new session - otherwise NULL |
sp_error sp_session_login | ( | sp_session * | session, | |
const char * | username, | |||
const char * | password | |||
) |
Logs in the specified username/password combo. This initiates the download in the background. A callback is called when login is complete
Here is a snippet from session.c:
error = sp_session_login(session, argv[1], argv[2]); if (SP_ERROR_OK != error) { fprintf(stderr, "failed to login: %s\n", sp_error_message(error)); return 3; }
[in] | session | Your session object |
[in] | username | The username to log in |
[in] | password | The password for the specified username |
sp_error sp_session_logout | ( | sp_session * | session | ) |
Logs out the currently logged in user
Always call this before terminating the application and libspotify is currently logged in. Otherwise, the settings and cache may be lost.
Here is a snippet from session_ready.c:
sp_error error = sp_session_logout(session); if (SP_ERROR_OK != error) { fprintf(stderr, "failed to log out from Spotify: %s\n", sp_error_message(error)); g_exit_code = 5; return; }
[in] | session | Your session object |
sp_error sp_session_player_load | ( | sp_session * | session, | |
sp_track * | track | |||
) |
Loads the specified track
After successfully loading the track, you have the option of running sp_session_player_play() directly, or using sp_session_player_seek() first. When this call returns, the track will have been loaded, unless an error occurred.
[in] | session | Your session object |
[in] | track | The track to be loaded |
sp_error sp_session_player_play | ( | sp_session * | session, | |
bool | play | |||
) |
sp_error sp_session_player_seek | ( | sp_session * | session, | |
int | offset | |||
) |
Seek to position in the currently loaded track
[in] | session | Your session object |
[in] | offset | Track position, in milliseconds. |
void sp_session_player_unload | ( | sp_session * | session | ) |
Stops the currently playing track
This frees some resources held by libspotify to identify the currently playing track.
[in] | session | Your session object |
sp_playlistcontainer* sp_session_playlistcontainer | ( | sp_session * | session | ) |
Returns the playlist container for the currently logged in user.
[in] | session | Your session object |
void sp_session_process_events | ( | sp_session * | session, | |
int * | next_timeout | |||
) |
Make the specified session process any pending events
Here is a snippet from session.c:
static void loop(sp_session *session) { sigset_t sigset; sigemptyset(&sigset); sigaddset(&sigset, SIGIO); while (g_exit_code < 0) { int timeout = -1; pthread_sigmask(SIG_BLOCK, &sigset, NULL); sp_session_process_events(session, &timeout); pthread_sigmask(SIG_UNBLOCK, &sigset, NULL); usleep(timeout * 1000); } }
[in] | session | Your session object |
[out] | next_timeout | Stores the time (in milliseconds) until you should call this function again |
sp_user* sp_session_user | ( | sp_session * | session | ) |
Fetches the currently logged in user
[in] | session | Your session object |
void* sp_session_userdata | ( | sp_session * | session | ) |
The userdata associated with the session
[in] | session | Your session object |