1

我正在使用 MonoMac,但我对 cocoa 和 objc 的理解非常好,如果你能用这些语言回答我,请这样做。

我有一个来自我的网络服务器的 url,它返回一个 mp4。我希望我的 MonoMac 应用程序启动 QuickTime 并开始播放该网址。

我尝试了这些方法:

Process.Start("/Applications/QuickTime Player.app/Contents/MacOS/QuickTime Player", url);

但是当 url 类似于http://webhost/1/blah.mp4时,quicktime 会说“无法打开文档 blah.mp4。该文件不存在。我知道该文件存在并且一切都正确。如果我使用这种方法:

var cfurl = MonoMac.CoreFoundataion.CFUrl.FromUrlString(url, null);
LSOpenCFURLRef(cfurl.Handle, (IntPtr)null);

流在 Safari 中打开,QuickTime 插件开始播放它。

我也试过 NSWorkspace OpenUrls 和 OpenFile

NSWorkspace.SharedWorkspace.OpenUrls(new[]{NSUrl.FromString(url)},
                                     @"com.apple.quicktimeplayer", 
                                     NSWorkspaceLaunchOptions.Async,
                                     new NSAppleEventDescriptor(),
                                     new[]{""});

但这会在 Safari 中启动

 NSWorkspace.SharedWorkspace.OpenFile(url, "QuickTimePlayer");

但这无济于事。

所以我尝试 NSTask

MonoMac.Foundation.NSTask.LaunchFromPath("/Applications/QuickTime Player.app/Contents/MacOS/QuickTime Player",
                                         new string[] {url});

但这给出了与我上面第一次尝试相同的“......找不到......”。

最后,如果我启动 QuickTime Player 并使用打开 URL 并将 URL 粘贴到文本框中并单击打开,则流播放不会出错。

我的可可应用程序如何将 URL 发送到 QuickTime Player?

4

1 回答 1

2

考虑到 URL 是一个远程 URL,您可以使用Cocoa 应用程序中的 Scripting Bridge要求 QuickTime Player 打开一个远程 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"];
}

您需要将 Scripting Bridge 框架链接到您的应用程序。

于 2011-04-07T01:59:44.860 回答