Reputation: 85
I'm a very noob user, I'm trying to play some tracks from Spotify in my Android app. Currently I'm using the kaaes API: https://github.com/kaaes/spotify-web-api-android
and I'm struggling to retrieve the tracks from a very specific Playlist and a very specific userId. It seems that I'm not able to do it, the only examples I found are old and don't help me. Here's what I tried:
Accessing list of playlists from Pager object
SpotifyApi api = new SpotifyApi();
SpotifyService spotify = api.getService();
spotify.getPlaylistTracks("USERID","PLAYLISTID", new Callback<Pager<PlaylistTrack>>() {
@Override
public void success(Pager<PlaylistTrack> playlistTrackPager, Response response) {
Log.e("TEST", "GOT the tracks in playlist");
List<PlaylistTrack> items = playlistTrackPager.items;
for( PlaylistTrack pt : items){
Log.e("TEST", pt.track.name + " - " + pt.track.id);
}
}
@Override
public void failure(RetrofitError error) {
Log.e("TEST", "Could not get playlist tracks");
}
});
It enlights red Callback (when I call new Callback<Pager<PlaylistTrack>>()
) and it says:
Cannot resolve symbol 'Callback'
If I alt+enter click on it it says:
Add library 'retrofit-2.4.0.retrofit-2.4.0' to classpath
If I do it, then it underlines all Callback<Pager<PlaylistTrack>>
, with error:
then I alt+enter again and it says:
Class 'Anonymous Class derived from Callback' must either be declared abstract or implement abstract method 'onResponse(Call, Response) in 'Callback'
Then I alt+enter click again and I choose: Implements methods onResponse() and onFailure()
and I adjust the old code with the new methods so it will be:
spotify.getPlaylistTracks("USERID","PLAYLISTID", new Callback<Pager<PlaylistTrack>>() {
@Override
public void onResponse(Call<Pager<PlaylistTrack>> playlistTrackPager, Response<Pager<PlaylistTrack>> response) {
Log.e("TEST", "GOT the tracks in playlist");
List<PlaylistTrack> items = playlistTrackPager.items;
for( PlaylistTrack pt : items){
Log.e("TEST", pt.track.name + " - " + pt.track.id);
}
}
@Override
public void onFailure(Call<Pager<PlaylistTrack>> call, Throwable t) {
Log.e("TEST", "Could not get playlist tracks");
}
});
But now, .items
is enlighted red and says:
Cannot resolve symbol 'items'
I couldn't find anything online about this.. it seems that I'm not able to fit the old code examples I found with the new API methods.
Thank you
Upvotes: 2
Views: 903
Reputation: 557
Your first code snipped does not show any errors in my test project. I guess there are issues with overlapping imports or other libraries.
Please check if it works if you add the following imports and remove the other retrofit/ kaaes imports:
import kaaes.spotify.webapi.android.SpotifyApi;
import kaaes.spotify.webapi.android.SpotifyService;
import kaaes.spotify.webapi.android.models.Pager;
import kaaes.spotify.webapi.android.models.PlaylistTrack;
import retrofit.Callback;
import retrofit.RetrofitError;
import retrofit.client.Response;
If this does not work, please remove the retrofit 2 library from your class path / project and try it again, since this wrapper still uses retrofit 1.9.0.
Upvotes: 2