From b0797e8fe99bf5eb0b399ad2a57b62e8f0c71fed Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sat, 7 Sep 2013 11:49:04 +0200 Subject: 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. --- TOOLS/osxbundle/mpv.app/Contents/Info.plist | 46 +++++++---------------------- osdep/macosx_application.m | 30 +++++++++++++++++++ 2 files changed, 40 insertions(+), 36 deletions(-) diff --git a/TOOLS/osxbundle/mpv.app/Contents/Info.plist b/TOOLS/osxbundle/mpv.app/Contents/Info.plist index 4661981803..4c9340d808 100644 --- a/TOOLS/osxbundle/mpv.app/Contents/Info.plist +++ b/TOOLS/osxbundle/mpv.app/Contents/Info.plist @@ -190,57 +190,31 @@ CFBundleTypeRole Viewer CFBundleURLName - Real Time (Streaming) Protocol + Streaming Protocol CFBundleURLSchemes + mms + mmst + http + httpproxy rtp rtsp - - - - CFBundleTypeRole - Viewer - CFBundleURLName - File over HTTP/FTP/UDP - CFBundleURLSchemes - - icyx - udp ftp - http_proxy - http - - - - CFBundleTypeRole - Viewer - CFBundleURLName - Microsoft Media Services - CFBundleURLSchemes - - mms - - - - CFBundleTypeRole - Viewer - CFBundleURLName - Cuesheet - CFBundleURLSchemes - - cue + udp + smb CFBundleTypeRole Viewer CFBundleURLName - CD/DVD Media + CD/DVD/Bluray Media CFBundleURLSchemes - dvdnav + cdda dvd vcd + bd 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(); -- cgit v1.2.3