如何在elcImagePickerController中获取视频的NSData?

时间:2016-09-08 10:39:13

标签: ios objective-c nsurlconnection nsdata elcimagepickercontroller

我想将视频上传到服务器...并使用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;
        } 

1 个答案:

答案 0 :(得分:1)

最后从这里获得解决方案https://stackoverflow.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