I'm trying to interact with a loaded page in a UIWebView without touching the screen. I have tried mediaplaybackrequiresuseraction with no success. I have also tried the method provided here, but apparently it doesn't work in ios 6. I'm trying to load this url and make the player start playing. Does anyone know how to make this work ios 6? Any help is greatly appreciated.
MY CODE
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];
NSString * storyLink = [[stories objectAtIndex: storyIndex] objectForKey: @"link"];
//storyLink is various form of http://link.brightcove.com/services/player/bcpid1683318714001?bckey=AQ~~,AAAAC59qSJk~,vyxcsD3OtBPHZ2UIrFX2-wdCLTYNyMNn&bclid=1644543007001&bctid=2238216269001 with different bctid=value
NSURL *kitcoURL = [NSURL URLWithString:storyLink];
NSURLRequest *requestURL = [NSURLRequest requestWithURL:kitcoURL];
[videoScreen setUserInteractionEnabled:YES];
[videoScreen setMediaPlaybackRequiresUserAction:NO];
[videoScreen loadRequest:requestURL];
}
//Method not working in ios6
- (UIButton *)findButtonInView:(UIView *)view {
UIButton *button = nil;
if ([view isMemberOfClass:[UIButton class]]) {
return (UIButton *)view;
}
if (view.subviews && [view.subviews count] > 0) {
for (UIView *subview in view.subviews) {
button = [self findButtonInView:subview];
if (button) return button;
}
}
return button;
}
- (void)webViewDidFinishLoad:(UIWebView *)_webView {
UIButton *b = [self findButtonInView:_webView];
[b sendActionsForControlEvents:UIControlEventTouchUpInside];
}
EDIT //videoScreen is my UIWebView
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *urlString = @"http://link.brightcove.com/services/player/bcpid1683318714001?bckey=AQ~~,AAAAC59qSJk~,vyxcsD3OtBPHZ2UIrFX2-wdCLTYNyMNn&bclid=1644543007001&bctid=2238216269001";
NSError *error;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"bckey=([^&]*)" options:0 error:&error];
NSTextCheckingResult *match = [regex firstMatchInString:urlString options:0 range:NSMakeRange(0, urlString.length)];
NSString *bckey = [urlString substringWithRange:[match rangeAtIndex:1]];
regex = [NSRegularExpression regularExpressionWithPattern:@"bctid=([0-9]*)" options:0 error:&error];
match = [regex firstMatchInString:urlString options:0 range:NSMakeRange(0, urlString.length)];
NSString *bctid = [urlString substringWithRange:[match rangeAtIndex:1]];
NSString *newUrlString = [NSString stringWithFormat:@"http://c.brightcove.com/services/viewer/htmlFederated?&playerKey=%@&videoID=%@", bckey, bctid];
[videoScreen loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:newUrlString]]];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
if (!webView.isLoading)
{
[self checkForVideoReady];
}
}
// Checking player object for ready. If it ready - starting video. Otherwise waiting 1 second
- (void)checkForVideoReady
{
if (![[videoScreen stringByEvaluatingJavaScriptFromString:@"player.ready"] isEqualToString:@"true"])
{
[self performSelector:@selector(checkForVideoReady) withObject:nil afterDelay:1];
}
else
{
[videoScreen stringByEvaluatingJavaScriptFromString:@"player.videoPlayer.playButton.element.click();"];
}
}