Reputation: 501
I have an arraylist of songs uri from spotify using android sdk. But only one song is playing I want to detect when one song is complete so that I can initiate another song below is the code I am using.
Config playerConfig = new Config(this,sharedPreferences.getString(KEY,""),CLIENT_ID);
Spotify.getPlayer(playerConfig, this, new SpotifyPlayer.InitializationObserver() {
@Override
public void onInitialized(SpotifyPlayer spotifyPlayer) {
mPlayer = spotifyPlayer;
// Toast.makeText(MainActivity.this,mPlayer.getMetadata().toString(),Toast.LENGTH_LONG).show();
// System.out.println(response.getAccessToken());
mPlayer.addNotificationCallback(PlaySong.this);
mPlayer.play(track.get(curr).getUriFull(), 0, 0);
mPlayer.queue(track.get(1).getUriFull());
// mPlayer.addPlayerNotificationCallback(MainActivity.this);
}
@Override
public void onError(Throwable throwable) {
}
});
Any help would be appreciated.
Upvotes: 1
Views: 501
Reputation: 501
Well I solved the problem myself after spending sometime on it. Below is the solution if anyone ever needs it.
mPlayer.addNotificationCallback(new Player.NotificationCallback() {
@Override
public void onPlaybackEvent(PlayerEvent playerEvent) {
if(playerEvent==PlayerEvent.kSpPlaybackNotifyTrackDelivered){
Toast.makeText(PlaySong.this,"Delivered",Toast.LENGTH_LONG).show();
System.out.println("Delivered");
}
@Override
public void onPlaybackError(Error error) {
}
});
Just Simply check this condition if(playerEvent==PlayerEvent.kSpPlaybackNotifyTrackDelivered)
Upvotes: 3