Browse Source

x-callback-url: added support for the x-error parameter (closes #14092)

Felix Paul Kühne 10 years ago
parent
commit
5280088a09
3 changed files with 20 additions and 13 deletions
  1. 13 10
      Sources/VLCAppDelegate.m
  2. 1 0
      Sources/VLCMovieViewController.h
  3. 6 3
      Sources/VLCMovieViewController.m

+ 13 - 10
Sources/VLCAppDelegate.m

@@ -187,26 +187,27 @@
             // vlc-x-callback://x-callback-url/action?param=value&x-success=callback
             APLog(@"x-callback-url with host '%@' path '%@' parameters '%@'", url.host, url.path, url.query);
             NSString *action = [url.path stringByReplacingOccurrencesOfString:@"/" withString:@""];
-            NSURL *movieURL = nil;
-            NSURL *successCallback = nil;
-            NSString *fileName = nil;
+            NSURL *movieURL;
+            NSURL *successCallback;
+            NSURL *errorCallback;
+            NSString *fileName;
             for (NSString *entry in [url.query componentsSeparatedByString:@"&"]) {
                 NSArray *keyvalue = [entry componentsSeparatedByString:@"="];
                 if (keyvalue.count < 2) continue;
                 NSString *key = keyvalue[0];
                 NSString *value = [keyvalue[1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
-                if ([key isEqualToString:@"url"]) {
+
+                if ([key isEqualToString:@"url"])
                     movieURL = [NSURL URLWithString:value];
-                }
-                else if ([key isEqualToString:@"filename"]) {
+                else if ([key isEqualToString:@"filename"])
                     fileName = value;
-                }
-                else if ([key isEqualToString:@"x-success"]) {
+                else if ([key isEqualToString:@"x-success"])
                     successCallback = [NSURL URLWithString:value];
-                }
+                else if ([key isEqualToString:@"x-error"])
+                    errorCallback = [NSURL URLWithString:value];
             }
             if ([action isEqualToString:@"stream"] && movieURL) {
-                [self openMovieFromURL:movieURL successCallback:successCallback];
+                [self openMovieFromURL:movieURL successCallback:successCallback errorCallback:errorCallback];
             }
             else if ([action isEqualToString:@"download"] && movieURL) {
                 [self downloadMovieFromURL:movieURL fileNameOfMedia:fileName];
@@ -490,12 +491,14 @@
 
 - (void)openMovieFromURL:(NSURL *)url
          successCallback:(NSURL *)successCallback
+           errorCallback:(NSURL *)errorCallback
 {
     if (!_movieViewController)
         _movieViewController = [[VLCMovieViewController alloc] initWithNibName:nil bundle:nil];
 
     _movieViewController.url = url;
     _movieViewController.successCallback = successCallback;
+    _movieViewController.errorCallback = errorCallback;
 
     UINavigationController *navCon = [[VLCPlaybackNavigationController alloc] initWithRootViewController:_movieViewController];
     navCon.modalPresentationStyle = UIModalPresentationFullScreen;

+ 1 - 0
Sources/VLCMovieViewController.h

@@ -87,6 +87,7 @@
 @property (nonatomic, strong) MLFile *fileFromMediaLibrary;
 @property (nonatomic, strong) NSURL *url;
 @property (nonatomic, strong) NSURL *successCallback;
+@property (nonatomic, strong) NSURL *errorCallback;
 @property (nonatomic, strong) NSString *pathToExternalSubtitlesFile;
 @property (nonatomic, retain) VLCMediaList *mediaList;
 @property (nonatomic, readwrite) int itemInMediaListToBePlayedFirst;

+ 6 - 3
Sources/VLCMovieViewController.m

@@ -95,6 +95,7 @@ typedef NS_ENUM(NSInteger, VLCPanType) {
     UIDatePicker *_sleepTimeDatePicker;
 
     NSInteger _mediaDuration;
+    BOOL _playbackFailed;
 }
 
 @property (nonatomic, strong) UIPopoverController *masterPopoverController;
@@ -1065,10 +1066,11 @@ typedef NS_ENUM(NSInteger, VLCPanType) {
 
     [self setControlsHidden:NO animated:NO];
     [self.navigationController dismissViewControllerAnimated:YES completion:^{
-        // switch back to the caller when user presses "Done"
-        if (self.successCallback && [sender isKindOfClass:[UIBarButtonItem class]]) {
+        // switch back to the caller when user presses "Done" or playback fails
+        if (self.successCallback && [sender isKindOfClass:[UIBarButtonItem class]])
             [[UIApplication sharedApplication] openURL:self.successCallback];
-        }
+        else if (self.errorCallback && _playbackFailed)
+            [[UIApplication sharedApplication] openURL:self.errorCallback];
     }];
 }
 
@@ -1174,6 +1176,7 @@ typedef NS_ENUM(NSInteger, VLCPanType) {
 
     if (currentState == VLCMediaPlayerStateError) {
         [self.statusLabel showStatusMessage:NSLocalizedString(@"PLAYBACK_FAILED", nil)];
+        _playbackFailed = YES;
         [self performSelector:@selector(closePlayback:) withObject:nil afterDelay:2.];
     }