我将创建应用程序,我将用音频录制视频,然后播放。
为此,我在我的代码中使用了AVCaptureManager。
如果视频大约是10秒,那么音频和视频都在播放,并且它正常工作。
但是,如果我录制的视频超过10秒,则只能播放视频(无声播放)。
这是我的代码。
- (void)startRecording
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"/GeneralInstruction"];
NSError *error;
if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath])
[[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:&error]; //Create folder
NSDate *time = [NSDate date];
NSDateFormatter* df = [NSDateFormatter new];
[df setDateFormat:@"ddMMyyyyhhmmss"];
NSString *timeString = [df stringFromDate:time];
NSString *myUniqueNames = [NSString stringWithFormat:@"%@", timeString];
NSString *myUniqueName = [NSString stringWithFormat:@"file://%@/%@.mp4",dataPath, myUniqueNames];
[self.fileOutput startRecordingToOutputFileURL:[NSURL URLWithString:myUniqueName] recordingDelegate:self];
}
之后,当我完成录制时,它会来......
#pragma mark - AVCaptureFileOutputRecordingDelegate
- (void)captureOutput:(AVCaptureFileOutput *)captureOutput
didStartRecordingToOutputFileAtURL:(NSURL *)fileURL
fromConnections:(NSArray *)connections
{
_isRecording = YES;
}
- (void)captureOutput:(AVCaptureFileOutput *)captureOutput
didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL
fromConnections:(NSArray *)connections error:(NSError *)error
{// [self saveRecordedFile:outputFileURL];
_isRecording = NO;
if ([self.delegate respondsToSelector:@selector(didFinishRecordingToOutputFileAtURL:error:)]) {
[self.delegate didFinishRecordingToOutputFileAtURL:outputFileURL error:error];
}
}