[vlc-commits] macosx: extract a helper to test if the position should be saved

Mikhail Gusarov git at videolan.org
Wed Sep 25 20:17:34 CEST 2019


vlc | branch: master | Mikhail Gusarov <dottedmag at dottedmag.net> | Thu Sep 19 14:33:51 2019 +0000| [08f4413550de4912f6b5f3f67976898944e254ca] | committer: Felix Paul Kühne

macosx: extract a helper to test if the position should be saved

This refactoring is a prerequisite for the next commit that improves the
decision for long video files.

Signed-off-by: Felix Paul Kühne <felix at feepk.net>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=08f4413550de4912f6b5f3f67976898944e254ca
---

 .../macosx/playlist/VLCPlaybackContinuityController.m   | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/modules/gui/macosx/playlist/VLCPlaybackContinuityController.m b/modules/gui/macosx/playlist/VLCPlaybackContinuityController.m
index 3bfefa4815..f0b02643ba 100644
--- a/modules/gui/macosx/playlist/VLCPlaybackContinuityController.m
+++ b/modules/gui/macosx/playlist/VLCPlaybackContinuityController.m
@@ -240,6 +240,16 @@
                                 completionBlock:completionBlock];
 }
 
+static const int64_t MinimumDuration = 3 * 60 * 1000;
+static const float MinimumStorePercent = 0.5;
+static const float MaximumStorePercent = 0.95;
+
+BOOL ShouldStorePlaybackPosition(float position, int64_t duration)
+{
+    return duration > MinimumDuration &&
+        position > MinimumStorePercent && position < MaximumStorePercent;
+}
+
 - (void)storePlaybackPositionForItem:(VLCInputItem *)inputItem
                               player:(VLCPlayerController *)playerController
 {
@@ -262,9 +272,8 @@
         [self storeLegacyPlaybackPositionForInputItem:inputItem withPlayer:playerController];
     }
 
-    float position = playerController.position;
-    if (position > .05 && position < .95 && libraryMediaItem.duration > 180000) {
-        libraryMediaItem.lastPlaybackPosition = position;
+    if (ShouldStorePlaybackPosition(playerController.position, libraryMediaItem.duration)) {
+        libraryMediaItem.lastPlaybackPosition = playerController.position;
     }
 }
 
@@ -281,7 +290,7 @@
     NSMutableArray *mediaList = [[defaults objectForKey:@"recentlyPlayedMediaList"] mutableCopy];
     NSString *mrl = inputItem.MRL;
 
-    if (relativePos > .05 && relativePos < .95 && dur > 180) {
+    if (ShouldStorePlaybackPosition(relativePos, dur*1000)) {
         msg_Dbg(getIntf(), "Store current playback position of %f", relativePos);
         [mutDict setObject:[NSNumber numberWithInteger:pos] forKey:inputItem.MRL];
 



More information about the vlc-commits mailing list