I have researched several fixes for this issue but not seem to have solved the problem.
I will outline below the steps I've taken to allow video from a < video > tag element to play in line. I need a solution that will work across different websites and not something that will only work for youtube etc.
Reference I'm using the WKWebView as the containing browser for the web content. I have set allowsInlineMediaPlayback = true (WKWebViewConfiguration). I have also implemented the following piece of JavaScript that i call on a webpage and successfully amends the attributes of the video tag to include "playsinline" "autoplay". thinking being no matter what guff the website developer has , or hasnt got in there i can be sure the attributes i need are added to the video tag. (as a side note i think youtube and others are also making it difficult for devleopers to affect how there website behaves (however much better the UX would be if they did))
Anyway to the code >>
WKWebViewConfiguration *dx = [[WKWebViewConfiguration alloc] init];
dx.allowsInlineMediaPlayback = TRUE;
WKWebView * webview = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, cell.wv.bounds.size.width, cell.wv.bounds.size.height) configuration:dx];
[cell addSubview:webview];
webview.navigationDelegate = self;
webview.UIDelegate = self;
webview.frame = CGRectMake(0, 0, cell.wv.bounds.size.width, cell.wv.bounds.size.height);
[[webview scrollView] setBounces:NO];
webview.scrollView.scrollEnabled = NO;
NSURL *nsurl=[NSURL URLWithString:urlws[indexPath.row]];
NSURLRequest *request = [NSURLRequest requestWithURL:nsurl cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval: 60.0];
[webview loadRequest:request];
NSString *jsCallBack = @"var b = document.querySelector(\"video\"); b.setAttribute(\"webkit-playsinline\",\"\"); b.setAttribute(\"autoplay\",\"\"); b.setAttribute(\"muted\",\"\");";
[webView evaluateJavaScript:jsCallBack completionHandler:^(NSString *result, NSError *error)
{
NSLog(@"Error %@",error);
NSLog(@"Result %@",result);
I then kick off the playback by calling this js code from ios
NSString *jsCallBack = @"var element = document.querySelector('[aria-label=\"Play\"]'); element.click();";
[webView evaluateJavaScript:jsCallBack completionHandler:^(NSString *result, NSError *error)
{
Results :
The play function is called and video plays but the user is taken into full screen playback which is not what should happen. @IOS WebKit is good, but needs more work and we need some more intelligent apis for this i think as its now seldom that any user wants to see a video in full screen. Its natural if the devise it turned on its side for full screen but otherwise it really smacks of a bad user experience.
If anyone has any ideas please let me know. Many thanks