[vlc-commits] macosx: fix resume playback guards, do not resume for folder urls

David Fuhrmann git at videolan.org
Mon Oct 20 18:38:40 CEST 2014


vlc/vlc-2.2 | branch: master | David Fuhrmann <dfuhrmann at videolan.org> | Sun Oct 19 23:00:05 2014 +0200| [56ccd7532f4cb9c5378500adca9e936578059c34] | committer: Felix Paul Kühne

macosx: fix resume playback guards, do not resume for folder urls

Folder URLs are likely DVD or bluray folders, which cannot be resumed
properly. Also fixes memleak, and unify guards. Do not save position
for input items which we do not resume afterwards anyway.

(cherry picked from commit b2525ebf7c3658d72963def5d9ac5b7627ac3b4c)
Signed-off-by: Felix Paul Kühne <fkuehne at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.2.git/?a=commit;h=56ccd7532f4cb9c5378500adca9e936578059c34
---

 modules/gui/macosx/playlist.m |   46 ++++++++++++++++++++++++++++++-----------
 1 file changed, 34 insertions(+), 12 deletions(-)

diff --git a/modules/gui/macosx/playlist.m b/modules/gui/macosx/playlist.m
index 88c97b2..9189e6f 100644
--- a/modules/gui/macosx/playlist.m
+++ b/modules/gui/macosx/playlist.m
@@ -1476,6 +1476,30 @@
     [o_arrayToSave release];
 }
 
+- (BOOL)isValidResumeItem:(input_item_t *)p_item
+{
+    char *psz_url = input_item_GetURI(p_item);
+    NSString *o_url_string = toNSStr(psz_url);
+    free(psz_url);
+
+    if ([o_url_string isEqualToString:@""])
+        return NO;
+
+    NSURL *o_url = [NSURL URLWithString:o_url_string];
+
+    if (![o_url isFileURL])
+        return NO;
+
+    BOOL isDir = false;
+    if (![[NSFileManager defaultManager] fileExistsAtPath:[o_url path] isDirectory:&isDir])
+        return NO;
+
+    if (isDir)
+        return NO;
+
+    return YES;
+}
+
 - (void)continuePlaybackWhereYouLeftOff:(input_thread_t *)p_input_thread
 {
     NSDictionary *recentlyPlayedFiles = [[NSUserDefaults standardUserDefaults] objectForKey:@"recentlyPlayedMedia"];
@@ -1491,17 +1515,16 @@
             return;
         }
 
+        /* check for file existance before resuming */
+        if (![self isValidResumeItem:p_item])
+            return;
+
         char *psz_url = decode_URI(input_item_GetURI(p_item));
         if (!psz_url)
             return;
-
-        NSString *url = [NSString stringWithUTF8String:psz_url ? psz_url : ""];
+        NSString *url = toNSStr(psz_url);
         free(psz_url);
 
-        /* check for file existance before resuming */
-        if (![[NSFileManager defaultManager] fileExistsAtPath:[[NSURL URLWithString:[NSString stringWithUTF8String:input_item_GetURI(p_item)]] path]])
-            return;
-
         NSNumber *lastPosition = [recentlyPlayedFiles objectForKey:url];
         if (lastPosition && lastPosition.intValue > 0) {
             vlc_value_t pos;
@@ -1543,15 +1566,14 @@
     if (!p_item)
         return;
 
-    char *psz_url = decode_URI(input_item_GetURI(p_item));
-    NSString *url = [NSString stringWithUTF8String:psz_url ? psz_url : ""];
-    free(psz_url);
-
-    if (url.length < 1)
+    if (![self isValidResumeItem:p_item])
         return;
 
-    if ([url rangeOfString:@"file://" options:NSCaseInsensitiveSearch].location != 0)
+    char *psz_url = decode_URI(input_item_GetURI(p_item));
+    if (!psz_url)
         return;
+    NSString *url = toNSStr(psz_url);
+    free(psz_url);
 
     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
     NSMutableDictionary *mutDict = [[NSMutableDictionary alloc] initWithDictionary:[defaults objectForKey:@"recentlyPlayedMedia"]];



More information about the vlc-commits mailing list