Disable autoplaying video for UIWebView

故事扮演 提交于 2019-12-24 00:44:40

问题


I have a delegate method but it doesn't help me . Please refer to the method below

-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType

回答1:


What page are you trying to open? UIWebView will NOT auto play any video by default. So if your video dose auto played, it should be some javascript in your HTML let it start to play.

Maybe you should check your HTML first.




回答2:


You can disable auto playback in the webView via code like below. Don't rely on the storyboard options. Didn't work for me. Have to do it in swift.

webView.mediaPlaybackRequiresUserAction = true
webView.allowsInlineMediaPlayback = false

Swift 5:

webView.configuration.mediaTypesRequiringUserActionForPlayback = .all
webView.allowsInlineMediaPlayback = false
webView.configuration.allowsInlineMediaPlayback = false



回答3:


You didn't actually give us your code, but it sounds like inside that method, you should have return NO;. This tells the delegate method to NOT start. Also, somewhere (probably where you create your web view), make sure you set the delegate with: myWebView.delegate = self;.



来源:https://stackoverflow.com/questions/7022579/disable-autoplaying-video-for-uiwebview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!