Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable embedded YouTube videos in WKWebView?

How would one go about playing an embedded video like YouTube in their WKWebView? When launching an embedded YouTube video from a UIWebView, it plays just fine – whereas in the WKWebView it automatically plays in fullscreen. Am I missing something?

like image 818
Justin Bush Avatar asked Dec 10 '22 12:12

Justin Bush


1 Answers

I had a similar issue as you. What did it for me was to change the allowsInlineMediaPlayback property of WKWebViewConfiguration to true and setting the playsinline property to 1 in the YouTube player.

webViewConfiguration.allowsInlineMediaPlayback = true
wkWebView = WKWebView(frame: self.view.frame, configuration: webViewConfiguration)
let myURL = URL(string: "https://www.youtube.com/embed/BY-aB72nONA?playsinline=1")
var youtubeRequest = URLRequest(url: myURL!)
wkWebView.load(youtubeRequest)
like image 155
jikigi Avatar answered Dec 30 '22 21:12

jikigi