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