[Android] Fix video stop & resume

Geoffrey Métais git at videolan.org
Fri Nov 27 17:07:29 CET 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Nov 27 14:36:57 2015 +0100| [7843c97c6b691403458dc5ce70c75deebb06e92a] | committer: Geoffrey Métais

Fix video stop & resume

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=7843c97c6b691403458dc5ce70c75deebb06e92a
---

 vlc-android/src/org/videolan/vlc/PlaybackService.java    |    6 +++---
 .../org/videolan/vlc/gui/video/VideoPlayerActivity.java  |   14 ++++----------
 2 files changed, 7 insertions(+), 13 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.java b/vlc-android/src/org/videolan/vlc/PlaybackService.java
index e96253a..227b607 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.java
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.java
@@ -1258,7 +1258,7 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
         sendBroadcast(broadcast);
     }
 
-    private synchronized void loadLastPlaylist() {
+    public synchronized void loadLastPlaylist() {
         SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
         String currentMedia = prefs.getString("current_media", "");
         if (currentMedia.equals(""))
@@ -1290,7 +1290,7 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
     }
 
     private synchronized void saveMediaList() {
-        if (getCurrentMedia() == null || getCurrentMedia().getType() == MediaWrapper.TYPE_VIDEO)
+        if (getCurrentMedia() == null)
             return;
         StringBuilder locations = new StringBuilder();
         for (int i = 0; i < mMediaList.size(); i++)
@@ -1302,7 +1302,7 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
     }
 
     private synchronized void savePosition(){
-        if (getCurrentMedia() == null || getCurrentMedia().getType() == MediaWrapper.TYPE_VIDEO)
+        if (getCurrentMedia() == null)
             return;
         SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit();
         editor.putBoolean("shuffling", mShuffling);
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 6be66f8..665ec0d 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -54,7 +54,6 @@ import android.support.annotation.NonNull;
 import android.support.v4.app.FragmentManager;
 import android.support.v4.content.LocalBroadcastManager;
 import android.support.v4.view.GestureDetectorCompat;
-import android.support.v4.view.MenuItemCompat;
 import android.support.v7.app.ActionBar;
 import android.support.v7.app.AlertDialog;
 import android.support.v7.app.AppCompatActivity;
@@ -67,7 +66,6 @@ import android.view.Display;
 import android.view.GestureDetector;
 import android.view.InputDevice;
 import android.view.KeyEvent;
-import android.view.Menu;
 import android.view.MenuItem;
 import android.view.MotionEvent;
 import android.view.Surface;
@@ -244,9 +242,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
      */
     private boolean mSwitchingView;
     private boolean mHardwareAccelerationError;
-    private boolean mEndReached;
     private boolean mHasSubItems = false;
-    private boolean mForceStop = false;
 
     // Playlist
     private int savedIndexPosition = -1;
@@ -434,7 +430,6 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
 
         mSwitchingView = false;
         mHardwareAccelerationError = false;
-        mEndReached = false;
 
         mAskResume = mSettings.getBoolean("dialog_confirm_resume", false);
         // Clear the resume time, since it is only used for resumes in external
@@ -807,8 +802,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
             time = 0;
         else
             time -= 2000; // go back 2 seconds, to compensate loading time
-        if (mForceStop)
-            mService.stop();
+        mService.stop();
 
         SharedPreferences.Editor editor = mSettings.edit();
         // Save position
@@ -1038,7 +1032,6 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
         } else if (BuildConfig.tv && mShowing && !mIsLocked) {
             hideOverlay(true);
         } else {
-            mForceStop = true;
             exitOK();
             super.onBackPressed();
         }
@@ -1585,7 +1578,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
 
     private void handleVout(int voutCount) {
         final IVLCVout vlcVout = mService.getVLCVout();
-        if (vlcVout.areViewsAttached() && voutCount == 0 && !mEndReached) {
+        if (vlcVout.areViewsAttached() && voutCount == 0) {
             /* Video track lost, open in audio mode */
             Log.i(TAG, "Video track lost, switching to audio");
             mSwitchingView = true;
@@ -2852,7 +2845,8 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
             // Get the title
             if (itemTitle == null)
                 title = mUri.getLastPathSegment();
-        }
+        } else
+            mService.loadLastPlaylist();
         if (itemTitle != null)
             title = itemTitle;
         mTitle.setText(title);



More information about the Android mailing list