[英]How can I use UTIs to get a list of video files in a directory that are playable by AVPlayer?
我一直在嘗試找出如何在 swift 中的 macOS 上使用 UTI(統一類型標識符),但找不到任何東西。 有誰知道我如何使用 UTI 獲取 AVPlayer 可播放的目錄中的視頻文件列表?
使用 Hiroki Kato 的 UTIKit ( https://github.com/cockscomb/UTIKit ):
let dir = URL(fileURLWithPath: "./your_dir_here")
let mimeTypes = AVURLAsset.audiovisualMIMETypes()
let playableUtis = mimeTypes.map { UTI(mimeType: $0)! }
let dirContents = try! FileManager.default.contentsOfDirectory(at: dir, includingPropertiesForKeys: nil, options: [.skipsHiddenFiles])
let movies = dirContents.filter { UTI("public.movie") ~= UTI(filenameExtension: $0.pathExtension) }
let playableMovies = movies.filter {
guard let movieUti = UTI(filenameExtension: $0.pathExtension) else {
return false
}
return playableUtis.contains(movieUti)
}
現在playableMovies
僅包含可由AVPlayer
播放的電影文件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.