Monday, March 23, 2015

presentViewController - [kUTTypeMovie] Video Capture and Play

1. Drag a button to the storyboard. Name the button as 'Capture Video.' Uncheck the 'Use Auto Layout' option in the file inspector.

2. Control-drag the button to ViewController.swift and selection 'Action' as the connection type. Name it captureVideo and obtain the code as below:

    @IBAction func captureVideo(sender: AnyObject) {


3. Write the code as below:

import UIKit
import MobileCoreServices

class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
    @IBAction func captureVideo(sender: AnyObject) {
        if (UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera)) {
            var myPickerController = UIImagePickerController()
            myPickerController.delegate = self
            myPickerController.allowsEditing = true
            myPickerController.sourceType = UIImagePickerControllerSourceType.Camera
            myPickerController.mediaTypes = [kUTTypeMovie]
            self.presentViewController(myPickerController, animated: true, completion: nil)
    override func viewDidLoad() {
        // Do any additional setup after loading the view, typically from a nib.