Forráskód Böngészése

VLC for iOS improved x-callback-url implementation

Signed-off-by: Felix Paul Kühne <fkuehne@videolan.org>
Ulrich Trampe 10 éve
szülő
commit
007954411d
2 módosított fájl, 25 hozzáadás és 7 törlés
  1. 19 1
      Sources/VLCAppDelegate.m
  2. 6 6
      Sources/VLCMovieViewController.m

+ 19 - 1
Sources/VLCAppDelegate.m

@@ -142,6 +142,7 @@
             NSString *action = [url.path stringByReplacingOccurrencesOfString:@"/" withString:@""];
             NSURL *movieURL = nil;
             NSURL *successCallback = nil;
+            NSString *fileName = nil;
             for (NSString *entry in [url.query componentsSeparatedByString:@"&"]) {
                 NSArray *keyvalue = [entry componentsSeparatedByString:@"="];
                 if (keyvalue.count < 2) continue;
@@ -150,6 +151,9 @@
                 if ([key isEqualToString:@"url"]) {
                     movieURL = [NSURL URLWithString:value];
                 }
+                else if ([key isEqualToString:@"filename"]) {
+                    fileName = value;
+                }
                 else if ([key isEqualToString:@"x-success"]) {
                     successCallback = [NSURL URLWithString:value];
                 }
@@ -157,6 +161,9 @@
             if ([action isEqualToString:@"stream"] && movieURL) {
                 [self openMovieFromURL:movieURL successCallback:successCallback];
             }
+            else if ([action isEqualToString:@"download"] && movieURL) {
+                [self downloadMovieFromURL:movieURL fileNameOfMedia:fileName];
+            }
         } else {
             NSString *receivedUrl = [url absoluteString];
             if ([receivedUrl length] > 6) {
@@ -184,7 +191,7 @@
                 VLCAlertView *alert = [[VLCAlertView alloc] initWithTitle:NSLocalizedString(@"OPEN_STREAM_OR_DOWNLOAD", nil) message:url.absoluteString cancelButtonTitle:NSLocalizedString(@"BUTTON_DOWNLOAD", nil) otherButtonTitles:@[NSLocalizedString(@"BUTTON_PLAY", nil)]];
                 alert.completion = ^(BOOL cancelled, NSInteger buttonIndex) {
                     if (cancelled)
-                        [[self downloadViewController] addURLToDownloadList:url fileNameOfMedia:nil];
+                        [self downloadMovieFromURL:url fileNameOfMedia:nil];
                     else
                         [self openMovieFromURL:url];
                 };
@@ -411,6 +418,17 @@
         [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
 }
 
+#pragma mark - download handling
+
+- (void)downloadMovieFromURL:(NSURL *)url
+             fileNameOfMedia:(NSString *)fileName
+{
+    [self.downloadViewController addURLToDownloadList:url fileNameOfMedia:fileName];
+
+    // select Downloads menu item and reveal corresponding viewcontroller
+    [self.menuViewController selectRowAtIndexPath:[NSIndexPath indexPathForRow:2 inSection:1] animated:NO scrollPosition:UITableViewScrollPositionNone];
+}
+
 #pragma mark - playback view handling
 
 - (void)openMediaFromManagedObject:(NSManagedObject *)mediaObject

+ 6 - 6
Sources/VLCMovieViewController.m

@@ -905,12 +905,12 @@
 - (IBAction)closePlayback:(id)sender
 {
     [self setControlsHidden:NO animated:NO];
-    [self.navigationController dismissViewControllerAnimated:YES completion:nil];
-
-    // switch back to the caller when user presses "Done"
-    if (self.successCallback && [sender isKindOfClass:[UIBarButtonItem class]]) {
-        [[UIApplication sharedApplication] openURL:self.successCallback];
-    }
+    [self.navigationController dismissViewControllerAnimated:YES completion:^{
+        // switch back to the caller when user presses "Done"
+        if (self.successCallback && [sender isKindOfClass:[UIBarButtonItem class]]) {
+            [[UIApplication sharedApplication] openURL:self.successCallback];
+        }
+    }];
 }
 
 - (IBAction)positionSliderAction:(UISlider *)sender