Browse Source

Added vlc:// prefix and handling

Signed-off-by: Felix Paul Kühne <fkuehne@videolan.org>
Luis Fernandes 12 years ago
parent
commit
1742d917d9
2 changed files with 41 additions and 2 deletions
  1. 10 0
      AspenProject/VLC for iOS-Info.plist
  2. 31 2
      AspenProject/VLCAppDelegate.m

+ 10 - 0
AspenProject/VLC for iOS-Info.plist

@@ -155,6 +155,16 @@
 				<string>db-a60fc6qj9zdg7bw</string>
 			</array>
 		</dict>
+		<dict>
+			<key>CFBundleTypeRole</key>
+			<string>Viewer</string>
+			<key>CFBundleURLName</key>
+			<string>VLC</string>
+			<key>CFBundleURLSchemes</key>
+			<array>
+				<string>vlc</string>
+			</array>
+		</dict>
 	</array>
 	<key>CFBundleVersion</key>
 	<string>2.0.2</string>

+ 31 - 2
AspenProject/VLCAppDelegate.m

@@ -83,13 +83,42 @@
             UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"SAVE_FILE", @"") message:[NSString stringWithFormat:NSLocalizedString(@"SAVE_FILE_LONG", @""), url.lastPathComponent] delegate:self cancelButtonTitle:NSLocalizedString(@"BUTTON_CANCEL", @"") otherButtonTitles:NSLocalizedString(@"BUTTON_SAVE", @""), nil];
             _tempURL = url;
             [alert show];
-        } else
-            [_playlistViewController openMovieFromURL:url];
+        } else {
+            NSURL *parsedUrl = [self parseOpenURL:url];
+            [_playlistViewController openMovieFromURL:parsedUrl];
+        }
         return YES;
     }
     return NO;
 }
 
+- (NSURL *)parseOpenURL:(NSURL *)url
+{
+    NSString *receivedUrl = [url absoluteString];
+    if ([receivedUrl length] > 6) {
+        NSString *verifyVlcUrl = [receivedUrl substringToIndex:6];
+        if ([verifyVlcUrl isEqualToString:@"vlc://"]) {
+            NSString *parsedString = [receivedUrl substringFromIndex:6];
+
+            // "url decode" so we can parse http:// links
+            parsedString = [parsedString stringByReplacingOccurrencesOfString:@"+"withString:@" "];
+            parsedString = [parsedString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+
+            // add http:// if nothing is there
+            NSDataDetector *detector = [NSDataDetector dataDetectorWithTypes:(NSTextCheckingTypes)NSTextCheckingTypeLink error:nil];
+            NSUInteger parsedStringLength = [parsedString length];
+            NSUInteger numberOfUrlMatches = [detector numberOfMatchesInString:parsedString options:0 range:NSMakeRange(0, parsedStringLength)];
+            if (numberOfUrlMatches == 0) {
+                parsedString = [@"http://" stringByAppendingString:parsedString];
+            }
+
+            NSURL *targetUrl = [NSURL URLWithString:parsedString];
+            return targetUrl;
+        }
+    }
+    return url;
+}
+
 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
 {
     if (buttonIndex == 1) {