[Android] Fix player resume from apps switch

Geoffrey Métais git at videolan.org
Sat Jun 4 12:26:13 CEST 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Sat Jun  4 12:25:44 2016 +0200| [40bd725f52212270c30b9744ceecdeb144e5c841] | committer: Geoffrey Métais

Fix player resume from apps switch

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

 .../org/videolan/vlc/gui/video/VideoPlayerActivity.java  | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 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 699dc1e..5cbb172 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -2866,6 +2866,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
         mIsPlaying = false;
         String title = getResources().getString(R.string.title);
         boolean fromStart = false;
+        boolean hasMedia = mService.hasMedia();
         String itemTitle = null;
         int positionInPlaylist = -1;
         long intentPosition = -1; // position passed in by intent (ms)
@@ -2900,7 +2901,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
         if (intent.hasExtra(PLAY_EXTRA_ITEM_TITLE))
             itemTitle = extras.getString(PLAY_EXTRA_ITEM_TITLE);
 
-        if (positionInPlaylist != -1 && mService.hasMedia()) {
+        if (positionInPlaylist != -1 && hasMedia) {
             // Provided externally from AudioService
             Log.d(TAG, "Continuing playback from PlaybackService at index " + positionInPlaylist);
             MediaWrapper openedMedia = mService.getMedias().get(positionInPlaylist);
@@ -2915,7 +2916,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
         }
 
         if (mUri != null) {
-            if (mService.hasMedia() && !mUri.equals(mService.getCurrentMediaWrapper().getUri()))
+            if (hasMedia && !mUri.equals(mService.getCurrentMediaWrapper().getUri()))
                 mService.stop();
             // restore last position
             MediaWrapper media = MediaDatabase.getInstance().getMedia(mUri);
@@ -2965,7 +2966,6 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
             // Start playback & seek
             mService.addCallback(this);
             /* prepare playback */
-            boolean hasMedia = mService.hasMedia();
             if (hasMedia)
                 media = mService.getCurrentMediaWrapper();
             else if (media == null)
@@ -2981,9 +2981,13 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
             // Handle playback
             if (!hasMedia)
                 mService.load(media);
-            else if (!mService.isPlaying())
-                mService.playIndex(positionInPlaylist);
-            else {
+            else if (!mService.isPlaying()) {
+                if (mService.getTime() > 0) {
+                    seek = false;
+                    mService.play();
+                } else
+                    mService.playIndex(positionInPlaylist);
+            } else {
                 seek = false;
                 onPlaying();
             }



More information about the Android mailing list