How to show only Spatial video using PHPickerFilter in swift 5.0

I want to get only spatial video while open the Photo library in my app. How can I achieve?

One more thing, If I am selecting any video using photo library then how to identify selected video is Spatial Video or not?

self.presentPicker(filter: .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("===========")
            
            // copy item to APP Storage
            //try? FileManager.default.copyItem(at: url, to: newUrl)
           // self.parent.videoURL = newUrl.absoluteString
            
        }
    }`

Replies

There is not currently API to achieve this kind of filter or identification. It'd be great if you could file a Feedback with this kind of detail asking what you are trying to achieve!

  • Thanks for the reply!!

    Now I want to more clarify with you, I want to select only special video from gallery. Is there any specific type is available to identify the Spatial video like UTType.quickTimeMovie.identifier

    if itemProvider.hasItemConformingToTypeIdentifier(UTType.quickTimeMovie.identifier) { progress = itemProvider.loadFileRepresentation(forTypeIdentifier: UTType.quickTimeMovie.identifier) { [weak self] url, error in }

Add a Comment