7

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?

a-a-m
  • 96
  • 1
  • 5
  • Note that, that property is only available from iOS10. For previous versions you should set configuration.requiresUserActionForMediaPlayback = true – Carien van Zyl Sep 22 '17 at 11:50
  • Thanks, I've tried on latest stable version iOS 11.0 and seems like that flag ignored for YouTube pages. – a-a-m Sep 22 '17 at 12:06

2 Answers2

7

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

Kishor
  • 376
  • 4
  • 14
0

Check the webView storyboard property Interaction for Audio Playback. Yes, I know, this is a question about video, but setting the Video Playback checkbox doesn't work, at least not on a target iOS 13 simulator!

Probably just check everything in that section - inline playback, interaction for Audio, interaction for Video. That's what I'm doing, although my test shows only Audio is necessary. I suspect this is a WKWebView bug and Apple will fix it so that Video properly works instead of Audio :-)

Matt H
  • 6,422
  • 2
  • 28
  • 32