Nikolay Borisov Nikolay Borisov - 1 month ago 18
Swift Question

WebView embed youtube video position

EXAMPLE HERE!!!

override func viewDidLoad() {
super.viewDidLoad()
secondVideoPlayer.allowsInlineMediaPlayback = true
secondVideoPlayer.loadHTMLString("<iframe width=\"\(newVideoPlayer.frame.width)\" height=\"\(newVideoPlayer.frame.height)\" src=\"\(urlString)?&playsinline=1\" frameborder=\"0\" allowfullscreen></iframe>",baseURL: nil)
}


Youtube video position starts not correctly, to see it correctly i always have to drag it how can i fix it? How can i manually set his start position?

Answer

Wrap your iframe inside a body and set the margin and padding to zero, so the content begins from the top left.

secondVideoPlayer.loadHTMLString("<body style=\"margin: 0; padding: 0;\"><iframe width=\"\(newVideoPlayer.frame.width)\" height=\"\(newVideoPlayer.frame.height)\" src=\"\(urlString)?&playsinline=1\" frameborder=\"0\" allowfullscreen></iframe></body>",baseURL: nil)
Comments