在我的應用程序中,我需要從模擬器獲取視頻,我需要上傳到server.can任何一個幫助me.Please儘快提供任何解決方案。如何從ios中的應用程序中的圖像庫中獲取視頻
感謝&問候 T.swathi
在我的應用程序中,我需要從模擬器獲取視頻,我需要上傳到server.can任何一個幫助me.Please儘快提供任何解決方案。如何從ios中的應用程序中的圖像庫中獲取視頻
感謝&問候 T.swathi
首先,創建一個的UIImagePickerController
在你的類,你將需要實現UIImagePickerControllerDelegate協議,並將其連接起來,以對選擇器的委託財產。一旦用戶選擇了某項內容,您應該能夠獲取從didFinishPickingMediaWithInfo中選擇的媒體位置。
//檢查iOS設備不是在模擬器
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// this is the file system url of the media
NSURL* videoUrl = [info objectForKey:UIImagePickerControllerMediaURL];
// TODO: read in data at videoUrl and write upload it to your server
}
imagePicker = [[UIImagePickerController alloc] init]; imagePicker.delegate = self; imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; imagePicker.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie,nil]; 此委託方法不調用然後我創建UIImagepicker的方式如下 – user3092286
你宣佈你的代表在.h文件中
是的,我在.h文件中decalred – user3092286
使用此功能可幫助全
-(void)selectVideoButtonClicked:(id)sender{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie, nil];
[self presentViewController:imagePicker animated:YES completion:nil];
}
,並採取「UIImagePickerControllerDelegate」 &和進口框架delege和使用委託函數挑來自庫的視頻
MobileCoreServices.framework首先在項目中導入,然後導入文件CoreServ之後冰/ CoreServices.h
- (void) imagePickerController: (UIImagePickerController *) picker didFinishPickingMediaWithInfo: (NSDictionary *) info {
NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
// Handle a movie capture
if (CFStringCompare ((CFStringRef) mediaType, kUTTypeMovie, 0)
== kCFCompareEqualTo) {
NSString *moviePath = [[info objectForKey: UIImagePickerControllerMediaURL] path];
NSLog(@" Video Path %@",moviePath);
NSString *fileName = [[NSString alloc]init];
//If you wants get File Name Then you can use this
if ([moviePath rangeOfString:@"//"].location != NSNotFound) {
NSString *separatorString = @"//";
NSArray *disSplit = [moviePath componentsSeparatedByString:separatorString];
fileName = disSplit[1] ;
// [self videoUploadingDirect:moviePath];
}
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath)) {
UISaveVideoAtPathToSavedPhotosAlbum (moviePath, nil, nil, nil);
}
}
[self dismissViewControllerAnimated:YES completion:nil];
}
謝謝:)
[的UIImagePickerController](http://developer.apple.com/library/ios/#documentation/uikit/reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html ) –