修复:空间拍摄--》选择照片图库--》过滤非空间照片、非空间视频等资源
This commit is contained in:
parent
2429df6010
commit
1aac7eff5f
@ -219,37 +219,44 @@ class CCSpaceAlbumFliterPopView: UIView {
|
||||
|
||||
self.allAssetItemModelArr.removeAll()
|
||||
self.listCollectView.reloadData()
|
||||
if selectedFileType == .image {
|
||||
|
||||
if selectedFileType == .image {
|
||||
let fetchImageResult = PHAsset.fetchAssets(with:.image, options: fetchOptions)
|
||||
fetchImageResult.enumerateObjects(options: .reverse) { asset, index, stop in
|
||||
fetchImageResult.enumerateObjects(options: .reverse) { asset, index, stop in
|
||||
|
||||
//这里是同步的
|
||||
let imageData = self.getImageData(for: asset)
|
||||
let photoImage:UIImage = UIImage(data: imageData!)!
|
||||
//创建model
|
||||
let model = CCSpaceAlbumFliterModel.initWithAssetType(assetType: AssetType.image, asset: asset,image:photoImage, localIdentifier: asset.localIdentifier)
|
||||
//加入数组
|
||||
self.allAssetItemModelArr.append(model)
|
||||
let frameCount = self.getFrameCount(for: asset)
|
||||
if frameCount > 1 {
|
||||
//这里是同步的
|
||||
let imageData = self.getImageData(for: asset)
|
||||
let photoImage:UIImage = UIImage(data: imageData!)!
|
||||
//创建model
|
||||
let model = CCSpaceAlbumFliterModel.initWithAssetType(assetType: AssetType.image, asset: asset,image:photoImage, localIdentifier: asset.localIdentifier)
|
||||
//加入数组
|
||||
self.allAssetItemModelArr.append(model)
|
||||
}
|
||||
}
|
||||
self.listCollectView.reloadData()
|
||||
|
||||
}else if selectedFileType == .video {
|
||||
|
||||
let fetchVideoResult = PHAsset.fetchAssets(with:.video, options: fetchOptions)
|
||||
fetchVideoResult.enumerateObjects(options: .reverse) { asset, index, stop in
|
||||
self.listCollectView.reloadData()
|
||||
}
|
||||
else if selectedFileType == .video {
|
||||
|
||||
self.getVideoURL(from: asset) { [self] url in
|
||||
let firstFrameImage:UIImage = self.getVideoFirstFrame(url: url)
|
||||
//创建model
|
||||
let model = CCSpaceAlbumFliterModel.initWithAssetType(assetType: AssetType.video, asset: asset,image:firstFrameImage, localIdentifier: asset.localIdentifier)
|
||||
//加入数组
|
||||
self.allAssetItemModelArr.append(model)
|
||||
DispatchQueue.main.async { [self] in
|
||||
listCollectView.reloadData()
|
||||
}
|
||||
}
|
||||
}
|
||||
let fetchVideoResult = PHAsset.fetchAssets(with:.video, options: fetchOptions)
|
||||
fetchVideoResult.enumerateObjects(options: .reverse) { asset, index, stop in
|
||||
|
||||
self.getVideoURL(from: asset) { [self] url, avasset in
|
||||
let isSpaceVideo = self.isSpatialVideo(asset:avasset)
|
||||
if isSpaceVideo {
|
||||
let firstFrameImage:UIImage = self.getVideoFirstFrame(url: url)
|
||||
//创建model
|
||||
let model = CCSpaceAlbumFliterModel.initWithAssetType(assetType: AssetType.video, asset: asset,image:firstFrameImage, localIdentifier: asset.localIdentifier)
|
||||
//加入数组
|
||||
self.allAssetItemModelArr.append(model)
|
||||
DispatchQueue.main.async { [self] in
|
||||
listCollectView.reloadData()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -307,7 +314,7 @@ class CCSpaceAlbumFliterPopView: UIView {
|
||||
|
||||
|
||||
//MARK: - 获取视频url
|
||||
private func getVideoURL(from asset: PHAsset, completion: @escaping (URL) -> Void) {
|
||||
private func getVideoURL(from asset: PHAsset, completion: @escaping (URL,AVURLAsset) -> Void) {
|
||||
if asset.mediaType == .video {
|
||||
let requestOptions = PHVideoRequestOptions()
|
||||
requestOptions.isNetworkAccessAllowed = true
|
||||
@ -315,7 +322,7 @@ class CCSpaceAlbumFliterPopView: UIView {
|
||||
PHImageManager.default().requestAVAsset(forVideo: asset, options: requestOptions) { (avAsset, _, _) in
|
||||
if let avAsset = avAsset as? AVURLAsset {
|
||||
let mediaURL = avAsset.url
|
||||
completion(mediaURL)
|
||||
completion(mediaURL,avAsset)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -443,12 +450,12 @@ extension CCSpaceAlbumFliterPopView:UICollectionViewDataSource, UICollectionView
|
||||
cell.imageView.image = model.image
|
||||
|
||||
if model.assetType == .image {
|
||||
let frameCount = getFrameCount(for: model.itemAsset!)
|
||||
if frameCount <= 1 {
|
||||
cell.frameCountLabel.text = "普通"
|
||||
}else{
|
||||
// let frameCount = getFrameCount(for: model.itemAsset!)
|
||||
// if frameCount <= 1 {
|
||||
// cell.frameCountLabel.text = "普通"
|
||||
// }else{
|
||||
cell.frameCountLabel.text = "空间"
|
||||
}
|
||||
// }
|
||||
|
||||
|
||||
|
||||
@ -502,7 +509,7 @@ extension CCSpaceAlbumFliterPopView:UICollectionViewDataSource, UICollectionView
|
||||
}
|
||||
}else if asset.mediaType == .video {
|
||||
//选择的是video
|
||||
self.getVideoURL(from: asset) { url in
|
||||
self.getVideoURL(from: asset) { url,avasset in
|
||||
|
||||
if Thread.isMainThread {
|
||||
self.hide()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user