1
0
mirror of https://github.com/mpv-player/mpv synced 2025-04-08 18:53:30 +00:00

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> <key>CFBundleTypeRole</key>
<string>Viewer</string> <string>Viewer</string>
<key>CFBundleURLName</key> <key>CFBundleURLName</key>
<string>Real Time (Streaming) Protocol</string> <string>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>
<key>CFBundleURLSchemes</key> <key>CFBundleURLSchemes</key>
<array> <array>
<string>mms</string> <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> </array>
</dict> </dict>
<dict> <dict>
<key>CFBundleTypeRole</key> <key>CFBundleTypeRole</key>
<string>Viewer</string> <string>Viewer</string>
<key>CFBundleURLName</key> <key>CFBundleURLName</key>
<string>Cuesheet</string> <string>CD/DVD/Bluray Media</string>
<key>CFBundleURLSchemes</key> <key>CFBundleURLSchemes</key>
<array> <array>
<string>cue</string> <string>cdda</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>dvd</string> <string>dvd</string>
<string>vcd</string> <string>vcd</string>
<string>bd</string>
</array> </array>
</dict> </dict>
</array> </array>

View File

@ -97,11 +97,25 @@ static NSString *escape_loadfile_name(NSString *input)
handler:^(NSEvent *event) { handler:^(NSEvent *event) {
return [self.eventsResponder handleKey:event]; return [self.eventsResponder handleKey:event];
}]; }];
NSAppleEventManager *em = [NSAppleEventManager sharedAppleEventManager];
[em setEventHandler:self
andSelector:@selector(getUrl:withReplyEvent:)
forEventClass:kInternetEventClass
andEventID:kAEGetURL];
} }
return self; return self;
} }
- (void)dealloc
{
NSAppleEventManager *em = [NSAppleEventManager sharedAppleEventManager];
[em removeEventHandlerForEventClass:kInternetEventClass
andEventID:kAEGetURL];
[super dealloc];
}
#define _R(P, T, E, K) \ #define _R(P, T, E, K) \
{ \ { \
NSMenuItem *tmp = [self menuItemWithParent:(P) title:(T) \ NSMenuItem *tmp = [self menuItemWithParent:(P) title:(T) \
@ -221,6 +235,22 @@ static NSString *escape_loadfile_name(NSString *input)
[self stopPlayback]; [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 - (void)application:(NSApplication *)sender openFiles:(NSArray *)filenames
{ {
Application *app = mpv_shared_app(); Application *app = mpv_shared_app();