I have an app that uses the front camera and the microphone to record a video. I have tried it on an iPhone 4S with iOS 6, iPad 2 iPhone 5 and iPhone 5S with iOS 7, and the video is recorded and played correctly.
But on an iPhone 4 with iOS 7.0.4 sometimes there's a black screen with audio, and sometimes there's the video but without any audio.
When this bug appears, any other app on the iPhone will record just a black screen or will record video without audio. I have to restart the iPhone 4 in order to try to record again.
Is this a bug on iOS 7, or is it a problem with my code? Have anyone experienced this as well?
Here's the recording code:
- (void)setupSession {
AVCaptureSession *session = [[AVCaptureSession alloc] init];
[session beginConfiguration];
// Recording in low resolution to boost up video capturing on lower-end devices
if ([session canSetSessionPreset:AVCaptureSessionPresetMedium]) {
session.sessionPreset = AVCaptureSessionPresetMedium;
NSLog(@"%@", session.sessionPreset);
}
if (!self.frontCamera || !self.microphone) {
NSLog(@"Unable to start recording session");
return;
}
// Adding camera capturing input
NSError *error;
AVCaptureDeviceInput *cameraInput = [AVCaptureDeviceInput deviceInputWithDevice:self.frontCamera
error:&error];
if (!cameraInput) {
NSLog(@"Couldn't retrieve camera input: %@", [error localizedDescription]);
return;
}
// Adding audio capturing input
error = nil;
AVCaptureDeviceInput *audioInput = [AVCaptureDeviceInput deviceInputWithDevice:self.microphone
error:&error];
if (error) {
NSLog(@"Couldn't retrive camera input: %@", [error localizedDescription]);
return;
}
if ([session canAddInput:cameraInput] && [session canAddInput:audioInput]) {
[session addInput:cameraInput];
[session addInput:audioInput];
} else {
NSLog(@"Session input could not be added");
}
// Adding movie file output
AVCaptureMovieFileOutput *movieFileOutput = [[AVCaptureMovieFileOutput alloc] init];
if ([session canAddOutput:movieFileOutput]) {
[session addOutput:movieFileOutput];
self.movieFileOutput = movieFileOutput;
} else {
return;
NSLog(@"Session output could not be added");
}
AVCaptureConnection *videoConnection = movieFileOutput.connections[0];
if ([videoConnection isVideoOrientationSupported]) {
videoConnection.videoOrientation = AVCaptureVideoOrientationLandscapeLeft;
}
// Listen for notifications
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(receivedCaptureSessionNotification:)
name:nil
object:session];
_session = session;
[session commitConfiguration];
self.canRecord = YES;
}`
And this is my dealloc:
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self
name:AVPlayerItemDidPlayToEndTimeNotification
object:self.session];
if ([self.session isRunning]) {
for(AVCaptureInput *input1 in self.session.inputs) {
[self.session removeInput:input1];
}
for(AVCaptureOutput *output1 in self.session.outputs) {
[self.session removeOutput:output1];
}
[self.session stopRunning];
}
self.session=nil;
NSLog(@"gamerecording dealloc'd");
}
I was logging my session inputs on dealloc, and the mic and front camera are always listed.
If more information is needed, I can include it.