【发布时间】:2021-01-12 13:01:31
【问题描述】:
我正在使用以下代码从 iPhone 的相册中获取视频的 URL。 然后我可以在应用程序中打开任何我想要的,但是 我找不到类似的方法来处理图像。 :(
var videoList: [String] = []
var videoListURL: [NSURL] = []
// Gets all the video file list from phone library
func fetchAllVideos() {
videoListURL.removeAll()
videoList.removeAll()
let fetchOptions = PHFetchOptions()
fetchOptions.predicate = NSPredicate(format: "mediaType = %d ", PHAssetMediaType.video.rawValue )
let allVideo = PHAsset.fetchAssets(with: .video, options: fetchOptions)
allVideo.enumerateObjects { (asset, index, bool) in
let imageManager = PHCachingImageManager()
let options = PHVideoRequestOptions()
options.isNetworkAccessAllowed = false
imageManager.requestAVAsset(forVideo: asset,
options: options,
resultHandler: { [self] (video, audioMix, info) in
guard let video2 = video as? AVURLAsset
else {return}
let urlVideo = video2.url
videoListURL.append(urlVideo as NSURL)
var names = urlVideo.lastPathComponent
if names.contains("MOV") {
names.removeLast(4)
self.videoList.append(names)
}
})
}
}
【问题讨论】:
标签: ios swift fetch photo-gallery