Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable autoplay for YouTube video in WKWebView?

I have simple ViewController with WKWebView configured as follows:

webView.configuration.allowsInlineMediaPlayback = true
webView.configuration.mediaTypesRequiringUserActionForPlayback = .video

But right after loading a web page with YouTube video it starts to play automatically (and switching to full screen at the same time) without any user interaction which is required. How to disable autoplay?

like image 317
a-a-m Avatar asked Sep 22 '17 11:09

a-a-m


People also ask

How do I turn off autoplay on YouTube videos?

1. On the Home tab of the YouTube app, tap your profile picture, then tap Settings. 2. Tap Autoplay, then tap the autoplay switch to the off position to turn off the feature.


1 Answers

I also had same problem,YouTube vide was playing in full screen

webview.configuration.allowsInlineMediaPlayback = true

programmatically setting allowsInlineMediaPlayback value didn't work for me

You can avoid video switching fullscreen by enable inline playback for WKWebview. enter image description here

like image 172
Kishor Avatar answered Nov 01 '22 08:11

Kishor