-->

连续通话startRecordingToOutputFileURL:(Consecutive cal

2019-07-29 16:21发布

苹果文档似乎表明,在录制视频文件,应用程序可以改变没有问题苍蝇的URL。 但我看到的一个问题。 当我尝试这一点,记录代表被调用有错误...

操作couldn,Äôt完成。 (OSStatus错误-12780。)信息字典是:{AVErrorRecordingSuccessfullyFinishedKey = 0; } }

(在时髦单引号“不能”来自测井[错误localizedDescription])

下面的代码,这基本上是调整,以WWDC10 AVCam示例:

1)开始记录。 启动定时器来改变输出URL每隔几秒钟

- (void) startRecording
{
    // start the chunk timer
    self.chunkTimer = [NSTimer scheduledTimerWithTimeInterval:5
                                                       target:self
                                                     selector:@selector(chunkTimerFired:)
                                                     userInfo:nil
                                                      repeats:YES];

    AVCaptureConnection *videoConnection = [AVCamCaptureManager connectionWithMediaType:AVMediaTypeVideo fromConnections:[[self movieFileOutput] connections]];
    if ([videoConnection isVideoOrientationSupported]) {
        [videoConnection setVideoOrientation:[self orientation]];
    }

    if ([[UIDevice currentDevice] isMultitaskingSupported]) {
        [self setBackgroundRecordingID:[[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{}]];
    }

    NSURL *fileUrl = [[ChunkManager sharedInstance] nextURL];
    NSLog(@"now recording to %@", [fileUrl absoluteString]);
    [[self movieFileOutput] startRecordingToOutputFileURL:fileUrl recordingDelegate:self];
}

2)当计时器触发,而不停止记录更改输出文件名

- (void)chunkTimerFired:(NSTimer *)aTimer {

    if ([[UIDevice currentDevice] isMultitaskingSupported]) {
        [self setBackgroundRecordingID:[[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{}]];
    }

    NSURL *nextUrl = [self nextURL];
    NSLog(@"changing capture output to %@", [[nextUrl absoluteString] lastPathComponent]);

    [[self movieFileOutput] startRecordingToOutputFileURL:nextUrl recordingDelegate:self];
}

注:自nextURL]生成文件URL像file-0.mov,file-5.mov,file-10.mov等。

3)它获得每次文件更改叫,和所有其他的调用是错误的...

- (void)              captureOutput:(AVCaptureFileOutput *)captureOutput
didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL
                    fromConnections:(NSArray *)connections
                              error:(NSError *)error
{
    id delegate = [self delegate];
    if (error && [delegate respondsToSelector:@selector(someOtherError:)]) {
        NSLog(@"got an error, tell delegate");
        [delegate someOtherError:error];
    }

    if ([self backgroundRecordingID]) {
        if ([[UIDevice currentDevice] isMultitaskingSupported]) {
            [[UIApplication sharedApplication] endBackgroundTask:[self backgroundRecordingID]];
        }
        [self setBackgroundRecordingID:0];
    }

    if ([delegate respondsToSelector:@selector(recordingFinished)]) {
        [delegate recordingFinished];
    }
}

当这个运行时,文件0被写入,那么我们会看到错误-12780变化到文件-5的URL之后,文件10被写入,那么一个错误,那么好吧,等等。

它的出现,改变在运行的URL不工作,但它停止写作,让下一个URL换个工作。

Answer 1:

感谢所有,审查和对这个善念。 下面是来自苹果DTS字...

我与我们的AV基金会的工程师说有,绝对是,这种方法是不是做的文件说,它应该的错误(“你不需要调用此方法,而另一个录制过程中之前调用stopRecording”)。 请文件中使用苹果的软件缺陷报告(bug报告http://developer.apple.com/bugreporter/ )让球队进行调查。 确保并在报告中包含的最小的项目。

我已经与苹果提起这是错误11632087



Answer 2:

在文档它说的:

If a file at the given URL already exists when capturing starts, recording to the new file will fail.

你确定你检查nextUrl是不存在的文件名?



Answer 3:

根据该文件,不支持打电话来连续2 startRecordingToOutputFileURL。

你可以看到它在这里

在iOS中,不支持此帧精确的文件交换。 再次调用此方法以避免任何错误之前,你必须调用stopRecording。



文章来源: Consecutive calls to startRecordingToOutputFileURL: