# All channels
#303: Editing Videos in UIKit 📼March 10, 2017 at 6:07pm
Today we're continuing our hunt for hidden gems in UIKit with
It's a cousin to
UIImagePickerViewControllerthat exposes <i>just</i> the basic video editing functionality from that class in a standalone, dedicated video editing view controller.
Let's give it a try.
First, we'll need a video file to edit. We'll use this one which is part of a freely available collection.
We'll download the video, rename it to something simple, and drag it into Xcode. We'll check the box next to our app in the dialog that appears, so it gets copied to our app target.
Now, let's write some code.
First, we'll make sure our video can be found:
...and that UIKit knows how to edit it:
Nice. Next, we can create a new video editor view controller and configure a few things on it:
Here we've told it our path, and given it a 10 second max duration. (Pro Tip: Default is 10 minutes, set to
0for no max).
From here we can simply present it like any other view controller:
The best part is all the functionality is self-contained inside the view controller.
The user can scrub through:
<img src="http://media.littlebitesofcocoa.com.s3.amazonaws.com/303-1.png" style="max-width: 640px; border-radius: 4px;" />
Trim the edges:
<img src="http://media.littlebitesofcocoa.com.s3.amazonaws.com/303-2.png" style="max-width: 640px; border-radius: 4px;" />
Then save the video back to the
videoPathwe set earlier:
<img src="http://media.littlebitesofcocoa.com.s3.amazonaws.com/303-3.png" style="max-width: 640px; border-radius: 4px;" />
Note: The documentation mentions
UIVideoEditorController<i>"only supporting Portrait"</i> orientations, but it seems to work fine in all orientations.
Last but not least, we can (optionally) set a
UIVideoEditorControllerto get notified when the user saves or cancels (or a save fails):
That's all for today. Know of an interesting UIKit B-side?
March 10, 2017 at 6:07pm
Just testing out what it might be like to public LBOC natively in Spectrum. No promises, just playing around. Very cool to see such great markdown support so early on in Spectrum's life. Cheers all!