1

I'm trying to create a simple player in android following guidance from http://damienradtke.org/playing-with-the-spotify-api/ , using it i'm able to play a track from spotify in ubuntu but i cant even build on android. So far i'm able to query for a track from spotify but its been a nightmare when i've tried to add playback capabilities using ALSA. I've tried using openAl and am still stuck. Is there a much simpler way to play streamed audio in jni?

at the end of my &on_search_complete callback i call a function 'play' which looks like this:

void play(sp_session *session, sp_track *track)
{
if(DEBUG_MODE) __android_log_print(ANDROID_LOG_INFO, "spotify", "attempting to play track...");
sp_error error = sp_session_player_load(session, track);
    if (error != SP_ERROR_OK) {
    if(DEBUG_MODE) __android_log_print(ANDROID_LOG_INFO, "spotify", "Error: %s\n",    sp_error_message(error));
    exit(1);
}

if(DEBUG_MODE) __android_log_print(ANDROID_LOG_INFO, "spotify", "Playing...");
sp_session_player_play(session, 1);
}

this leads to the &on_music_delivery callback being executed, i believe this is where i need to add my playback code.

static int on_music_delivery(sp_session *session, const sp_audioformat *format, const void *frames, int num_frames)
{
if(DEBUG_MODE) __android_log_print(ANDROID_LOG_INFO, "spotify", "in on_music_delivery");
}

I've had little success building my code with ALSA, can someone point me to the right direction here. Its frustrating and i dont want to give up at the last hurdle. NB: i'm a beginner in the C language

kev
  • 1,148
  • 2
  • 14
  • 29

1 Answers1

0

Disclaimer: I work for Spotify

First of all, I'd like to state that the Android documentation shipped with libspotify isn't nearly as great as it could be. We're working to improve this. Until then, I can advise you that using OpenSL to play audio from the native code is probably the easiest way to accomplish this task. I would advise checking out this StackOverflow question to find some good OpenSL tutorials.

Community
  • 1
  • 1
Nik Reiman
  • 39,067
  • 29
  • 104
  • 160