0

My attempt was to set webView.configuration.mediaTypesRequiringUserActionForPlayback = .video

However, this does not work and after searching Google I was not able to find a workaround.

webView is an IBOutlet with a custom WKWebView class as follows:

import UIKit
import WebKit

class ScrollWebView: WKWebView {


  required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
    self.configuration.allowsInlineMediaPlayback = true
    self.configuration.mediaTypesRequiringUserActionForPlayback = .all
  }
}
Babiker
  • 18,300
  • 28
  • 78
  • 125

3 Answers3

2

Your problem is that mediaTypesRequiringUserActionForPlayback is not a boolean. It's of type WKAudiovisualMediaTypes. Here is the Apple Documentation:

Try this:

webView.configuration.mediaTypesRequiringUserActionForPlayback = .video
Kerberos
  • 4,036
  • 3
  • 36
  • 55
nighttalker
  • 896
  • 6
  • 13
  • Sorry, I pasted the wrong property name. Also, setting mediaTypesRequiringUserActionForPlayback to .video still does not work. As such, I've edited the question. – Babiker Nov 11 '17 at 02:01
0

After further research I realized that WKWebView cannot be configure nor created to a great extent in Storyboard or with Interface Builder. It must be created programatically. Reference: WKWebView in Interface Builder

Configuration can be done at object creation time.

Babiker
  • 18,300
  • 28
  • 78
  • 125
0

It is possible to set these in a Storyboard: enter image description here

Josh Heald
  • 3,907
  • 28
  • 37