macosx_application: handle URL events as fileopen events

This allows to open URLs directly with mpv. This is useful for streaming and
libquvi supported sites.
This commit is contained in:
Stefano Pigozzi 2013-09-07 11:49:04 +02:00
parent ae64f29930
commit b0797e8fe9
2 changed files with 42 additions and 38 deletions

View File

@ -190,57 +190,31 @@
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>CFBundleURLName</key>
<string>Real Time (Streaming) Protocol</string>
<key>CFBundleURLSchemes</key>
<array>
<string>rtp</string>
<string>rtsp</string>
</array>
</dict>
<dict>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>CFBundleURLName</key>
<string>File over HTTP/FTP/UDP</string>
<key>CFBundleURLSchemes</key>
<array>
<string>icyx</string>
<string>udp</string>
<string>ftp</string>
<string>http_proxy</string>
<string>http</string>
</array>
</dict>
<dict>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>CFBundleURLName</key>
<string>Microsoft Media Services</string>
<string>Streaming Protocol</string>
<key>CFBundleURLSchemes</key>
<array>
<string>mms</string>
<string>mmst</string>
<string>http</string>
<string>httpproxy</string>
<string>rtp</string>
<string>rtsp</string>
<string>ftp</string>
<string>udp</string>
<string>smb</string>
</array>
</dict>
<dict>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>CFBundleURLName</key>
<string>Cuesheet</string>
<string>CD/DVD/Bluray Media</string>
<key>CFBundleURLSchemes</key>
<array>
<string>cue</string>
</array>
</dict>
<dict>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>CFBundleURLName</key>
<string>CD/DVD Media</string>
<key>CFBundleURLSchemes</key>
<array>
<string>dvdnav</string>
<string>cdda</string>
<string>dvd</string>
<string>vcd</string>
<string>bd</string>
</array>
</dict>
</array>

View File

@ -97,11 +97,25 @@ static NSString *escape_loadfile_name(NSString *input)
handler:^(NSEvent *event) {
return [self.eventsResponder handleKey:event];
}];
NSAppleEventManager *em = [NSAppleEventManager sharedAppleEventManager];
[em setEventHandler:self
andSelector:@selector(getUrl:withReplyEvent:)
forEventClass:kInternetEventClass
andEventID:kAEGetURL];
}
return self;
}
- (void)dealloc
{
NSAppleEventManager *em = [NSAppleEventManager sharedAppleEventManager];
[em removeEventHandlerForEventClass:kInternetEventClass
andEventID:kAEGetURL];
[super dealloc];
}
#define _R(P, T, E, K) \
{ \
NSMenuItem *tmp = [self menuItemWithParent:(P) title:(T) \
@ -221,6 +235,22 @@ static NSString *escape_loadfile_name(NSString *input)
[self stopPlayback];
}
- (void)getUrl:(NSAppleEventDescriptor *)event
withReplyEvent:(NSAppleEventDescriptor *)replyEvent
{
NSString *url =
[[event paramDescriptorForKeyword:keyDirectObject] stringValue];
self.files = @[url];
if (self.willStopOnOpenEvent) {
self.willStopOnOpenEvent = NO;
cocoa_stop_runloop();
} else {
[self handleFiles];
}
}
- (void)application:(NSApplication *)sender openFiles:(NSArray *)filenames
{
Application *app = mpv_shared_app();