大家好,又见面了,我是全栈君。
1、检索音视频
PHFetchOptions *allPhotosOptions;
@property (nonatomic, strong) PHFetchResult *assetsFetchResults;
if (allPhotosOptions == nil) {
allPhotosOptions = [[PHFetchOptions alloc] init];
allPhotosOptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:YES]];
}
self.assetsFetchResults = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:allPhotosOptions];
当中assetsFetchResults存储了全部的图片信息。PHAssetMediaTypeImage为搜索图片的类型。相同的搜索其它类的能够依据
typedef NS_ENUM(NSInteger, PHAssetMediaType) { PHAssetMediaTypeUnknown = 0, PHAssetMediaTypeImage = 1, PHAssetMediaTypeVideo = 2, PHAssetMediaTypeAudio = 3, } NS_ENUM_AVAILABLE_IOS(8_0);
2、获取图片UIImage
[[PHCachingImageManager defaultManager] requestImageForAsset:asset targetSize:AssetGridThumbnailSize contentMode:PHImageContentModeAspectFill options:nil resultHandler:^(UIImage *result, NSDictionary *info) { // Set the cell's thumbnail image if it's still showing the same asset. if ([cell.representedAssetIdentifier isEqualToString:asset.localIdentifier]) { cell.thumbnailImage = result; } }];
asset为assetsFetchResults中的一个PHAsset,targetSize是获取图片的大小,这个依据你显示的方式设置,假设须要获取图片其它信息比方标题能够採用
[phAsset valueForKey:@"filename"];
3、播放视频
-(void)setVideoAsset:(PHAsset *)videoAsset
{
_videoAsset = videoAsset;
[[PHImageManager defaultManager] requestPlayerItemForVideo:_videoAsset options:nil resultHandler:^(AVPlayerItem * _Nullable playerItem, NSDictionary * _Nullable info) {
self.currentItem = playerItem;
[self.player replaceCurrentItemWithPlayerItem:self.currentItem];
[self.currentItem addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionNew context:nil];
}];
}
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/108313.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...