[Android] Save time instead of progress percentage

Geoffrey Métais git at videolan.org
Tue Feb 6 16:20:27 CET 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Feb  6 16:17:23 2018 +0100| [d4670c11850a346d0e9d22a3be99530d4a111856] | committer: Geoffrey Métais

Save time instead of progress percentage

Fix imprecise resume points

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

 medialibrary/jni/utils.cpp                                          | 4 +++-
 vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java | 2 +-
 vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt           | 4 ++--
 3 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/medialibrary/jni/utils.cpp b/medialibrary/jni/utils.cpp
index 3c29739d5..a5a0da341 100644
--- a/medialibrary/jni/utils.cpp
+++ b/medialibrary/jni/utils.cpp
@@ -68,7 +68,9 @@ mediaToMediaWrapper(JNIEnv* env, fields *fields, medialibrary::MediaPtr const& m
     unsigned int height = hasVideoTracks ? videoTracks.at(0)->height() : 0;
     int64_t duration = mediaPtr->duration();
     const medialibrary::IMediaMetadata& progressMeta = mediaPtr->metadata( medialibrary::IMedia::MetadataType::Progress );
-    int64_t progress = progressMeta.isSet() ? duration * ( progressMeta.integer() / 100.0 ) : 0;
+    int64_t progress = progressMeta.isSet() ? progressMeta.integer() : 0;
+    // workaround to convert legacy percentage progress
+    if (progress != 0 && progress < 100) progress = duration * ( progress / 100.0 );
     const medialibrary::IMediaMetadata& seenMeta =  mediaPtr->metadata( medialibrary::IMedia::MetadataType::Seen );
     int64_t seen = seenMeta.isSet() ? seenMeta.integer() : 0;
 
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 106bdef2b..c71688b05 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -3096,7 +3096,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
                         media = mMedialibrary.getMedia(mUri);
                     }
                     if (media != null && media.getId() != 0L && media.getTime() == 0L)
-                        media.setTime((long) (media.getMetaLong(MediaWrapper.META_PROGRESS) * (double) media.getLength())/100L);
+                        media.setTime(media.getMetaLong(MediaWrapper.META_PROGRESS));
                 } else
                     media = openedMedia;
                 if (media != null) {
diff --git a/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt b/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
index 8467aed9e..8d391e517 100644
--- a/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -368,7 +368,7 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
                 progress = 0f
             }
             media.time = if (progress == 0f) 0L else time
-            media.setLongMeta(MediaWrapper.META_PROGRESS, (progress * 100).toLong())
+            media.setLongMeta(MediaWrapper.META_PROGRESS, media.time)
         }
         if (canSwitchToVideo) {
             //Save audio delay
@@ -535,7 +535,7 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
             if (mw.length <= 0L && length > 0L) {
                 mw = medialibrary.findMedia(mw)
                 if (mw.id != 0L) {
-                    mw.time = (mw.getMetaLong(MediaWrapper.META_PROGRESS) * length.toDouble()).toLong() / 100L
+                    mw.time = mw.getMetaLong(MediaWrapper.META_PROGRESS)
                     if (mw.time > 0L) player.seek(mw.time)
                 }
             }



More information about the Android mailing list