如何启动 QuickTime 并让它开始播放 URL?
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
考虑到该 URL 是远程 URL,您可以使用 Cocoa 中的脚本桥应用程序要求 QuickTime Player 打开远程 URL:
您需要将 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:
You’ll need to link the Scripting Bridge framework to your application.