Reputation: 108
I am trying to embed a video from youtube with the following code:
func setUpVideo() {
let width = webView.frame.width
let height = webView.frame.height
let frame = 0
bmiWebView.allowsInlineMediaPlayback = true
let videoUrl = "https://www.youtube.com/embed/GCALWdwKr48"
let htmlUrl = "<html><body><iframe width=\(width) height=\(height) src=\(videoUrl)?&playsinline = 1 frameborder=\(frame) allowfullscreen></iframe></body></html>"
webView.loadHTMLString(htmlUrl, baseURL: NSBundle.mainBundle().bundleURL)
}
I'm able to load the video initially with white background but when it loads it looks like below. I'm not sure why there is a white background. If someone can tell me how to remove that will be really helpful. Thank you.
Upvotes: 3
Views: 759
Reputation: 707
The white background is the margin on the body of the HTML of your UIWebView.
Add some CSS to set the margin to 0 like so:
<html>
<head>
<style>body{margin:0px;}</style>
</head>
<body>
<iframe width=\(width) height=\(height) src=\(videoUrl)?&playsinline = 1 frameborder=\(frame) allowfullscreen></iframe>
</body>
</html>
Upvotes: 1