[Android] video: improve position saving

Sébastien Toque git at videolan.org
Wed Jul 25 22:24:36 CEST 2012


android | branch: master | Sébastien Toque <xilasz at gmail.com> | Wed Jul 25 20:18:56 2012 +0200| [4cc7e1d740d356e9038fe78e1b897c989d7e7d7d] | committer: Sébastien Toque

video: improve position saving

- save position even if media is paused.
- do not save position if in the last 5 seconds, instead, erase it

> http://git.videolan.org/gitweb.cgi/android.git/?a=commit;h=4cc7e1d740d356e9038fe78e1b897c989d7e7d7d
---

 .../src/org/videolan/vlc/gui/video/VideoPlayerActivity.java |   11 ++++++++---
 1 file changed, 8 insertions(+), 3 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 60b619c..c661c79 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -278,9 +278,14 @@ public class VideoPlayerActivity extends Activity {
             super.onPause();
             return;
         }
-        long time = 0;
+        long time = mLibVLC.getTime();
+        long length = mLibVLC.getLength();
+        //remove saved position if in the last 5 seconds
+        if (length - time < 5000)
+            time = 0;
+        else
+            time -= 5000; // go back 5 seconds, to compensate loading time
         if (mLibVLC.isPlaying()) {
-            time = mLibVLC.getTime() - 5000;
             mLibVLC.pause();
         }
         mSurface.setKeepScreenOn(false);
@@ -994,7 +999,7 @@ public class VideoPlayerActivity extends Activity {
             mLibVLC.readMedia(mLocation, false);
             mSurface.setKeepScreenOn(true);
 
-            // Save media for next time, and restore position if it's the same one as before
+            // restore last position
             lastLocation = preferences.getString(PreferencesActivity.LAST_MEDIA, null);
             lastTime = preferences.getLong(PreferencesActivity.LAST_TIME, 0);
             if (lastTime > 0 && mLocation.equals(lastLocation))



More information about the Android mailing list