[Android] Video player: prevent NPE
Geoffrey Métais
git at videolan.org
Tue Dec 18 14:55:52 CET 2018
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Dec 18 12:08:07 2018 +0100| [3401410d2e3a99b7482ad6e10e06a4691a91cc4a] | committer: Geoffrey Métais
Video player: prevent NPE
> https://code.videolan.org/videolan/vlc-android/commit/3401410d2e3a99b7482ad6e10e06a4691a91cc4a
---
.../src/org/videolan/vlc/gui/video/VideoPlayerActivity.java | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
index b90f2f774..73f804f5c 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -2430,7 +2430,8 @@ public class VideoPlayerActivity extends AppCompatActivity implements IPlaybackS
final Intent intent = getIntent();
final Bundle extras = intent.getExtras();
long savedTime = 0L;
- final boolean hasMedia = mService.hasMedia();
+ final MediaWrapper currentMedia = mService.getCurrentMediaWrapper();
+ final boolean hasMedia = currentMedia != null;
final boolean isPlaying = mService.isPlaying();
/*
* If the activity has been paused by pressing the power button, then
@@ -2466,7 +2467,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IPlaybackS
itemTitle = extras.getString(Constants.PLAY_EXTRA_ITEM_TITLE);
}
if (savedTime == 0L && mSavedTime > 0L) savedTime = mSavedTime;
- final boolean restorePlayback = hasMedia && mService.getCurrentMediaWrapper().getUri().equals(mUri);
+ final boolean restorePlayback = hasMedia && currentMedia.getUri().equals(mUri);
MediaWrapper openedMedia = null;
final boolean resumePlaylist = mService.isValidIndex(positionInPlaylist);
@@ -2533,12 +2534,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IPlaybackS
// Start playback & seek
/* prepare playback */
final boolean medialoaded = media != null;
- if (!medialoaded) {
- if (hasMedia)
- media = mService.getCurrentMediaWrapper();
- else
- media = new MediaWrapper(mUri);
- }
+ if (!medialoaded) media = hasMedia ? currentMedia : new MediaWrapper(mUri);
if (mWasPaused)
media.addFlags(MediaWrapper.MEDIA_PAUSED);
if (intent.hasExtra(Constants.PLAY_DISABLE_HARDWARE))
More information about the Android
mailing list