What I need:
-
play a user-picked video from iPhone gallery with my custom playback controls
-
read the video metadata (ex. duration)
-
be able to reopen the video on next app launch
-
do it in the fastest way, even for multi-gigabyte videos
-
don’t deal with access permissions since iOS offers the built in secure photos picker
After trying various approaches, it doesn’t look easy to accomplish all my needs. I found two options:
-
use
PhotosPicker(selection: $selectedVideoItem, matching: .videos)component from swift UI. It providesPhotosPickerItemin result which I handle gettingAVAssetfrom it and passing it to my videoplayer component. Two issues with this approach:-
I need to utilize
selectedVideoItem.itemIdentifierto be able to reopen the video on next app launch, but it isn’t accessible until user grants full access to photos gallery -
PhotosPickerUI doesn’t look consistent – if an error occurs, theselectedVideoItemremains, so opening the picker second time shows it preselected, but it can’t be loaded because of the error
-
-
load the video as a file through
loadFileRepresentation(). This seems to work and I will able to reopen the video on further app launches since it’s stored in a temp file. But I don’t like that the video is actually copied to a file, so I need to take care of it and handle surrounding edge cases (ex. failure on copy, limited storage space).
So, interesting if there’s way to get this stuff working without copying the video to a temp file. Or maybe there’s another option…