你好,我需要建立从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
雷给出了相当不错的教程.希望它有所帮助.
雷给出了相当不错的教程.希望它有所帮助.