How can I start QuickTime and have it start playing a url?
I'm using MonoMac, but I understand cocoa and objc well enough that if you can answer me in those languages, please do.
I have a url from my web server which returns an mp4. I'd like my MonoMac application to launch QuickTime and start playing that url.
I tried these methods:
Process.Start("/Applications/QuickTime Player.app/Contents/MacOS/QuickTime Player", url);
but when the url is something like http://webhost/1/blah.mp4, quicktime says "The document blah.mp4 could not be opened. The file doesn't exist. I know the file exists and everything is correct. If I use this method:
var cfurl = MonoMac.CoreFoundataion.CFUrl.FromUrlString(url, null);
LSOpenCFURLRef(cfurl.Handle, (IntPtr)null);
The stream is opened in Safari and the QuickTime plugin starts playing it.
I've also tried NSWorkspace OpenUrls and OpenFile
NSWorkspace.SharedWorkspace.OpenUrls(new[]{NSUrl.FromString(url)},
@"com.apple.quicktimeplayer",
NSWorkspaceLaunchOptions.Async,
new NSAppleEventDescriptor(开发者_JAVA技巧),
new[]{""});
but this launches in safari
NSWorkspace.SharedWorkspace.OpenFile(url, "QuickTimePlayer");
but this does nothing.
So I try NSTask
MonoMac.Foundation.NSTask.LaunchFromPath("/Applications/QuickTime Player.app/Contents/MacOS/QuickTime Player",
new string[] {url});
But this gives the same "... could not be found..." as my very first attempt above.
Finally, if I start QuickTime Player and use open URL and paste the url into the textbox and click Open, the stream plays without error.
How can my cocoa app send a URL to QuickTime Player?
Considering the URL is a remote URL, you can use Scripting Bridge in Cocoa applications to ask QuickTime Player to open a remote URL:
id qtApp = [SBApplication applicationWithBundleIdentifier:@"com.apple.QuickTimePlayerX"];
[qtApp activate];
if ([qtApp isRunning]) {
// note that the parameter to openURL: must be the string representation of a URL
[qtApp openURL:@"http://movies.apple.com/media/us/ipad/2011/tours/apple-ipad2-feature-us-20110302_r848-9cie.mov?width=848&height=480"];
}
You’ll need to link the Scripting Bridge framework to your application.
精彩评论