iPhone:使用ALAssetsLibrary枚举时如何获取视频文件二进制文件? [英] iPhone: How to get Video file binary when using ALAssetsLibrary enumeration?

查看:55
本文介绍了iPhone:使用ALAssetsLibrary枚举时如何获取视频文件二进制文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过ALAssetsLibrary访问iPhone的相册库.我可以成功访问相册并获取设备上每个图像的资源URL.我的测试是,在获取所有图像之后,将其上传到我的Web服务器也可以正常工作.我也在尝试获取视频文件并执行相同的过程,即将视频文件上传到我的服务器.这是问题所在,我不知道如何像使用UIImageJPEGRepresentation那样对视频指针二进制文件进行访问,并发送给我的HTTP代码?

I am trying to access iPhone's photo album gallery through ALAssetsLibrary. I am successful accessing the photo album and get the asset URL of each images on the device. My testing is, after getting all the images, uploading to my web server is also working well. I am also trying to get the video file and do the same process, i.e. upload video file to my server. Here is the issue, i don't know how to access video pointer binary like how i did for images using UIImageJPEGRepresentation, and send to my HTTP code?

-(void) assetsEmumeration {


void (^assetEnumerator)(struct ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) {
        if(result != NULL) {
            NSLog(@"See Asset: %@", result);
            [assetArray addObject:result];
            // get image url
            NSURL *url = [[result defaultRepresentation] url];
            NSString *urlInStr = [NSString stringWithFormat:@"%@",url];

            NSData *imgData = UIImageJPEGRepresentation ([UIImage imageWithCGImage:[result thumbnail]], 90);

            HttpUpload (imgData);
        }
    };

    void (^assetGroupEnumerator)(struct ALAssetsGroup *, BOOL *) =  ^(ALAssetsGroup *group, BOOL *stop) 
    {

        if(group != nil) {
            [group enumerateAssetsUsingBlock:assetEnumerator];
        }
        [self.activity stopAnimating];
        [self.activity setHidden:YES];
    };
    assetLibrary = [[ALAssetsLibrary alloc] init];
    [assetLibrary enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos
                           usingBlock:assetGroupEnumerator
                         failureBlock: ^(NSError *error) {
                             NSLog(@"Failure: %@", [error localizedDescription]);
                         }];
    assetArray = [[NSMutableArray array] retain]; 

}

有人能解决这个问题吗,请指导我!

Could someone came across this to solve, please guide me!

推荐答案

您可以使用ALAssetRepresentation的

You can get the raw bytes using ALAssetRepresentation's getBytes:fromOffset:length:error: method, something like this:

uint8_t *bytes = malloc([representation size]);
NSError *error = nil;
NSUInteger length = [representation getBytes:bytes fromOffset:0 length:[representation size] error:&error];

这篇关于iPhone:使用ALAssetsLibrary枚举时如何获取视频文件二进制文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆