문제

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.

도움이 되었습니까?

해결책

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.

다른 팁

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top