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;
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。