0
我基於關閉演示活動在這裏寫一個Android應用程序:DemoActivity.java
我希望能夠翻轉的Android設備的屏幕(縱向到橫向或反之亦然),保持用戶登錄並播放音樂。目前我能夠保持用戶登錄,但我堅持如何保存播放狀態。
在我的onCreate:Spotify的:保存回放狀態信息
if(savedInstanceState != null) {
String accessToken = savedInstanceState.getString("accesstoken");
Config player_Config = new Config(this, accessToken, CLIENT_ID);
setPlayer(player_Config);
mCurrentPlaybackState = savedInstanceState.getParcelable("playbackstate");
}
的onSaveInstanceState我:
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
savedInstanceState.putString("accesstoken", accessToken);
savedInstanceState.putParcelable("playbackstate", mCurrentPlaybackState);
super.onSaveInstanceState(savedInstanceState);
}
我setPlayer(不包括身份驗證,因爲用戶將已經登錄):
public void setPlayer(Config player_Config) {
Spotify.getPlayer(player_Config, this, new SpotifyPlayer.InitializationObserver() {
@Override
public void onInitialized(SpotifyPlayer spotifyPlayer) {
myPlayer = spotifyPlayer;
myPlayer.addConnectionStateCallback(HostPartyActivity.this);
myPlayer.addNotificationCallback(HostPartyActivity.this);
updateUIElements();
}
@Override
public void onError(Throwable throwable) {
Log.e("HostPartyActivity", "Could not initialize player: " + throwable.getMessage());
}
});
}
我的親的樣品情況blem:
- 用戶按下「登錄」按鈕,登錄到Spotify的帳戶
- 用戶按下「播放」按鈕和Spotify的曲目開始播放
- 用戶從縱向翻轉裝置,以景觀
- 應用自動登錄基於用戶保存的數據
- Spotify的曲目將停止播放(應保持在保存時間玩)
謝謝你的幫助。