[Android] VideoPlayerActivity: save time as well for external videos

Edward Wang git at videolan.org
Fri Feb 8 05:23:47 CET 2013


vlc-ports/android | branch: master | Edward Wang <edward.c.wang at compdigitec.com> | Thu Feb  7 22:36:58 2013 -0500| [3b9ff935dceebb45d806a434e55768137a54ef4d] | committer: Edward Wang

VideoPlayerActivity: save time as well for external videos

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

 .../org/videolan/vlc/gui/PreferencesActivity.java  |    1 +
 .../vlc/gui/video/VideoPlayerActivity.java         |   32 +++++++++++++++++---
 2 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java b/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
index f4be4d7..7c462c7 100644
--- a/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
@@ -53,6 +53,7 @@ public class PreferencesActivity extends PreferenceActivity implements OnSharedP
 
     public final static String NAME = "VlcSharedPreferences";
     public final static String LAST_MEDIA = "LastMedia";
+    public final static String VIDEO_RESUME_TIME = "VideoResumeTime";
     public final static int RESULT_RESCAN = RESULT_FIRST_USER + 1;
 
     @Override
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 bc66a0d..8585b08 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -287,6 +287,13 @@ public class VideoPlayerActivity extends Activity {
         mSwitchingView = false;
         mEndReached = false;
 
+        // Clear the resume time, since it is only used for resumes in external
+        // videos.
+        SharedPreferences preferences = getSharedPreferences(PreferencesActivity.NAME, MODE_PRIVATE);
+        SharedPreferences.Editor editor = preferences.edit();
+        editor.putLong(PreferencesActivity.VIDEO_RESUME_TIME, -1);
+        editor.commit();
+
         IntentFilter filter = new IntentFilter();
         filter.addAction(Intent.ACTION_BATTERY_CHANGED);
         filter.addAction(VLCApplication.SLEEP_INTENT);
@@ -360,12 +367,17 @@ public class VideoPlayerActivity extends Activity {
         if (time >= 0) {
             SharedPreferences preferences = getSharedPreferences(PreferencesActivity.NAME, MODE_PRIVATE);
             SharedPreferences.Editor editor = preferences.edit();
-            editor.putString(PreferencesActivity.LAST_MEDIA, mLocation);
+            if(DatabaseManager.getInstance(this).mediaItemExists(mLocation)) {
+                editor.putString(PreferencesActivity.LAST_MEDIA, mLocation);
+                DatabaseManager.getInstance(this).updateMedia(
+                        mLocation,
+                        DatabaseManager.mediaColumn.MEDIA_TIME,
+                        time);
+            } else {
+                // Video file not in media library, store time just for onResume()
+                editor.putLong(PreferencesActivity.VIDEO_RESUME_TIME, time);
+            }
             editor.commit();
-            DatabaseManager.getInstance(this).updateMedia(
-                    mLocation,
-                    DatabaseManager.mediaColumn.MEDIA_TIME,
-                    time);
         }
 
         AudioServiceController.getInstance().unbindAudioService(this);
@@ -1337,11 +1349,21 @@ public class VideoPlayerActivity extends Activity {
             // restore last position
             Media media = DatabaseManager.getInstance(this).getMedia(this, mLocation);
             if(media != null) {
+                // in media library
                 if(media.getTime() > 0 && !fromStart)
                     mLibVLC.setTime(media.getTime());
 
                 mLastAudioTrack = media.getAudioTrack();
                 mLastSpuTrack = media.getSpuTrack();
+            } else {
+                // not in media library
+                SharedPreferences preferences = getSharedPreferences(PreferencesActivity.NAME, MODE_PRIVATE);
+                long rTime = preferences.getLong(PreferencesActivity.VIDEO_RESUME_TIME, -1);
+                SharedPreferences.Editor editor = preferences.edit();
+                editor.putLong(PreferencesActivity.VIDEO_RESUME_TIME, -1);
+                editor.commit();
+                if(rTime > 0)
+                    mLibVLC.setTime(rTime);
             }
 
             try {



More information about the Android mailing list