قالب وردپرس درنا توس
Home / IOS Development / # 303: Editing videos in UIKit 📼 – Little Bites of Cocoa

# 303: Editing videos in UIKit 📼 – Little Bites of Cocoa



Subjects

Topics

Today, we continue the quest for hidden beads in UIKit with UIVideoEditorController .

It is a cousin of UIImagePickerViewController which shows only basic video editing functionality from this class in a standalone dedicated video editing control .

Let's try.

First, we need a video file to edit. We use this which is part of a freely available collection.

We download the video rename it for something simple and drag it into Xcode . We check the box next to our app in the dialog that appears to be copied to our app target .

Now let's write some code.

First, we want to make sure our video can be found:

  guard    la    path    =    Bundle .   main .   1
9659024]
forResource : "video" ofType : "mP4" ) otherwise {[19659018] return }

… and that UIKit knows how to edit it:

  guard    UIVideoEditorController .   canEditVideo  (  atPath :    lane )    otherwise    {   return  } 

Fine. Then we can create a new video editing controller and configure some things on it: la editor = UIVideoEditorController ()

editor . videoPath = path
editor . videoMaximumDuration = 10.0
editor . videoQuality [19659018] = . typeIFrame1280x720

Here we have told it our way, giving it a 10 second maximum duration. Pro Tip: Standard is 10 minutes, set to 0 without maximum).

From here we can only present it as any other display regulators :

  lying ~~ POS = HEADCOMP  (  editor     animated :    ] true     completion :    nil ) [19659037] Tidy! 

The best part is that all functionality is independent in the display regulator .

The user can scrub through:

Trim the edges:

Then make the video back to videoPath we put earlier: [19659007] ]

Notice: The documentation mentions UIVideoEditorController "support only portrait" orientations but it seems to work well in all orientations [19659000].

Last but not least, we may (optional) put a delegate on our UIVideoEditorController to be notified when the user saves or cancel an edit failure):

  editor [19659022].  ]       [196590100] Extension    SomeViewController  :  
      UIVideoEditorControllerDelegate   
      UINavigationControllerDelegate [19659034] {

    FUNC    VideoEditorController 

( _ editor : UIVideoEdito rController      ] [19659129]}

] } ] }

It's all for today. Do you know about an interesting UIKIT B page?

Send it on!


Source link