Can't check if the write was successful after maxRecordedDuration

I am trying to create an application that can record video to a file. I used this documentation file as a guide: Apple Documentation . The problem occurs when the length of the video reaches the maximum allowed length. This is how I set the maximum duration:

    self.avOutput = [[AVCaptureMovieFileOutput alloc] init];
    self.avOutput.maxRecordedDuration = CMTimeMake(5 * 20, 20);

      

This method is then called and that's where the problem starts:

- (void)captureOutput:(AVCaptureFileOutput *)captureOutput
    didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL
    fromConnections:(NSArray *)connections
    error:(NSError *)error 
{
    BOOL recordedSuccessfully = YES;
    if ([error code] != noErr) {
        // A problem occurred: Find out if the recording was successful.
        id value = [[error userInfo] objectForKey:AVErrorRecordingSuccessfullyFinishedKey];
        if (value) {
            recordedSuccessfully = [value boolValue];
        }
    }

    // some code...

}

      

So this method call: [[error userInfo] objectForKey:AVErrorRecordingSuccessfullyFinishedKey]

returns nil

as a result and I can't check if the entry is complete.

This is very strange because I haven't found any piece of documentation that covers this particular case. This is what I get when the error log is printed:

(lldb) po error
Error Domain=AVFoundationErrorDomain Code=-11810 "Recording Stopped" UserInfo=0x146443c0 {AVErrorTimeKey=CMTime: {100/20 = 5.000}, NSLocalizedFailureReason=The recording reached the maximum allowable length., NSLocalizedDescription=Recording Stopped, NSUnderlyingError=0x1463edb0 "The operation couldn’t be completed. (OSStatus error -16132.)"}

(lldb) po error.userInfo
{
    AVErrorTimeKey = "CMTime: {100/20 = 5.000}";
    NSLocalizedDescription = "Recording Stopped";
    NSLocalizedFailureReason = "The recording reached the maximum allowable length.";
    NSUnderlyingError = "Error Domain=NSOSStatusErrorDomain Code=-16132 \"The operation couldn\U2019t be completed. (OSStatus error -16132.)\"";
}

      

Can someone help me overcome this problem?

Thank!

+3


source to share


1 answer


Hey, I'm not sure if you have ever found a solution to this problem, but I am talking about it by checking the size of the recorded video as follows using

    @property(nonatomic, strong) NSData *getVideo; 

      

in the following way:



    //At the end of the method above add:

    getVideo = [NSData dataWithContentsOfURL:outputFileURL];
    NSLog(@" size of getVideo %lu in bytes", (unsigned long)getVideo.length);

      

This will check the size of the recorded video. I hope this was helpful. Have you found a better way to resolve this issue? Thank you!

0


source







All Articles