Last active
January 30, 2016 16:54
-
-
Save ikekou/5840156 to your computer and use it in GitHub Desktop.
[Objective-C] カメラロールからムービーを選択する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*-------------------------------------------------------------------------------- | |
カメラロールからムービーを選択する | |
--------------------------------------------------------------------------------*/ | |
- (void)chooseMovie{ | |
// フォトライブラリが使えるか確認 | |
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]){ | |
// 使える | |
UIImagePickerController *picker=[[UIImagePickerController alloc]init]; | |
picker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary; | |
picker.mediaTypes=@[(NSString*) kUTTypeMovie ]; // import MobileCoreServices | |
picker.allowsEditing=NO; | |
picker.delegate=self; | |
picker.videoQuality=UIImagePickerControllerQualityTypeHigh; | |
// 開く | |
[self presentViewController:picker animated:YES completion:NULL]; | |
}else{ | |
// 使えない | |
NSLog(@"PhotoLibraryが使えない"); | |
} | |
} | |
/*-------------------------------------------------------------------------------- | |
UIImagePickerControllerで選択されたとき | |
--------------------------------------------------------------------------------*/ | |
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{ | |
NSString *mediaType=[info objectForKey:UIImagePickerControllerMediaType]; | |
if([mediaType isEqualToString:(NSString*)kUTTypeMovie]){ | |
// 動画のURLを取得 | |
NSURL *url=[info objectForKey:UIImagePickerControllerMediaURL]; | |
NSLog(@"%@",url.absoluteString); | |
self.movieURL=url; | |
} | |
// 閉じる | |
[self dismissViewControllerAnimated:YES completion:NULL]; | |
} | |
/*-------------------------------------------------------------------------------- | |
UIImagePickerControllerで選択されなかったとき | |
--------------------------------------------------------------------------------*/ | |
- (void) imagePickerControllerDidCancel:(UIImagePickerController *)picker{ | |
[self dismissViewControllerAnimated:YES completion:NULL]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment