Search code examples
iosswiftuiimagepickercontroller

How to store location of selected video from PhotoLibrary


When selecting a video from the Photo Library, iOS compresses the video and stores it in the tmp/ folder. That location is returned as the '.mediaURL' and is used to load the video into an AVPlayer. I am trying to save the location of the selected video so it can be played back later, but I found that the tmp/ url is cleared out at some point after closing the app and reopening it. For music, I can store the 'persistentID' to retrieve the songs later. I have not been able to find a good way to persist the location of the originally selected video so it can be replayed later without having to select it again during the current session. Looking for suggestions.

I am using Swift 5 for iOS.

Thanks...


Solution

  • When you use imagePicker to select a video from gallery , you need to copy it someWhere say inside the documents folder to be able to persistently reference it when you open the app again