Showing posts with label video. Show all posts
Showing posts with label video. Show all posts

Friday, April 3, 2015

Play an embedded Youtube video

1. Uncheck the 'Use Auto Layout' option in the file inspector.

2. Drag the web view to the storyboard.  

3. Control-drag the web view to ViewController.swift. Name it myWebView and obtain the code as below:


@IBOutlet weak var myWebView: UIWebView!

4. Complete the code as below:

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var myWebView: UIWebView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        let myURL : NSURL = NSURL(string: "
https://www.youtube.com/embed/vmMAI86Lub0")!
       //Note: use the "embed" address instead of the "watch" address.
        let myURLRequest : NSURLRequest = NSURLRequest(URL: myURL)
        self.myWebView.loadRequest(myURLRequest)
    }

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() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }