PreviewMediaFragment: prevent NPE on onSaveInstanceState

Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
This commit is contained in:
Álvaro Brey 2022-06-14 17:14:22 +02:00
parent 17ebc23621
commit 528705a31d
No known key found for this signature in database
GPG key ID: 2585783189A62105

View file

@ -284,12 +284,12 @@ public class PreviewMediaFragment extends FileFragment implements OnTouchListene
outState.putParcelable(EXTRA_FILE, getFile());
outState.putParcelable(EXTRA_USER, user);
if (MimeTypeUtil.isVideo(getFile())) {
if (MimeTypeUtil.isVideo(getFile()) && exoPlayer != null) {
savedPlaybackPosition = exoPlayer.getCurrentPosition();
autoplay = exoPlayer.isPlaying();
outState.putLong(EXTRA_PLAY_POSITION, savedPlaybackPosition);
outState.putBoolean(EXTRA_PLAYING, autoplay);
} else if (mediaPlayerServiceConnection.isConnected()) {
} else if (mediaPlayerServiceConnection != null && mediaPlayerServiceConnection.isConnected()) {
outState.putInt(EXTRA_PLAY_POSITION, mediaPlayerServiceConnection.getCurrentPosition());
outState.putBoolean(EXTRA_PLAYING, mediaPlayerServiceConnection.isPlaying());
}