ios – Why is it take so lengthy to load a video? SwiftUI VideoPlayer

0
30


I am creating an app the deal with movies, so I am utilizing VideoPlayer and a wrapper to PHPickerViewController. To do this I am coping video file from digicam roll to momentary listing and once I run this app it’s taken 10 seconds to load a 1:52 min video.

That is the code:

import SwiftUI
import PhotosUI
import AVKit

struct ContentView: View {
    @State non-public var isShowingPicker = false
    @State non-public var videoURL: URL?
    
    var physique: some View {
        VStack {
            Button("Choose Video") {
                isShowingPicker = true
            }
            
            if let videoURL = videoURL {
                VideoPlayer(participant: AVPlayer(url: videoURL))
                    .body(peak: 300)
            }
        }
        .sheet(isPresented: $isShowingPicker) {
            PHPickerViewControllerWrapper(videoURL: $videoURL)
        }
    }
}

struct PHPickerViewControllerWrapper: UIViewControllerRepresentable {
    @Binding var videoURL: URL?
    
    func makeUIViewController(context: Context) -> PHPickerViewController {
        var configuration = PHPickerConfiguration()
        configuration.filter = .movies
        configuration.selectionLimit = 1
        
        let picker = PHPickerViewController(configuration: configuration)
        picker.delegate = context.coordinator
        
        return picker
    }
    
    func updateUIViewController(_ uiViewController: PHPickerViewController, context: Context) {}
    
    func makeCoordinator() -> Coordinator {
        Coordinator(self)
    }
    
    class Coordinator: PHPickerViewControllerDelegate {
        let mum or dad: PHPickerViewControllerWrapper
        
        init(_ mum or dad: PHPickerViewControllerWrapper) {
            self.mum or dad = mum or dad
        }
        
        func picker(_ picker: PHPickerViewController, didFinishPicking outcomes: [PHPickerResult]) {
            guard let consequence = outcomes.first else { return }
            
            consequence.itemProvider.loadFileRepresentation(forTypeIdentifier: UTType.film.identifier) { (url, error) in
                guard let url = url else {return}
                let fileName = "(Int(Date().timeIntervalSince1970)).(url.pathExtension)"
                let newUrl = URL(fileURLWithPath: NSTemporaryDirectory() + fileName)
                strive? FileManager.default.linkItem(at: url, to: newUrl)
                DispatchQueue.foremost.async {
                    self.mum or dad.videoURL = newUrl
                    picker.dismiss(animated: true)
                }
            }
        }
    }
}

When the code runs I obtain the folowing messages on console:

2023-05-24 08:01:06.964329-0300 videoLoader[2846:964095] [api] -[CIImage initWithCVPixelBuffer:options:] failed as a result of the buffer is nil.
2023-05-24 08:01:07.041494-0300 videoLoader[2846:964651] [TextIdentificationService] Textual content LID dominant failure: lidInconclusive
2023-05-24 08:01:07.041839-0300 videoLoader[2846:964651] [VisualTranslationService] Visible isTranslatable: NO; not providing translation: lidInconclusive
2023-05-24 08:01:07.080261-0300 videoLoader[2846:964095] [api] -[CIImage initWithCVPixelBuffer:options:] failed as a result of the buffer is nil.
2023-05-24 08:01:08.008267-0300 videoLoader[2846:964651] Metallic API Validation Enabled

Any concepts on find out how to enhance efficiency on that?

Tips on how to do away with these messages?