Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to present UIVideoEditorController [closed]

Tags:

ios

swift

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

like image 774
Michael Jajou Avatar asked Jul 23 '17 00:07

Michael Jajou


1 Answers

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)
    }
}
like image 145
ninjaproger Avatar answered Sep 18 '22 01:09

ninjaproger