[Android] Video player: Fix service connection fail

Geoffrey Métais git at videolan.org
Fri Apr 5 17:14:20 CEST 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Apr  5 17:13:08 2019 +0200| [426806588c66a9fca4de21d177ca759ef1d1392d] | committer: Geoffrey Métais

Video player: Fix service connection fail

On video playback resume back from mulittaskiing, connection to
playbackservice could fail and mess video playback

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

 .../src/org/videolan/vlc/gui/video/VideoPlayerActivity.java | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 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 d9029e2fe..fd123cbe7 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -610,9 +610,13 @@ public class VideoPlayerActivity extends AppCompatActivity implements IPlaybackS
 
         saveBrightness();
 
-        if (mService != null) mService.removeCallback(this);
+        if (mService != null) {
+            mService.removeCallback(this);
+            mService = null;
+        }
         // Clear Intent to restore playlist on activity restart
         setIntent(new Intent());
+        mHandler.removeCallbacksAndMessages(null);
     }
 
     private void saveBrightness() {
@@ -1532,7 +1536,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IPlaybackS
                     mLockBackButton = true;
                     break;
                 case CHECK_VIDEO_TRACKS:
-                    if (mService.getVideoTracksCount() < 1 && mService.getAudioTracksCount() > 0) {
+                    if (mService != null && mService.getVideoTracksCount() < 1 && mService.getAudioTracksCount() > 0) {
                         Log.i(TAG, "No video track, open in audio mode");
                         switchToAudioMode(true);
                     }
@@ -2492,7 +2496,6 @@ public class VideoPlayerActivity extends AppCompatActivity implements IPlaybackS
             mWasPaused = true;
         if (mWasPaused && BuildConfig.DEBUG)
             Log.d(TAG, "Video was previously paused, resuming in paused mode");
-
         if (intent.getData() != null) mUri = intent.getData();
         if (extras != null) {
             if (intent.hasExtra(Constants.PLAY_EXTRA_ITEM_LOCATION))
@@ -2937,8 +2940,8 @@ public class VideoPlayerActivity extends AppCompatActivity implements IPlaybackS
                 }
             });
             mService.addCallback(this);
-        } else {
-            if (mService != null) mService.removeCallback(this);
+        } else if (mService != null) {
+            mService.removeCallback(this);
             mService = null;
             mHandler.sendEmptyMessage(AUDIO_SERVICE_CONNECTION_FAILED);
         }



More information about the Android mailing list