标签:
#import <MobileCoreServices/MobileCoreServices.h>
<UIVideoEditorControllerDelegate>//编辑视频
@property (strong, nonatomic) NSString *pathToRecordedVideo;
- (IBAction)editVideo:(id)sender;
- (IBAction)takePicture:(id)sender { // Make sure camera is available if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] == NO) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Camera Unavailable" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil]; [alert show]; return; } if (self.imagePicker == nil) { self.imagePicker = [[UIImagePickerController alloc] init]; self.imagePicker.delegate = self; self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; self.imagePicker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera]; self.imagePicker.allowsEditing = YES; } [self presentViewController:self.imagePicker animated:YES completion:NULL]; }
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { NSString * mediaType = [info objectForKey: UIImagePickerControllerMediaType]; if (CFStringCompare((__bridge CFStringRef) mediaType, kUTTypeMovie, 0) == kCFCompareEqualTo) { NSString * moviePath = [[info objectForKey: UIImagePickerControllerMediaURL] path];
self.pathToRecordedVideo = moviePath;
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath)) { UISaveVideoAtPathToSavedPhotosAlbum (moviePath, nil, nil, nil); } } UIImage * image = (UIImage *)[info objectForKey:UIImagePickerControllerEditedImage]; UIImageWriteToSavedPhotosAlbum (image, nil, nil , nil); self.imageView.image = image; self.imageView.contentMode = UIViewContentModeScaleAspectFill; [self dismissViewControllerAnimated:YES completion:NULL]; } - (void) imagePickerControllerDidCancel: (UIImagePickerController *) picker { [self dismissViewControllerAnimated:YES completion:NULL]; }
- (IBAction)editVideo:(id)sender
{
if (self.pathToRecordedVideo)
{
UIVideoEditorController *editor = [[UIVideoEditorController alloc] init];
editor.videoPath = self.pathToRecordedVideo;
editor.delegate = self;
[self presentViewController:editor animated:YES completion:NULL];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"No Video Recorded Yet" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil];
[alert show];
}
}
-(void)videoEditorController:(UIVideoEditorController *)editor didSaveEditedVideoToPath:(NSString *)editedVideoPath
{
self.pathToRecordedVideo = editedVideoPath;
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (editedVideoPath))
{
UISaveVideoAtPathToSavedPhotosAlbum (editedVideoPath, nil, nil, nil);
}
[self dismissViewControllerAnimated:YES completion:NULL];
}
-(void)videoEditorControllerDidCancel:(UIVideoEditorController *)editor
{
[self dismissViewControllerAnimated:YES completion:NULL];
}
标签:
原文地址:http://www.cnblogs.com/fengmin/p/5520895.html