[Android] Restore position and time in last playlist

Geoffrey Métais git at videolan.org
Tue Jun 16 13:13:56 CEST 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Jun 16 13:13:22 2015 +0200| [6165d2a09dea6fea5aec2409529cf1d5cd9ea4bb] | committer: Geoffrey Métais

Restore position and time in last playlist

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

 .../src/org/videolan/vlc/PlaybackService.java        |   18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.java b/vlc-android/src/org/videolan/vlc/PlaybackService.java
index 07d621e..eeb4b97 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.java
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.java
@@ -860,6 +860,7 @@ public class PlaybackService extends Service {
     }
 
     private void stop() {
+        savePosition();
         MediaPlayer().stop();
         mEventHandler.removeHandler(mVlcEventHandler);
         mMediaListPlayer.getMediaList().removeEventListener(mListEventListener);
@@ -1124,12 +1125,20 @@ public class PlaybackService extends Service {
 
         mShuffling = prefs.getBoolean("shuffling", false);
         mRepeating = RepeatType.values()[prefs.getInt("repeating", RepeatType.None.ordinal())];
-        int position = Math.max(0, mediaPathList.indexOf(currentMedia));
+        int position = prefs.getInt("position_in_list", Math.max(0, mediaPathList.indexOf(currentMedia)));
+        long time = prefs.getLong("position_in_song", -1);
         // load playlist
         try {
             mInterface.loadLocations(mediaPathList, position);
+            if (time > 0)
+                mInterface.setTime(time);
         } catch (RemoteException e) {
             e.printStackTrace();
+        } finally {
+            SharedPreferences.Editor editor = prefs.edit();
+            editor.putInt("position_in_list", 0);
+            editor.putLong("position_in_song", 0);
+            Util.commitPreferences(editor);
         }
     }
 
@@ -1151,6 +1160,13 @@ public class PlaybackService extends Service {
         Util.commitPreferences(editor);
     }
 
+    private synchronized void savePosition(){
+        SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit();
+        editor.putInt("position_in_list", mCurrentIndex);
+        editor.putLong("position_in_song", MediaPlayer().getTime());
+        Util.commitPreferences(editor);
+    }
+
     private boolean validateLocation(String location)
     {
         /* Check if the MRL contains a scheme */



More information about the Android mailing list