Post

Replies

Boosts

Views

Activity

SwiftUI - How to load a video from Photos
Hello, I'm currently stuck trying to load a Video - previously picked by an PHPicker. In the photos you can see the current Views. The Videoplayer View stays unresponsive but in the first frames when the picker disappears you can see the thumbnail and a play button. What am i doing wrong? Should i load the file differently? This is my Picker: struct VideoPicker: UIViewControllerRepresentable{     @Binding var videoURL:String? func makeUIViewController(context: Context) -> PHPickerViewController {         var config = PHPickerConfiguration()         config.filter = .videos         let picker = PHPickerViewController(configuration: config)         picker.delegate = context.coordinator         return picker     } func updateUIViewController(_ uiViewController: PHPickerViewController, context: Context) {} func makeCoordinator() -> Coordinator {         Coordinator(self)     } class Coordinator:NSObject, PHPickerViewControllerDelegate{ let parent:VideoPicker init(_ parent: VideoPicker){ self.parent = parent } 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 let url = url else {return} self.parent.videoURL = url.absoluteString print(url) print(FileManager.default.fileExists(atPath: url.path)) } } } } I'm totally able to get the URL (local URL - e.g.: file:///private/var/mobile/Containers/Data/Application/22126131-CBF4-4CAF-B943-22540F1096E1/tmp/.com.apple.Foundation.NSItemProvider. ) But for the life of me - the VideoPlayer won't play it: struct VideoView:View{     @Binding var videoURL:String? @Binding var showVideoPicker:Bool     var body: some View{         if let videoURL = videoURL {             VideoPlayer(player: AVPlayer(url: URL(fileURLWithPath:videoURL)))  .frame(width: 100, height: 100, alignment: .center)  .clipShape(RoundedRectangle(cornerRadius: 16)) .onLongPressGesture{ generator.feedback.notificationOccurred(.success) showVideoPicker.toggle() } } else{     Text("...") } } } Maybe somebody can point me in the right direction because in every Tutorial everybody uses stuff that's bundled to play a video. I want to use Videos from the Photos APP (apple). The videoURL is a @State in my ContentView. It gets updated through the VideoPicker. Sorry for the formatting this is my first Post.
4
0
7.7k
Jan ’22