I want to have small YouTube player in my app. The only way i found to be recommended is embeding web page with YouTube player into my app. So i used WKWebView and loaded em
let videoView = UIView(frame: CGRect(x: 0, y: 80, width: self.view.frame.width, height: self.view.frame.height - 80))
self.view.addSubview(videoView)
let youTubeVideoHTML: String = " "
let html: String = String(format: youTubeVideoHTML, videoView.frame.width, videoView.frame.height, id)
let webConfiguration = WKWebViewConfiguration()
if #available(iOS 9.0, *) {
webConfiguration.allowsAirPlayForMediaPlayback = true
webConfiguration.allowsInlineMediaPlayback = true
webConfiguration.allowsPictureInPictureMediaPlayback = true
webConfiguration.mediaTypesRequiringUserActionForPlayback = []
}
webView = WKWebView(frame: CGRect(x: 0, y: 0, width: videoView.frame.width, height: videoView.frame.height), configuration: webConfiguration)
webView.uiDelegate = self
webView.scrollView.isScrollEnabled = false
webView.scrollView.zoomScale = 0
webView.isMultipleTouchEnabled = false
webView.scrollView.isPagingEnabled = false
webView.scrollView.isMultipleTouchEnabled = false
videoView.addSubview(webView)
webView.loadHTMLString(html, baseURL: URL(string: "https://www.youtube.com"))