UIVideoEditorController delegate method called twice

1.4k Views Asked by At

I'm using UIVideoEditorController, but the success delegate method called twice for me. However, all pointers of all passed objects tell it sends exactly the same data.

let editor = UIVideoEditorController()
editor.videoMaximumDuration = 10.0
editor.videoQuality = .typeIFrame1280x720
editor.delegate = self
editor.videoPath = // some path goes here
self.present(editor, animated: true, completion: nil)

And then the following method prints "here" 2 times.

func videoEditorController(_ editor: UIVideoEditorController, didSaveEditedVideoToPath editedVideoPath: String) {
    print("here")
    self.dismiss(animated: true, completion: nil)
}
5

There are 5 best solutions below

0
On
func videoEditorController(_ editor: UIVideoEditorController,
 didSaveEditedVideoToPath editedVideoPath: String) {

    // This is the trimed video url
    print(editedVideoPath)
    
   dismiss(animated:true)
}
0
On

yes, I know, this bad way but workin :)

var isSaved:Bool = false

func videoEditorController(_ editor: UIVideoEditorController, didSaveEditedVideoToPath editedVideoPath: String) {
   if(!isSaved) {
      print("here")
      self.isSaved = true
   }
       self.dismiss(animated: true, completion: nil)
   }
0
On

Can you please debug that you UIViewController that using UIVideoEditorController is reallocating properly when user leaves the screen. Like after leaving the screen or going back from the screen.

Might be one object of your UIViewController in memory that's why your method called twice.

To debug this

  • create deinit{ print("deallocating") } for you UIViewController.
  • add break point on print.
  • then make sure deinit is getting called.

Hope it will help you. :)

1
On
func videoEditorController(_ editor: UIVideoEditorController, didSaveEditedVideoToPath editedVideoPath: String) {
    editor.delegate = nil
    editor.dismiss(animated: true)
}
0
On

this work for me

- (void)videoEditorController:(UIVideoEditorController *)editor didSaveEditedVideoToPath:(NSString *)editedVideoPath {

    [editor dismissViewControllerAnimated:YES completion:^{
        NSLog(@"path = %@", editedVideoPath);
    }];    
}