|
@@ -45,6 +45,7 @@
|
|
|
|
|
|
@property (nonatomic, strong) dispatch_queue_t videoRecordQueue;
|
|
|
|
|
|
+@property (nonatomic, assign) BOOL isChangeSession;
|
|
|
|
|
|
@end
|
|
|
|
|
@@ -167,34 +168,40 @@
|
|
|
}
|
|
|
|
|
|
- (void)resetSession {
|
|
|
- if (_ignoreAudio == NO) {
|
|
|
- [_captureSession beginConfiguration];
|
|
|
- if (_audioCaptureDeviceInput) {
|
|
|
- [_captureSession removeInput:_audioCaptureDeviceInput];
|
|
|
- }
|
|
|
-
|
|
|
- NSError *error = nil;
|
|
|
- // 获取音频输入对象
|
|
|
- AVCaptureDevice *audioCaptureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
|
|
|
- _audioCaptureDeviceInput = [[AVCaptureDeviceInput alloc] initWithDevice:audioCaptureDevice error:&error];
|
|
|
- if (error) {
|
|
|
- if (self.callback) {
|
|
|
- self.callback(NO, @"获取音频设备输入出错!");
|
|
|
+ if ([_captureSession isRunning]) {
|
|
|
+ if (_ignoreAudio == NO) {
|
|
|
+ [_captureSession beginConfiguration];
|
|
|
+ self.isChangeSession = YES;
|
|
|
+ if (_audioCaptureDeviceInput) {
|
|
|
+ [_captureSession removeInput:_audioCaptureDeviceInput];
|
|
|
}
|
|
|
- return;
|
|
|
- }
|
|
|
- if ([_captureSession canAddInput:_audioCaptureDeviceInput]) {
|
|
|
- [_captureSession addInput:_audioCaptureDeviceInput];
|
|
|
- }
|
|
|
- else {
|
|
|
- if (self.callback) {
|
|
|
- self.callback(NO, @"麦克风被占用!");
|
|
|
+
|
|
|
+ NSError *error = nil;
|
|
|
+ // 获取音频输入对象
|
|
|
+ AVCaptureDevice *audioCaptureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
|
|
|
+ _audioCaptureDeviceInput = [[AVCaptureDeviceInput alloc] initWithDevice:audioCaptureDevice error:&error];
|
|
|
+ if (error) {
|
|
|
+ if (self.callback) {
|
|
|
+ self.callback(NO, @"获取音频设备输入出错!");
|
|
|
+ }
|
|
|
+ return;
|
|
|
}
|
|
|
+ if ([_captureSession canAddInput:_audioCaptureDeviceInput]) {
|
|
|
+ [_captureSession addInput:_audioCaptureDeviceInput];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ if (self.callback) {
|
|
|
+ self.callback(NO, @"麦克风被占用!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ [_captureSession commitConfiguration];
|
|
|
+ self.isChangeSession = NO;
|
|
|
}
|
|
|
-
|
|
|
- [_captureSession commitConfiguration];
|
|
|
}
|
|
|
- [self startSession];
|
|
|
+ else {
|
|
|
+ [self startSession];
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
@@ -209,7 +216,7 @@
|
|
|
}
|
|
|
|
|
|
- (void)stopSession {
|
|
|
- if (_captureSession) {
|
|
|
+ if (_captureSession && _isChangeSession == NO) {
|
|
|
@weakObj(self);
|
|
|
dispatch_async(self.videoRecordQueue, ^{
|
|
|
@strongObj(self);
|
|
@@ -223,6 +230,8 @@
|
|
|
|
|
|
- (void)startRecord {
|
|
|
if (_captureMovieFileOutput) {
|
|
|
+ [self clearVideoFile];
|
|
|
+
|
|
|
// 开始录制
|
|
|
[self.captureMovieFileOutput startRecordingToOutputFileURL:[NSURL fileURLWithPath:[self getRecordFilePath]] recordingDelegate:self];
|
|
|
}
|
|
@@ -391,10 +400,14 @@
|
|
|
}
|
|
|
|
|
|
- (void)clearVideoFile {
|
|
|
- if (self.videoFileURL) {
|
|
|
- [self removeVideoWithPath:self.videoFileURL.path];
|
|
|
- self.videoFileURL = nil;
|
|
|
+ if (_isRecording) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ NSURL *fileUrl = [NSURL fileURLWithPath:[self getRecordFilePath]];
|
|
|
+ if (fileUrl) {
|
|
|
+ [self removeVideoWithPath:fileUrl.path];
|
|
|
}
|
|
|
+ self.videoFileURL = nil;
|
|
|
}
|
|
|
|
|
|
// 上传视频
|