[vlc-commits] macosx: fix resume playback guards, do not resume for folder urls
David Fuhrmann
git at videolan.org
Sun Oct 19 23:08:44 CEST 2014
vlc | branch: master | David Fuhrmann <dfuhrmann at videolan.org> | Sun Oct 19 23:00:05 2014 +0200| [b2525ebf7c3658d72963def5d9ac5b7627ac3b4c] | committer: David Fuhrmann
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.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=b2525ebf7c3658d72963def5d9ac5b7627ac3b4c
---
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