如何启动 QuickTime 并让它开始播放 URL?

发布于 2024-10-31 01:25:43 字数 1525 浏览 0 评论 0原文

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

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

我尝试了这些方法:

Process.Start("/Applications/QuickTime Player.app/Contents/MacOS/QuickTime Player", 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 粘贴到文本框中并单击“打开”,则流播放不会出现错误。

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

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(),
                                     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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

-黛色若梦 2024-11-07 01:25:43

考虑到该 URL 是远程 URL,您可以使用 Cocoa 中的脚本桥应用程序要求 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 框架链接到您的应用程序。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文