Saturday 24 June 2017

Youtube Player (Swift)


STEP - 1 : Main.Storyboard

A. Add a WebView to Main.Storyboard.

B. Add @IBOutlet to ViewController.swift ( Press 'Ctrl + Mouse Left Key' and drag to ViewController )

STEP - 2 : Add 'App Transport Security Setting' to info.plist file.

STEP - 3 : Inside 'App Transport Security Setting' -> Add 'Allow Arbitrary Load' and set value 'Yes'.

STEP - 4 : ViewController.swift

*******************------------------*******************
//
//  ViewController.swift
//  YoutubeEmbed
//
//  Created by Admin on 03/04/1939 Saka.
//  Copyright © 1939 Saka Admin. All rights reserved.
//

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.
        getVideo(videocode: "Kd57YHWqrsI")
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    func getVideo(videocode : String)
    {
        let url1 = URL(string: "http://www.youtube.com/embed/\(videocode)")
        myWebview.loadRequest(URLRequest(url: url1!))
    }

}


No comments:

Post a Comment