Wil*_*ill 0 video assets alassetslibrary ios5
所以我有一个应用程序,允许用户录制视频或从他们的照片库中选择视频,然后将视频上传到服务器.录制视频后,我获得了资产的URL.
我尝试使用以下代码将NSData设置为assetURL:
NSString *vidString =[NSString stringWithFormat:@"%@",savedVideoURL];
NSURL *vidURL = [NSURL URLWithString:vidString];
NSData *videoData = [NSData dataWithContentsOfURL:vidURL];
Run Code Online (Sandbox Code Playgroud)
savedVideoURL是录制期间获得的资产URL.资产URL看起来像这样:assets-library://asset/asset.MOV?id=6EB7A04D-3DF8-44E5-A6D8-FD98461AE75E&ext=MOV
当我尝试将NSData设置为该URL时,NSData仍然等于nil.
我无法使用以下解决方案:从ALAsset url iOS获取视频NSData
有没有其他人知道将NSData设置为该资产的URL的方法?
提前致谢!
不要忘记导入:AssetsLibrary/ALAssetRepresentation.h
和代码:
ALAssetsLibrary *assetLibrary=[[ALAssetsLibrary alloc] init];
[assetLibrary assetForURL:YOURURL resultBlock:^(ALAsset *asset) // substitute YOURURL with your url of video
{
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];//this is NSData may be what you want
[data writeToFile:photoFile atomically:YES]; //you can remove this if only nsdata needed
}
failureBlock:^(NSError *err) {
NSLog(@"Error: %@",[err localizedDescription]);
}];
Run Code Online (Sandbox Code Playgroud)