[Android] Video player: prevent NPE when HUD is not ready

Geoffrey Métais git at videolan.org
Mon Feb 18 17:04:54 CET 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Feb 18 16:56:40 2019 +0100| [fef0f71c704180bfe97deec52ea9507fbb1c8b0b] | committer: Geoffrey Métais

Video player: prevent NPE when HUD is not ready

> https://code.videolan.org/videolan/vlc-android/commit/fef0f71c704180bfe97deec52ea9507fbb1c8b0b
---

 .../org/videolan/vlc/gui/video/VideoPlayerActivity.java  | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 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 c743c9851..e33dfaa6d 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -694,8 +694,10 @@ public class VideoPlayerActivity extends AppCompatActivity implements IPlaybackS
                 mPlaylistModel.getDataset().observe(this, mPlaylistObserver);
             }
             mPlaylistToggle.setVisibility(View.VISIBLE);
-            mHudBinding.playlistPrevious.setVisibility(View.VISIBLE);
-            mHudBinding.playlistNext.setVisibility(View.VISIBLE);
+            if (mHudBinding != null) {
+                mHudBinding.playlistPrevious.setVisibility(View.VISIBLE);
+                mHudBinding.playlistNext.setVisibility(View.VISIBLE);
+            }
             mPlaylistToggle.setOnClickListener(VideoPlayerActivity.this);
 
             final ItemTouchHelper.Callback callback =  new SwipeDragItemTouchHelperCallback(mPlaylistAdapter);
@@ -1246,8 +1248,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IPlaybackS
         }
         UiTools.setViewVisibility(mOverlayInfo, View.INVISIBLE);
         mInfo.setText("");
-        if (mHudBinding != null)
-            mHudBinding.playerOverlayPlay.requestFocus();
+        if (mHudBinding != null) mHudBinding.playerOverlayPlay.requestFocus();
     }
 
     public void delayAudio(long delta) {
@@ -2150,6 +2151,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IPlaybackS
     }
 
     private void initSeekButton() {
+        if (mHudBinding == null) return;
         mHudBinding.playerOverlayRewind.setOnClickListener(this);
         mHudBinding.playerOverlayForward.setOnClickListener(this);
         mHudBinding.playerOverlayRewind.setOnTouchListener(new OnRepeatListener(this));
@@ -2213,6 +2215,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IPlaybackS
     private void showOverlayTimeout(int timeout) {
         if (mService == null) return;
         initOverlay();
+        if (mHudBinding == null) return;
         if (timeout != 0) mOverlayTimeout = timeout;
         else mOverlayTimeout = mService.isPlaying() ? OVERLAY_TIMEOUT : OVERLAY_INFINITE;
         if (mIsNavMenu){
@@ -2323,7 +2326,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IPlaybackS
                 mOverlayBackground.startAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_out));
                 mOverlayBackground.setVisibility(View.INVISIBLE);
             }
-            mHudBinding.progressOverlay.setVisibility(View.INVISIBLE);
+            if (mHudBinding != null) mHudBinding.progressOverlay.setVisibility(View.INVISIBLE);
             showControls(false);
             mShowing = false;
             dimStatusBar(true);
@@ -2380,8 +2383,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IPlaybackS
     }
 
     private void updateOverlayPausePlay() {
-        if (mService == null || mHudBinding == null)
-            return;
+        if (mService == null || mHudBinding == null) return;
         if (mService.isPausable())
             mHudBinding.playerOverlayPlay.setImageResource(mService.isPlaying() ? R.drawable.ic_pause_circle
                     : R.drawable.ic_play_circle);



More information about the Android mailing list