Bug 162329 - WKWebView set mediaPlaybackRequiresUserAction = false not working to auto play a video
Summary: WKWebView set mediaPlaybackRequiresUserAction = false not working to auto pla...
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit API (show other bugs)
Version: Other
Hardware: iPhone / iPad iOS 10
: P2 Blocker
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-09-20 19:04 PDT by rainer
Modified: 2016-09-20 20:30 PDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description rainer 2016-09-20 19:04:09 PDT
Hi I am working on iOS 10 with Swift3 right now.

My scenario is to autoplay a youtube video inline using WKWebView. I set the config's mediaPlaybackRequiresUserAction to false in order to enable the video autoplay, as suggested by Apple Dev Docs.

However this config does not seem to work, the video loaded correctly, but you have to press the play button to make it actually play.

Code below:

let config = WKWebViewConfiguration()
            config.requiresUserActionForMediaPlayback = false
            config.allowsInlineMediaPlayback = true
            config.mediaPlaybackRequiresUserAction = false
            config.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone
            let webView = WKWebView(frame: self.topView.bounds, configuration: config)
            webView.addObserver(self, forKeyPath: self.webViewLoadingKey, options: .new, context: nil)