连续调用startRecordingToOutputFileURL: [英] Consecutive calls to startRecordingToOutputFileURL:

查看:786
本文介绍了连续调用startRecordingToOutputFileURL:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Apple文档似乎表明,在将视频录制到文件时,应用程序可以动态更改URL,没有任何问题。但我看到了一个问题。当我尝试这个时,录音代表被调用时出错......

The Apple docs seem to indicate that while recording video to a file, the app can change the URL on the fly with no problem. But I'm seeing a problem. When I try this, the recording delegate gets called with an error...


操作无法完成。 (OSStatus错误-12780。)信息
字典是:{
AVErrorRecordingSuccessfullyFinishedKey = 0; }

The operation couldn’t be completed. (OSStatus error -12780.) Info dictionary is: { AVErrorRecordingSuccessfullyFinishedKey = 0; }

(can not中的时髦单引号来自记录[error localizedDescription])

这是代码,基本上是对WWDC10 AVCam样本的调整:

Here's the code, which is basically tweaks to WWDC10 AVCam sample:

1)开始录制。启动计时器每隔几秒更改一次输出网址

- (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];
}

注意:[self nextURL]生成文件网址,如file-0.mov, file-5.mov,file-10.mov等等。

Note: [self nextURL] generates file urls like file-0.mov, file-5.mov, file-10.mov and so on.

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];
    }
}

运行时,会写入file-0,然后我们在将url更改为file-5后立即看到错误-12780,文件-10被写入,然后出现错误,然后就可以了,等等。

When this runs, file-0 gets written, then we see error -12780 right after changing the url to file-5, file-10 gets written, then an error, then okay, and so on.

看来动态更改URL不起作用,但它会停止写入,允许下一个URL更改工作。

It's appears that changing the URL on the fly doesn't work, but it stops the writing which allows the next URL change to work.

任何帮助都将非常感激。

Any help would be much appreciated.

推荐答案

感谢所有人,对此进行了审核和好评。以下是来自Apple DTS的消息...

Thanks all, for the review and good thoughts on this. Here's the word from Apple DTS...


我与我们的AV Foundation工程师交谈过,这绝对是一个错误
in这个方法没有按照文档说的那样做
(你不需要在调用这个方法之前调用stopRecording
而另一个记录正在进行中。)。请使用Apple Bug Reporter( http://developer.apple.com/)提交错误报告
bugreporter /

所以团队可以调查。确保并在报告中包含您的最小
项目。

I spoke with our AV Foundation engineers, and it is definitely a bug in that this method is not doing what the documentation says it should ("You do not need to call stopRecording before calling this method while another recording is in progress."). Please file a bug report using the Apple Bug Reporter (http://developer.apple.com/bugreporter/) so the team can investigate. Make sure and include your minimal project in the report.

我已将此作为错误11632087向Apple提交

I've filed this with Apple as bug 11632087

这篇关于连续调用startRecordingToOutputFileURL:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆