It seems like the iframe API has changed since the time of the previous answer. I have updated the HTML that's loaded in the WKWebView based on the iframe API Reference. Using this code I managed to autoplay YouTube videos in fullscreen in a WKWebView on iOS11.
class YouTubeVideoPlayerVC: UIViewController {
@IBOutlet weak var videoPlayerView: WKWebView!
var videoURL:URL! // has the form "//www.youtube.com/embed/videoID"
var didLoadVideo = false
override func viewDidLoad[] {
super.viewDidLoad[]
videoPlayerView.configuration.mediaTypesRequiringUserActionForPlayback = []
}
override func viewDidLayoutSubviews[] {
super.viewDidLayoutSubviews[]
// Size of the webView is used to size the YT player frame in the JS code
// and the size of the webView is only known in `viewDidLayoutSubviews`,
// however, this function is called again once the HTML is loaded, so need
// to store a bool indicating whether the HTML has already been loaded once
if !didLoadVideo {
videoPlayerView.loadHTMLString[embedVideoHtml, baseURL: nil]
didLoadVideo = true
}
}
var embedVideoHtml:String {
return """
"""
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视
Video liên quan