1

我试图录制视频,但我收到了类似的错误

无法记录到 URL <#file url>,因为它不是文件 URL。

我将目标网址定义如下:

NSString *Path = [[NSString alloc] init];
Path = @"/Users/me/Documents/My fols/recording_try/newMovie.mov";
NSURL *dest = [[NSURL alloc] initWithString:[Path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

然后在创建会话后,输入和输出对象。我试过这样录音。

mMovieFileOutput = [[AVCaptureMovieFileOutput alloc] init] ;
[mSession addOutput:mMovieFileOutput];
[mMovieFileOutput startRecordingToOutputFileURL:dest recordingDelegate:self];

我已经开始运行会话,尝试使用 begin 和comitconfiguration 等。但每次运行时都会收到如下错误:

[AVCaptureMovieFileOutput startRecordingToOutputFileURL:recordingDelegate:] - Cannot record to URL /Users/me/Documents/My%20fols/recording_try/newMovie.mov because it is not a file URL.

我不知道我要去哪里错了......有人可以帮忙吗?

提前致谢...

4

2 回答 2

2

只需更改您的 NSURL 配置以符合文件 URL 类型

像这样的东西:

NSURL *dest = [[NSURL alloc] initFileURLWithPath:<#(NSString *)#>]

于 2015-06-29T07:04:42.947 回答
1

尝试这样的事情:

// variable names should start with lower case letters

// also, let's do as much as we can with auto-released objects
// so we don't have to worry about leaking (if we're not using ARC)
NSString *path = [NSString stringWithString: @"/Users/me/Documents/My fols/recording_try"];
NSURL *dest = [NSURL URLWithString:[path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
if(dest == nil)
{
    NSLog( @"does not appear to be a valid NSURL object" );
    return;
}

NSError * error = nil;
if([[NSFileManager defaultManager] createDirectoryAtURL: dest withIntermediateDirectories: YES attributes: nil error: &error] == YES)
{
    dest = [dest URLByAppendingPathComponent: @"newMovie.mov"];

    // now you can create the session plus input and output objects
    // within this block

} else {
    NSLog( @"was not able to create the directory which contains path %@ - error is %@", path, [error localizedDescription] );
}
于 2012-06-05T10:15:36.187 回答