Commit 6c0a7bb2 authored by Tobias's avatar Tobias Committed by Felix Paul Kühne
Browse files

fix crashing bug when paying a file from a media list

parent cee7085f
...@@ -264,40 +264,13 @@ ...@@ -264,40 +264,13 @@
if (self.fileFromMediaLibrary) if (self.fileFromMediaLibrary)
matchedFile = self.fileFromMediaLibrary; matchedFile = self.fileFromMediaLibrary;
else if (self.mediaList) { else if (self.mediaList) {
/* TODO: move this code to MLKit */ NSURL *url = [self.mediaList mediaAtIndex:self.itemInMediaListToBePlayedFirst].url;
NSString *path = [[[self.mediaList mediaAtIndex:self.itemInMediaListToBePlayedFirst] url] absoluteString]; NSArray *files = [MLFile fileForURL:url];
NSString *componentString = @""; matchedFile = files.firstObject;
NSArray *pathComponents = [path componentsSeparatedByString:@"/"];
NSUInteger componentCount = pathComponents.count;
if ([pathComponents[componentCount - 2] isEqualToString:@"Documents"])
componentString = [path lastPathComponent];
else {
NSUInteger firstElement = [pathComponents indexOfObject:@"Documents"] + 1;
for (NSUInteger x = 0; x < componentCount - firstElement; x++) {
if (x == 0)
componentString = [componentString stringByAppendingFormat:@"%@", pathComponents[firstElement + x]];
else
componentString = [componentString stringByAppendingFormat:@"/%@", pathComponents[firstElement + x]];
}
}
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSManagedObjectContext *moc = [[MLMediaLibrary sharedMediaLibrary] managedObjectContext];
if (moc) {
NSEntityDescription *entity = [NSEntityDescription entityForName:@"File" inManagedObjectContext:moc];
[request setEntity:entity];
[request setPredicate:[NSPredicate predicateWithFormat:@"url CONTAINS %@", componentString]];
NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"title" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)];
[request setSortDescriptors:@[descriptor]];
NSArray *matches = [moc executeFetchRequest:request error:nil];
matchedFile = matches.firstObject;
}
} }
if (matchedFile.lastPosition) if (matchedFile.lastPosition) {
lastPosition = matchedFile.lastPosition.floatValue; lastPosition = matchedFile.lastPosition.floatValue;
}
duration = matchedFile.duration.intValue; duration = matchedFile.duration.intValue;
if (lastPosition < .95) { if (lastPosition < .95) {
if (duration != 0) if (duration != 0)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment