Spotify Android SDK - How to Update Player Object in Hour
I am using Spotify Android SDK version spotifysdk-1.0.0-beta8.aar. I have a valid OAuth token which I update every hour successfully. This is how I first get the Spotify Player object
mPlayer = Spotify.getPlayer(playerConfig, this, new Player.InitializationObserver() {
@Override
public void onInitialized(Player player) {
player.addConnectionStateCallback(JukeSpotDashboardActivity.this);
player.addPlayerNotificationCallback(JukeSpotDashboardActivity.this);
player.login(utils.getPreferenceValue(getString(R.string.spotify_access_token)));
}
@Override
public void onError(Throwable throwable) {
Log.e(JukeSpotDashboardActivity.class.getName(),
"Could not initialize player: " + throwable.getMessage());
}
});
At the end of each hour, the access token is refreshed and stored in shared preferences. How do you guys suggest using a new access token in the same mPlayer object so that the streaming of any song doesn't currently stop and I don't have to recreate that Spotify Player object?
I know there is
mPlayer.login(accessToken);
but it didn't work when i got a new accessToken and went inside. Any idea what I am doing wrong?
source to share
Once logged in, your app will be able to stream until the app is stopped, the network connection is lost, or the user account is terminated. (There may be other events as well.) This means that you do not need to update the Player object with an updated access token to continue streaming.
Please note that if you make any other requests using an access token, such as adding a track to a playlist, the access token must be updated in whatever tool you use to make the request. For example, if you are using the excellent kaaes Spotify Web API client for Android , you will need to get a new instance SpotifyService
based on an instance on an updated access token.
source to share