21

I am using FDTake (the pod wont be too important for this question but still) to select videos from Photos which works fine. However, I would also like to be able to edit videos and limit their length to about 12 seconds. To do so I looked at the code of the pod and changed line 271 to self.imagePicker.allowsEditing = true which already causes the problem I haven't been able to solve so far: The left slider's touch (box) is “off”. Since that's a rather vague description I uploaded a video and you can find it right here.

Unfortunately, I have absolutely no idea what engenders the problem and would really appreciate some help with this. I asked the creator of FDTake but apparently he thinks that Apple needs to fix this (as you'll be able to see in one of the latest closed issues).

Can someone explain how I can fix this and what is causing it?

Moritz
  • 745
  • 1
  • 10
  • 32
  • Have you tried this on a device? Is it still off? Sometimes the simulator implementation of these kind of things can be a little off. – Randall Apr 25 '18 at 03:43
  • @Randall Yes, I have. Gave it another try on my iPhone before putting a bounty on this question. The problem started occurring after updating from iOS 10 to iOS 11 – Moritz Apr 25 '18 at 04:22
  • left slider is working in your video. Which box is "off" ? – Awais Fayyaz Apr 25 '18 at 05:55
  • @AwaisFayyaz This slider thingy, the left box with this arrow you need to drag in order to trim the video. It is not working as it should. As you can see in the video, I have to start dragging NEXT to this slider/box. It doesn’t react if I start dragging where it is displayed. – Moritz Apr 25 '18 at 06:08
  • Ok. So you need to trim the video from any where. e.g video is 20 seconds long. and you need to trim it from say 5 to 15 seconds. ? – Awais Fayyaz Apr 25 '18 at 06:15
  • No, the user shall be able to trim the video the way (s)he wants. No fixed trim points. @AwaisFayyaz – Moritz Apr 25 '18 at 06:18
  • Got it. Let me try and i will get back to you – Awais Fayyaz Apr 25 '18 at 06:20
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/169730/discussion-between-awais-fayyaz-and-moritz). – Awais Fayyaz Apr 25 '18 at 07:39

3 Answers3

8

One possible Solution: Select the video and then trim the video using PryntTrimmerView

You can use PryntTrimmerView library for trimming the videos. I have implemented this library in a sample project. You can download the running sample project from my github repo Here

The load random video button loads a random video from device's storage (photos). Therefore atleast one video file needs to be present

An Avplayer is being used for displaying the video

This is complete video

Complete video

Use the black handles to trim the video as desired

Trimming the Video

Trimming the video


Note: : Minimum Allowed distance between handles is specified in PryntTrimmerView.swift file using a private property.

/// The minimum duration allowed for the trimming. The handles won't pan further if the minimum duration is attained.
  public var minDuration: Double = 2

And this function uses this property along with video duration and frame to calculate minimum distance bw handles

private var minimumDistanceBetweenHandle: CGFloat {
    guard let asset = asset else { return 0 }
    let distance = CGFloat(minDuration) * assetPreview.contentView.frame.width / CGFloat(asset.duration.seconds)
    print("minimum distance: \(distance)")
    return distance
  }

Let me know if you encounter any problems or need more information

Thanks

Awais Fayyaz
  • 2,275
  • 1
  • 22
  • 45
  • 1
    Thank you for your effort, I really appreciate it. I’ve found this pod, too, while looking for a workaround. Nevertheless, I’m curious why the problem is occurring and would like to sort of point out to Apple that this bug should be fixed if it IS a bug. – Moritz Apr 26 '18 at 20:20
  • Thanks for the feedback. BTW, It is more likely that it is FDTake library issue. How are you assuming that it is a bug from apple?. Any insights into this? – Awais Fayyaz Apr 27 '18 at 09:42
  • Because it still worked when my iPhone was running on iOS 10. – Moritz Apr 27 '18 at 09:44
  • So, the same code was working on iOS 10. and now not working on _____ which iOS? – Awais Fayyaz Apr 27 '18 at 09:47
  • Currently on 11.3.1... didn’t check yet if there is another software update available already – Moritz Apr 27 '18 at 09:49
  • It is more likely that code in the library needs to be updated. Ok. Waiting for a solution with you :) – Awais Fayyaz Apr 27 '18 at 09:52
  • Not sure if I would agree, the code relies to a great extent on image picker without any fancy extras. Please take a look at the code by FDTake and especially the part containing line 271 before making such claims. I’ve checked it several times and didn’t see any deprecated code being used. Didn’t find a mistake though either. If you do, please let me know. I could very well be wrong. – Moritz Apr 27 '18 at 09:59
  • Ok @Moritz. I'll try to have a look at FDTake – Awais Fayyaz Apr 27 '18 at 10:19
5

I've reproduced the issue using an UIImagePickerController directly.

Here is some code that you can call from your viewController:

 let picker = UIImagePickerController()
 picker.allowsEditing = true
 picker.mediaTypes = [String(kUTTypeMovie)]
 picker.videoMaximumDuration = 12.0

 present(picker, animated: true, completion: nil)

My guess is that there is a gesture conflict with some internal view only on the left side of the screen, once you've pulled the left handle somewhere in the middle, you can access it directly.

Also, this does not seem to be new: IOS 11 UIImagepicker for video how to move the slider to the bottom?

The best thing you can do is to file a radar to Apple.

In the meantime, you can use the library suggested by Awais Fayyaz as a workaround. (Disclaimer: I'm the author of the library, so I am biased of course). Another option would be to use an UIVideoEditorController once the user has selected the video, that component does not have any issue on iOS 11.

HHK
  • 1,352
  • 1
  • 15
  • 25
  • 1
    Thank your for your answer! Unfortunately, I couldn't find that question before posting mine but it backs up my assumption! I guess I am going to start using your library though: It also looks much better than the standard editor! – Moritz Apr 30 '18 at 14:17
  • @VenkiWAR yeah, typos happen – Moritz May 01 '18 at 13:56
2

We've had the same problem here. It certainly has to do with gestures on the left side of the screen.

When you add additionalSafeAreaInsets to your UIImagePickerController it works much better.

This is what we tried:

 let imagePickerController = UIImagePickerController()
 imagePickerController.allowsEditing = true
 imagePickerController.mediaTypes = [kUTTypeMovie as String]
 imagePickerController.videoMaximumDuration = 12.0
 imagePickerController.additionalSafeAreaInsets = UIEdgeInsets(top: 20, left: 20, bottom: 20, right: 20)

We ended up using the UIVideoEditorController.

Gerharbo
  • 286
  • 1
  • 6