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?
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With