我使用android sdk有一个来自spotify的歌曲uri的arraylist。但是只有一首歌正在播放,我想在一首歌完成时检测到,以便我可以在下面发出另一首歌是我正在使用的代码。
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) {
}
});
任何帮助将不胜感激。
答案 0 :(得分:3)
嗯,我花了一些时间后自己解决了这个问题。如果有人需要,以下是解决方案。
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) {
}
});
只需检查此条件if(playerEvent==PlayerEvent.kSpPlaybackNotifyTrackDelivered)