I am capturing video using following code:
UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
ipc.sourceType = UIImagePickerControllerSo
#pragma mark -
#pragma mark File Names and Paths
// Creates the path if it does not exist.
- (void)ensurePathAt:(NSString *)path {
NSFileManager *fm = [NSFileManager defaultManager];
if ( [fm fileExistsAtPath:path] == false ) {
[fm createDirectoryAtPath:path
withIntermediateDirectories:YES
attributes:nil
error:NULL];
}
}
- (NSString *)documentPath {
if ( ! documentPath_ ) {
NSArray *searchPaths =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
documentPath_ = [searchPaths objectAtIndex: 0];
documentPath_=[documentPath_ stringByAppendingPathComponent:@"VideoAlbum"];
[documentPath_ retain];
}
return documentPath_;
}
- (NSString *)audioPath {
if ( ! AudioPath_ ) {
AudioPath_ = [[self documentPath] stringByAppendingPathComponent:@"Demo"];
NSLog(@"%@",AudioPath_);
[AudioPath_ retain];
[self ensurePathAt:AudioPath_];
}
return AudioPath_;
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *type = [info objectForKey:UIImagePickerControllerMediaType];
if ([type isEqualToString:(NSString *)kUTTypeVideo] || [type isEqualToString:(NSString *)kUTTypeMovie])
{
NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
NSData *videoData = [NSData dataWithContentsOfURL:videoURL];
tempPath = [[self audioPath] stringByAppendingFormat:@"/%@.mp4",[NSDate date]];
BOOL success = [videoData writeToFile:tempPath atomically:NO];
NSLog(@"%hhd",success);
}
[[picker presentingViewController] dismissViewControllerAnimated:YES completion:nil];
}