diff --git a/src/inputs/spotify.c b/src/inputs/spotify.c index f4d5cc8a..a52ebc07 100644 --- a/src/inputs/spotify.c +++ b/src/inputs/spotify.c @@ -22,14 +22,30 @@ #include #include "input.h" +#include "logger.h" #include "spotify.h" +// How many retries to start playback if resource is still loading +#define SPOTIFY_SETUP_RETRIES 5 +// How long to wait between retries in microseconds (500000 = 0.5 seconds) +#define SPOTIFY_SETUP_RETRY_WAIT 500000 + static int setup(struct player_source *ps) { + int i = 0; int ret; - ret = spotify_playback_setup(ps->path); + while((ret = spotify_playback_setup(ps->path)) == SPOTIFY_SETUP_ERROR_IS_LOADING) + { + if (i >= SPOTIFY_SETUP_RETRIES) + break; + + DPRINTF(E_DBG, L_SPOTIFY, "Resource still loading (%d)\n", i); + usleep(SPOTIFY_SETUP_RETRY_WAIT); + i++; + } + if (ret < 0) return -1; diff --git a/src/spotify.c b/src/spotify.c index 67a483a7..ed6d5745 100644 --- a/src/spotify.c +++ b/src/spotify.c @@ -604,7 +604,7 @@ playback_setup(void *arg, int *retval) if (SP_ERROR_OK != err) { DPRINTF(E_LOG, L_SPOTIFY, "Playback setup failed: %s\n", fptr_sp_error_message(err)); - *retval = -1; + *retval = (SP_ERROR_IS_LOADING == err) ? SPOTIFY_SETUP_ERROR_IS_LOADING : -1; return COMMAND_END; } diff --git a/src/spotify.h b/src/spotify.h index 988892e1..2e2f47c9 100644 --- a/src/spotify.h +++ b/src/spotify.h @@ -15,6 +15,8 @@ struct spotify_status_info char libspotify_user[100]; }; +#define SPOTIFY_SETUP_ERROR_IS_LOADING -2 + int spotify_playback_setup(const char *path);