UIWebView\WKWebView加载iframe视频、控制视频加载立即开始播放和禁止点击播放视频视频全屏,其实就是对其里面的两个属性(allowsInlineMediaPlayback
、mediaPlaybackRequiresUserAction
)的设置
UIWebView
NSString *html=[NSString stringWithFormat:@"<iframe height=100%% width=100%% src='https://v.qq.com/iframe/player.html?vid=s0519r3u0sh&tiny=0&auto=1' style=\"position: absolute;top:0;left:0;\" frameborder=0 allowfullscreen></iframe>"];
UIWebView *webView=[[UIWebView alloc]initWithFrame:CGRectMake(0, 30, ScreenWidth,ScreenWidth*272.0/480.0)];
[self.view addSubview: webView];
//禁止点击播放视频全屏
webView.allowsInlineMediaPlayback = YES;
//webView加载完成视频开始播放(iframe里面已经设置开始播放auto=1)
webView.mediaPlaybackRequiresUserAction=NO;
webView.scrollView.bounces=NO;
webView.delegate=self;
webView.scrollView.bounces=NO;
webView.backgroundColor=[UIColor redColor]; webView.scrollView.backgroundColor=[UIColor redColor];
webView.opaque=NO;(只有设置为NO,设置webView.backgroundColor才有用)
WKWebView
//初始化一个WKWebViewConfiguration对象
WKWebViewConfiguration *config = [WKWebViewConfiguration new];
//初始化偏好设置属性:preferences
config.preferences = [WKPreferences new];
//The minimum font size in points default is 0; config.preferences.minimumFontSize = 10;
WKWebView *webView = [[WKWebView alloc]initWithFrame:self.view.frame configuration:config]; (必须以这种方式初始化)
[self.view addSubview:webView];
//禁止点击播放视频全屏
webView.configuration.allowsInlineMediaPlayback = YES;
//webView加载完成视频开始播放(iframe里面已经设置开始播放auto=1)
webView.configuration.mediaPlaybackRequiresUserAction = NO;
网友评论