How to launch QuickTime from a Mac App

RobertDalyRobertDaly Robert DalyUSMember ✭✭

Hi Anyone!

I have been trying to launch QuickTime from my app and I am able to launch it successfully. However, I want it to play an audio file and I have not been having any success with it.
I found an objective-c example below and am able to make use of some of it (namely the first two lines - see my code below)

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

My Code:
SBApplication app; // Reference to an app

            app = SBApplication.FromBundleIdentifier("com.apple.QuickTimePlayerX"); // Get it
            app.Activate(); // And activate it

This code launches successfully QuickTime, but I don't know how to use the openURL: to have QuickTime play the audio file. I made sure it runs properly outside of my app (directly with QuickTime) and I have tried a number of things to get it to work. Shown below is what I have tried:

            NSUrl url = new NSUrl(lblImagePath.StringValue);

            Selector sel = new Selector("openURL:");

            SBApplication app; 

            app = SBApplication.FromBundleIdentifier("com.apple.QuickTimePlayerX");
            app.Activate();
            if(app.IsRunning) {
                app.PerformSelector(sel,url,0);

            }

This results in a message from QuickTime: The movie “sample_both.mp3” can’t be opened because the file is not in a format that QuickTime Player understands. The file may be damaged or may not be a movie file...

If anyone can assist, I would be most grateful!

Bob

Posts

  • DavidLilleyDavidLilley David Lilley USMember ✭✭✭

    It seems a complicated way to go, Perhaps the way to go is..

    https://developer.apple.com/library/mac/documentation/cocoa/reference/applicationkit/classes/nsworkspace_class/reference/reference.html

    eg..
    NSWorkspace.SharedWorkspace.OpenUrl(aURL); (opens a web browsers)
    or
    NSWorkspace.SharedWorkspace.OpenFile(sPath, sAppName);

  • RobertDalyRobertDaly Robert Daly USMember ✭✭

    Hi David,

    Many thanks! I just discovered the same thing last night at the following link:
    http://pastebin.com/4nfh24DB (in the Raw output shown below). The only one that worked was the NSWorkspace.SharedWorkspace.OpenFile(url, "QuickTimePlayer"); with modification - "QuickTimePlayer" should be "QuickTime Player.app" and the url has to be a string, not a NSUrl.
    Additionally, the qtApp area below (SBApplication does not have the openURL method in Xamarin. My code is simply as follows:

                NSWorkspace.SharedWorkspace.OpenFile(mediaFile[0],"QuickTime Player.app");
    

    And this works fine!

    Thanks again!

    Bob

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

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

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

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

    MonoMac.Foundation.NSTask.LaunchFromPath("/Applications/QuickTime Player.app/Contents/MacOS/QuickTime Player",
    new string[] {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"];
    }

    =====================

Sign In or Register to comment.