Skip to content

Instantly share code, notes, and snippets.

@dradtke
Created July 17, 2012 17:05
Show Gist options
  • Select an option

  • Save dradtke/3130612 to your computer and use it in GitHub Desktop.

Select an option

Save dradtke/3130612 to your computer and use it in GitHub Desktop.
// src/main.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <libspotify/api.h>
#define DEBUG 1
extern const uint8_t g_appkey[];
extern const size_t g_appkey_size;
extern const char *username;
extern const char *password;
int g_logged_in;
void debug(const char *format, ...)
{
if (!DEBUG)
return;
va_list argptr;
va_start(argptr, format);
vprintf(format, argptr);
printf("\n");
}
static void on_login(sp_session *session, sp_error error)
{
debug("callback: on_login");
if (error != SP_ERROR_OK) {
fprintf(stderr, "Error: unable to log in: %s\n", sp_error_message(error));
exit(1);
}
g_logged_in = 1;
}
static void on_main_thread_notified(sp_session *session)
{
debug("callback: on_main_thread_notified");
}
static int on_music_delivered(sp_session *session, const sp_audioformat *format, const void *frames, int num_frames)
{
debug("callback: on_music_delivered");
return 0;
}
static void on_log(sp_session *session, const char *data)
{
// this method is *very* verbose, so this data should really be written out to a log file
}
static void on_end_of_track(sp_session *session)
{
debug("callback: on_end_of_track");
}
static sp_session_callbacks session_callbacks = {
.logged_in = &on_login,
.notify_main_thread = &on_main_thread_notified,
.music_delivery = &on_music_delivered,
.log_message = &on_log,
.end_of_track = &on_end_of_track
};
static sp_session_config spconfig = {
.api_version = SPOTIFY_API_VERSION,
.cache_location = "tmp",
.settings_location = "tmp",
.application_key = g_appkey,
.application_key_size = 0, // set in main()
.user_agent = "spot",
.callbacks = &session_callbacks,
NULL
};
int main(void)
{
sp_error error;
sp_session *session;
// create the spotify session
spconfig.application_key_size = g_appkey_size;
error = sp_session_create(&spconfig, &session);
if (error != SP_ERROR_OK) {
fprintf(stderr, "Error: unable to create spotify session: %s\n", sp_error_message(error));
return 1;
}
int next_timeout = 0;
g_logged_in = 0;
sp_session_login(session, username, password, 0, NULL);
while (!g_logged_in) {
usleep(next_timeout * 1000);
sp_session_process_events(session, &next_timeout);
}
printf("success!\n");
return 0;
}
@alex190690
Copy link
Copy Markdown

Hi.... I compile this program after of install libspotify but i still show this error when i compile the complete program:

/home/alex/Escritorio/spot/src/main.o||In function on_login':| main.c|| undefined reference tosp_error_message'|
/home/alex/Escritorio/spot/src/main.o||In function main':| main.c|| undefined reference tosp_session_create'|
main.c|| undefined reference to sp_error_message'| main.c|| undefined reference tosp_session_login'|
main.c|| undefined reference to `sp_session_process_events'|

I would like to know what is the solution at this problem. Thanks....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment