Frage

I'm new to Objective-C. Currently I'm trying to execute lame with NSTask. The following code seems to be working because Xcode's output space shows me lame's standardoutput i.e. shows same as lame's output on Terminal.

But I can't get any output file i.e. test.mp3 on my desktop. Why I can't get any output? Is there any wrong with my code?

NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:@"/usr/local/bin/lame"];
[task setArguments:[NSArray arrayWithObjects:@"/Users/xanadu62/Music/test.wav",nil]];
[task setStandardOutput:[NSFileHandle fileHandleForWritingAtPath:@"/Users/xanadu62/Desktop/test.mp3"]];
[task launch];

Also, I'd like to use "--preset extreme" as lame option. But "task setArguments:" doesn't allow to use this option as argument. I'd like to know how can I solve this issue too.

War es hilfreich?

Lösung

Try it this way:

NSTask *task = [[NSTask alloc] init];

[task setLaunchPath:@"/usr/local/bin/lame"];

[task setArguments: [NSArray arrayWithObjects:
                                    @"--preset",
                                    @"extreme",
                                    @"/Users/xanadu62/Music/test.wav",
                                    @"/Users/xanadu62/Desktop/test.mp3", 
                                    nil]
];

[task launch];

You don't need to use pipes.

usage: lame [options] <infile> [outfile]

    <infile> and/or <outfile> can be "-", which means stdin/stdout.

Andere Tipps

Never used lame, but by looking at the docs the correct terminal command would be

"lame --preset extreme /Users/lawrencepires/Desktop/test.mp3 /Users/lawrencepires/Desktop/test1.mp3"

test.mp3 being the input file, test1.mp3 being the output file.

Working Code - (may be worth changing for live output)

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application


[self lameconvert];
}


- (void)lameconvert {

NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:@"/usr/local/bin/lame"];
NSArray *argArray = [NSArray arrayWithObjects:@"--preset",@"extreme",@"/Users/xanadu62/Music/test.wav",@"/Users/xanadu62/Music/test.wav",nil];

[task setArguments:argArray];

[task launch];
[task waitUntilExit];
NSLog(@"Conversion Complete");


}
@end
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top