diff options
author | Stefano Pigozzi <stefano.pigozzi@gmail.com> | 2013-09-07 11:49:04 +0200 |
---|---|---|
committer | Stefano Pigozzi <stefano.pigozzi@gmail.com> | 2013-09-07 12:10:29 +0200 |
commit | b0797e8fe99bf5eb0b399ad2a57b62e8f0c71fed (patch) | |
tree | 0d0428c26ab1d50262060059b16d23ef174a4aa9 /osdep/macosx_application.m | |
parent | ae64f29930e1fc86b8abd3b71a1335912511e751 (diff) | |
download | mpv-b0797e8fe99bf5eb0b399ad2a57b62e8f0c71fed.tar.bz2 mpv-b0797e8fe99bf5eb0b399ad2a57b62e8f0c71fed.tar.xz |
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.
Diffstat (limited to 'osdep/macosx_application.m')
-rw-r--r-- | osdep/macosx_application.m | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/osdep/macosx_application.m b/osdep/macosx_application.m index fb20fbf2cc..7c5990d912 100644 --- a/osdep/macosx_application.m +++ b/osdep/macosx_application.m @@ -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(); |