我的app需要实现一个网页视频自动播放的功能,我使用了WKWebView加载视频页面并且指定了webView.configuration.requiresUserActionForMediaPlayback = NO,但是还是无法自动播放视频,同样的页面使用UIWebView就可以自动播放,google后只有stack overflow上前几天有人问了同样的问题,请问这里有大神知道是什么原因么,系统是ios9.3,附网页代码和本地代码:
网页:
http://www.w3school.com.cn/html5/att_video_autoplay.asp
Objective-C:
WKWebView* webView = [[WKWebView alloc] initWithFrame:self.view.frame];
webView.allowsBackForwardNavigationGestures = YES;
webView.configuration.allowsInlineMediaPlayback = YES;
webView.configuration.requiresUserActionForMediaPlayback = NO;
[self.view addSubview:self.webView];
NSString *docUrl = @"http://192.168.6.21/ttt/video.html";
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:docUrl]]];
WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init]; config.allowsInlineMediaPlayback = YES; config.mediaPlaybackRequiresUserAction = false; wkWebView = [[WKWebView alloc] initWithFrame:aRect configuration:config] 【直接设置验证下来确实没有用,在wkWebView创建时,传入是可以实现自动播放的】