如何启动QuickTime并开始播放URL? [英] How can I start QuickTime and have it start playing a url?

查看:318
本文介绍了如何启动QuickTime并开始播放URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是MonoMac,但我对可可和objc的理解足够好,如果可以用这些语言回答我,请这样做。

I'm using MonoMac, but I understand cocoa and objc well enough that if you can answer me in those languages, please do.

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

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.

我尝试了以下方法:

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

但是当url是 http://webhost/1/blah.mp4 ,quicktime表示无法打开文档blah.mp4。该文件不存在。我知道该文件存在一切正确,如果我使用此方法:

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);

流已打开

我还尝试了NSWorkspace OpenUrls和OpenFile

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");

但这什么也没做。

所以我尝试了NSTask

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.

最后,如果我启动QuickTime Player并使用打开的URL并将URL粘贴到文本框中,然后单击打开,则流将正确播放。

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.

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

How can my cocoa app send a URL to QuickTime Player?

推荐答案

URL是一个远程URL,您可以在Cocoa应用程序中使用脚本桥要求QuickTime Player打开远程URL:

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"];
}

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

You’ll need to link the Scripting Bridge framework to your application.

这篇关于如何启动QuickTime并开始播放URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆