I have never used UIVideoEditorController so I am not sure where to start with it.
I want the view controller to pop up when the user selects a video in my collection view cell.
I already know the URL of the video, so I just need someone to show me how to properly present the view controller.
This is my code so far
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let video = videosArray[indexPath.row]
The video variable is the video i want to allow them to edit
Try this:
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let video = videosArray[indexPath.row] // videosArray is a list of URL instances
if UIVideoEditorController.canEditVideo(atPath: video.path) {
let editController = UIVideoEditorController()
editController.videoPath = video.path
editController.delegate = self
present(editController, animated:true)
}
}
Also you need to add UIVideoEditorControllerDelegate
methods for dismissing presented video editor controller:
extension YourViewController: UIVideoEditorControllerDelegate {
func videoEditorController(_ editor: UIVideoEditorController,
didSaveEditedVideoToPath editedVideoPath: String) {
dismiss(animated:true)
}
func videoEditorControllerDidCancel(_ editor: UIVideoEditorController) {
dismiss(animated:true)
}
func videoEditorController(_ editor: UIVideoEditorController,
didFailWithError error: Error) {
print("an error occurred: \(error.localizedDescription)")
dismiss(animated:true)
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With