通过ALAsset的方式,无法获取系统相册中文件的具体路径,一般采取的方式是通过ALAssetRepresentation直接获取视频数据,如果还需要一个fileURL的话,可以将视频数据写入自定义fileURL的文件中,示例代码如下:
-(void)assetPickerController:(ZYQAssetPickerController )picker didFinishPickingAssets:(NSArray )assets{
for (ALAsset *asset in assets) {
NSLog(@"HERE\n asset.defaultRepresentation.url = %@\n asset.defaultRepresentation.filename = %@",asset.defaultRepresentation.url, asset.defaultRepresentation.filename);
[self saveVideoToApp:nil asset:asset];
ALAssetRepresentation *representation = asset.defaultRepresentation;
if ([mediaType isEqualToString:ALAssetTypeVideo]) {
long long size = representation.size;
NSMutableData* data = [[NSMutableData alloc] initWithCapacity:size];
void* buffer = [data mutableBytes];
[representation getBytes:buffer fromOffset:0 length:size error:nil];
NSData *fileData = [[NSData alloc] initWithBytes:buffer length:size];
NSString *savePath = [NSString stringWithFormat:@"%@%@", [NSHomeDirectory() stringByAppendingString:@"/tmp/"], representation.filename];
[[NSFileManager defaultManager] removeItemAtPath:savePath error:nil];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
[fileData writeToFile:savePath atomically:NO];
});
}
}
}