Disable autoplaying video for UIWebView

2019-07-11 21:24发布

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

3条回答
霸刀☆藐视天下
2楼-- · 2019-07-11 21:34

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.

查看更多
\"骚年 ilove
3楼-- · 2019-07-11 21:42

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;.

查看更多
SAY GOODBYE
4楼-- · 2019-07-11 21:45

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
查看更多
登录 后发表回答