如何在 swift 5.0 中使用 PHPickerFilter 仅显示空间视频

问题描述 投票:0回答:1

我想在我的应用程序中打开照片库时仅获取空间视频。我怎样才能实现?

还有一件事,如果我使用照片库选择任何视频,那么如何识别所选视频是否是空间视频?

self.presentPicker(过滤器:.videos)

/// - Tag: PresentPicker
private func presentPicker(filter: PHPickerFilter?) {
    var configuration = PHPickerConfiguration(photoLibrary: .shared())
    
    // Set the filter type according to the user’s selection.
    configuration.filter = filter
    // Set the mode to avoid transcoding, if possible, if your app supports arbitrary image/video encodings.
    configuration.preferredAssetRepresentationMode = .current
    // Set the selection behavior to respect the user’s selection order.
    configuration.selection = .ordered
    // Set the selection limit to enable multiselection.
    configuration.selectionLimit = 1
    
    let picker = PHPickerViewController(configuration: configuration)
    picker.delegate = self
    present(picker, animated: true)
}





func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {
    picker.dismiss(animated: true) {
        // do something on dismiss
    }
    
    guard let provider = results.first?.itemProvider else {return}
    provider.loadFileRepresentation(forTypeIdentifier: "public.movie") { url, error in
        guard error == nil else{
            print(error)
            return
        }
        // receiving the video-local-URL / filepath
        guard let url = url else {return}
        // create a new filename
        let fileName = "\(Int(Date().timeIntervalSince1970)).\(url.pathExtension)"
        // create new URL
        let newUrl = URL(fileURLWithPath: NSTemporaryDirectory() + fileName)
        
        print(newUrl)
        print("===========")

    }
}
ios swift phphotolibrary
1个回答
0
投票

截至 2024 年 4 月,目前不支持此功能。您能做的最好的事情就是过滤视频。

要检查视频是否是空间的,您可以这样做

if let _ = try? await AVURLAsset(url: videoURL).loadTracks(withMediaCharacteristic: .containsStereoMultiviewVideo).first {
  print("Is spatial video")
} else {
  print("Is not a spatial video")
}
© www.soinside.com 2019 - 2024. All rights reserved.