苹果文档似乎表明,在录制视频文件,应用程序可以改变没有问题苍蝇的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换个工作。