Документы Apple, по-видимому, указывают на то, что при записи видео в файл приложение может изменять URL на лету без проблем. Но я вижу проблему. Когда я это пробую, делегат записи вызывается с ошибкой...
Операция не может быть завершена. (Ошибка OSStatus -12780.) Информация словарь: { AVErrorRecordingSuccessfullyFinishedKey = 0; }
(фанковая одиночная цитата в "не может" происходит от регистрации [error localizedDescription])
Здесь код, который является в основном твиком для WWDC10 AVCam sample:
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];
}
Примечание. [self nextURL] генерирует файлы, такие как 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 сразу после изменения URL-адреса в файл-5, записывается файл-10, затем ошибка, затем все в порядке и т.д.
Похоже, что изменение URL-адреса "на лету" не работает, но оно останавливает запись, которая позволяет работать с следующим URL-адресом.
Любая помощь будет высоко оценена.