Post

Replies

Boosts

Views

Activity

Reply to SwiftUI - How to load a video from Photos
Okay i just fixed it by myself. If anybody comes across this and has the same problem: You first have to copy the video to your APP storage. Well at least that's what it made it work for me. In your Picker do something like this after receiving the URL from the picker. I always thought the videoplayer could just play the Video from the given URL. It can't. In my picker delegate method: 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) // copy item to APP Storage                 try? FileManager.default.copyItem(at: url, to: newUrl)                 self.parent.videoURL = newUrl.absoluteString             }         } be sure to remove any gestures on VideoView (my longpressgesture messed with the standard interactions given by the AVPlayer)
Jan ’22