Commit 4543b3be authored by Ulrich Trampe's avatar Ulrich Trampe Committed by Felix Paul Kühne

VLC for iOS implements an URL scheme that confirms to the x-callback-url specification

Signed-off-by: Felix Paul Kühne's avatarFelix Paul Kühne <fkuehne@videolan.org>
parent 11a434c6
......@@ -172,6 +172,16 @@
<string>vlc</string>
</array>
</dict>
<dict>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>CFBundleURLName</key>
<string>x-callback-url</string>
<key>CFBundleURLSchemes</key>
<array>
<string>vlc-x-callback</string>
</array>
</dict>
</array>
<key>CFBundleVersion</key>
<string>2.4.0</string>
......
......@@ -135,6 +135,28 @@
APLog(@"saving the file failed (%li): %@", (long)theError.code, theError.localizedDescription);
[self updateMediaList];
} else if ([url.scheme isEqualToString:@"vlc-x-callback"] || [url.host isEqualToString:@"x-callback-url"]) {
// URL confirmes to the x-callback-url specification
// 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;
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"]) {
movieURL = [NSURL URLWithString:value];
}
else if ([key isEqualToString:@"x-success"]) {
successCallback = [NSURL URLWithString:value];
}
}
if ([action isEqualToString:@"stream"] && movieURL) {
[self openMovieFromURL:movieURL successCallback:successCallback];
}
} else {
NSString *receivedUrl = [url absoluteString];
if ([receivedUrl length] > 6) {
......@@ -410,17 +432,24 @@
}
- (void)openMovieFromURL:(NSURL *)url
successCallback:(NSURL *)successCallback
{
if (!_movieViewController)
_movieViewController = [[VLCMovieViewController alloc] initWithNibName:nil bundle:nil];
_movieViewController.url = url;
_movieViewController.successCallback = successCallback;
UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:_movieViewController];
navCon.modalPresentationStyle = UIModalPresentationFullScreen;
[self.window.rootViewController presentViewController:navCon animated:YES completion:nil];
}
- (void)openMovieFromURL:(NSURL *)url
{
[self openMovieFromURL:url successCallback:nil];
}
- (void)openMediaList:(VLCMediaList *)list atIndex:(int)index
{
if (!_movieViewController)
......
......@@ -90,6 +90,7 @@
@property (nonatomic, strong) MLFile *fileFromMediaLibrary;
@property (nonatomic, strong) NSURL *url;
@property (nonatomic, strong) NSURL *successCallback;
@property (nonatomic, strong) NSString *pathToExternalSubtitlesFile;
@property (nonatomic, retain) VLCMediaList *mediaList;
@property (nonatomic, readwrite) int itemInMediaListToBePlayedFirst;
......
......@@ -906,6 +906,11 @@
{
[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];
}
}
- (IBAction)positionSliderAction:(UISlider *)sender
......
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