如何在 elcImagePickerController 中获取视频的 NSData?
Posted
技术标签:
【中文标题】如何在 elcImagePickerController 中获取视频的 NSData?【英文标题】:How to get NSData of video in elcImagePickerController? 【发布时间】:2016-09-08 10:39:13 【问题描述】:我想将视频上传到服务器...并且正在使用 elcImagePickerController 来选择多个/单个视频
但是在
- (void)elcImagePickerController:(ELCImagePickerController *)picker didFinishPickingMediaWithInfo:(NSArray *)info
方法没有获取 UIImagePickerControllerMediaURL 来获取数据..
那么如何获取视频数据发送到服务器呢?
这是我的代码
if ([dict objectForKey:UIImagePickerControllerOriginalImage])
UIImage* image=[dict objectForKey:UIImagePickerControllerOriginalImage];
[images addObject:image];
NSURL *imagePath = [dict objectForKey:UIImagePickerControllerReferenceURL];
NSString *imageName = [imagePath lastPathComponent];
[imgNames addObject:imageName];
UIImageView *imageview = [[UIImageView alloc] initWithImage:image];
[imageview setContentMode:UIViewContentModeScaleAspectFit];
imageview.frame = workingFrame;
[_scrollView addSubview:imageview];
workingFrame.origin.x = workingFrame.origin.x + workingFrame.size.width;
【问题讨论】:
this post may help!! 否 :( 只能显示视频/图像但无法获取视频的 NSData... ***.com/questions/33189012/… 在 didFinishPickingMediaWithInfo 中没有得到 UIImagePickerControllerMediaURL ... 而是得到 UIImagePickerControllerReferenceURL ... @Larme 我建议使用原生UIImagePickerController
。它有足够的方法来完成任何类型的任务,并且易于实现。无需使用第三方进行媒体采摘!!
【参考方案1】:
终于从这里得到了解决方案https://***.com/a/10799693/6011616
ALAssetsLibrary *assetLibrary=[[ALAssetsLibrary alloc] init];
[assetLibrary assetForURL:[NSURL URLWithString:videoLink] resultBlock:^(ALAsset *asset)
ALAssetRepresentation *rep = [asset defaultRepresentation];
Byte *buffer = (Byte*)malloc(rep.size);
NSUInteger buffered = [rep getBytes:buffer fromOffset:0.0 length:rep.size error:nil];
NSData *data = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES];
NSLog(@"%@",data); //this is what I was expecting
【讨论】:
以上是关于如何在 elcImagePickerController 中获取视频的 NSData?的主要内容,如果未能解决你的问题,请参考以下文章