当前位置:  开发笔记 > IOS > 正文

如何在iOS 9目标c中录制iPhone摄像头的视频?

如何解决《如何在iOS9目标c中录制iPhone摄像头的视频?》经验,为你挑选了1个好方法。

你好,我需要建立从iPhone相机录制视频的应用程序.
我在网上搜索,但没有发现它在iOS 9中有效.我从这个git项目得到了这个代码:https: //github.com/versluis/Video-Recorder

此代码打开相机,但不允许我拍摄视频.

- (IBAction)recordButton:(id)sender {

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

    UIImagePickerController *picker = [[UIImagePickerController alloc]init];
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    picker.delegate = self;
    picker.allowsEditing = NO;

    NSArray *mediaTypes = [[NSArray alloc]initWithObjects:(NSString *)kUTTypeMovie, nil];

    picker.mediaTypes = mediaTypes;

    [self presentViewController:picker animated:YES completion:nil];

} else {

    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:nil message:@"I'm afraid there's no camera on this device!" delegate:nil cancelButtonTitle:@"Dang!" otherButtonTitles:nil, nil];
    [alertView show];
    }
}

 - (IBAction)playbackButton:(id)sender {

// pick a video from the documents directory
NSURL *video = [self grabFileURL:@"video.mov"];

// create a movie player view controller
MPMoviePlayerViewController * controller = [[MPMoviePlayerViewController alloc]initWithContentURL:video];
[controller.moviePlayer prepareToPlay];
[controller.moviePlayer play];

// and present it
[self presentMoviePlayerViewControllerAnimated:controller];

}


#pragma mark - Delegate Methods

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {

// user hit cancel
[self dismissViewControllerAnimated:YES completion:nil];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

// grab our movie URL
NSURL *chosenMovie = [info objectForKey:UIImagePickerControllerMediaURL];

// save it to the documents directory
NSURL *fileURL = [self grabFileURL:@"video.mov"];
NSData *movieData = [NSData dataWithContentsOfURL:chosenMovie];
[movieData writeToURL:fileURL atomically:YES];

// save it to the Camera Roll
UISaveVideoAtPathToSavedPhotosAlbum([chosenMovie path], nil, nil, nil);

// and dismiss the picker
[self dismissViewControllerAnimated:YES completion:nil];

}

- (NSURL*)grabFileURL:(NSString *)fileName {

// find Documents directory
NSURL *documentsURL = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];

// append a file name to it
documentsURL = [documentsURL URLByAppendingPathComponent:fileName];

return documentsURL;
}

小智.. 5

雷给出了相当不错的教程.希望它有所帮助.



1> 小智..:

雷给出了相当不错的教程.希望它有所帮助.

推荐阅读
Chloemw
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有