How to disable autoplay for YouTube video in WKWebView?
Asked Answered
G

2

8

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?

Garwood answered 22/9, 2017 at 11:19 Comment(2)
Note that, that property is only available from iOS10. For previous versions you should set configuration.requiresUserActionForMediaPlayback = trueTopple
Thanks, I've tried on latest stable version iOS 11.0 and seems like that flag ignored for YouTube pages.Garwood
S
8

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

Scabble answered 26/12, 2017 at 10:45 Comment(1)
THIS DOESN'T WORK FOR IOS 13 ANYMORE! HELP!Anis
S
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 :-)

Slice answered 19/10, 2022 at 13:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.