我想列出所有视频。不仅是照片库中的视频,还有视频应用中的视频,包括电影,电视节目,音乐视频等。
当我像这样使用ALAsset时:
ALAsset *asset = [videoLibrary objectAtIndex:indexPath.row];
videoURL = [[asset defaultRepresentation] url];
[videoURLs addObject:videoURL];
[cell.textLabel setText:[NSString stringWithFormat:@"Video %d", indexPath.row+1]];
[cell.imageView setImage:[UIImage imageWithCGImage:[asset thumbnail]]];
在(UITableViewCell *)tableView:cellForRowAtIndexPath:方法中,只显示照片库中的视频。有没有办法获得所有类型?
提前致谢
答案 0 :(得分:0)
我想您需要检索IOS设备上的所有视频,您可以找到相同in this post的代码
答案 1 :(得分:0)
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0),^ {
NSMutableArray *assetGroups = [[NSMutableArray alloc] init];
NSMutableArray *assetURLDictionaries = [[NSMutableArray alloc] init];
// Process assets
void (^assetEnumerator)(ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) {
if (result != nil) {
if([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypeVideo]){
[assetURLDictionaries addObject:[result valueForProperty:ALAssetPropertyURLs]];
NSURL *url = result.defaultRepresentation.url;
[assetLibrary assetForURL:url
resultBlock:^(ALAsset *asset) {
if (asset) {
@synchronized(assets) {
[systemVideoArray addObject:asset];
[self.mTableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
}
}
}
failureBlock:^(NSError *error){
NSLog(@"operation was not successfull!");
}];
}
}
};