情景1:
情景2:
文件写入无法在第一次尝试时写出。
UserInfo = {NSLocalizedRecoverySuggestion =再次尝试保存。,NSLocalizedDescription =无法保存,NSUnderlyingError = 0x1c464f3c0 {错误域= NSOSStatusErrorDomain代码= -12412“(null)”}} 2017-10-26 23:25:16.896673-0400 [2135:771655]状态失败!:3错误域= AVFoundationErrorDomain代码= -11823“无法保存”
第二次尝试正常。
我做错了什么?
答案 0 :(得分:0)
添加了重试逻辑来规避问题。不是最好的解决方案,但它有效。
[self.screenRecorder startCaptureWithHandler:^(CMSampleBufferRef _Nonnull sampleBuffer, RPSampleBufferType bufferType, NSError * _Nullable error) {
if(CMSampleBufferDataIsReady(sampleBuffer) == false || self.assetWriter == nil)
{
return;
}
if (self.assetWriter.status == AVAssetWriterStatusFailed) {
NSLog(@"AVWriter Failed!");
return;
}
if (CMSampleBufferDataIsReady(sampleBuffer)) {
if(self.assetWriter.status == AVAssetWriterStatusWriting) {
if (bufferType == RPSampleBufferTypeVideo) {
if (!self.startedSession) {
dispatch_async(dispatch_get_main_queue(), ^{
_startDate = [NSDate date];
_recordingTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(updateRecordingTime) userInfo:nil repeats:YES];
// Disable the idle timer while recording
[UIApplication sharedApplication].idleTimerDisabled = YES;
});
CMTime pts = CMSampleBufferGetPresentationTimeStamp(sampleBuffer);
[self.assetWriter startSessionAtSourceTime:pts];
self.startedSession = YES;
NSLog(@"MP4Writer: started session in appendVideoSample");
}
if (CMTimeCompare(kCMTimeInvalid, self.firstVideoFrameTime) == 0) {
self.firstVideoFrameTime = CMSampleBufferGetPresentationTimeStamp(sampleBuffer);
}
if (self.assetWriterVideoInput.readyForMoreMediaData) {
@try {
[self.assetWriterVideoInput appendSampleBuffer:sampleBuffer];
}
@catch(NSException *expection) {
NSLog(@"Missed Video Buffer: %@", self.assetWriter.error);
}
}
}
if (bufferType == RPSampleBufferTypeAudioMic) {
if (CMTimeCompare(kCMTimeInvalid, self.firstVideoFrameTime) == 0 ||
CMTimeCompare(self.firstVideoFrameTime, CMSampleBufferGetPresentationTimeStamp(sampleBuffer)) == 1) {
return;
}
if (!self.startedSession) {
CMTime pts = CMSampleBufferGetPresentationTimeStamp(sampleBuffer);
[self.assetWriter startSessionAtSourceTime:pts];
self.startedSession = YES;
NSLog(@"MP4Writer: started session in appendAudioSample");
}
if (self.assetWriterAudioInput.isReadyForMoreMediaData) {
@try {
[self.assetWriterAudioInput appendSampleBuffer:sampleBuffer];
}
@catch(NSException *expection) {
NSLog(@"Missed Audio Buffer: %@", self.assetWriter.error);
}
}
}
}
}
} completionHandler:^(NSError * _Nullable error) {
if (!error) {
NSLog(@"Recording started successfully.");
}
}];
答案 1 :(得分:0)
output
15