Reputation: 8124
I am here with a silly question. I am having a embedded vimeo player like this:
NSString *htmlString = @"<html><head><style type="text/css">body {background-color:black; color:black; margin-right:auto; margin-left:auto;}</style></head><body style="margin:0"><iframe id="video" name="video" src="http://player.vimeo.com/video/67487897?byline=0&autoplay=1&api=1&player_id=video" width="768.000000" height="525.000000" frameborder="0"></body></html>";
and loaded it in a UIWebView like this:
[_webView loadHTMLString:html baseURL:nil];
The video loads fine but it does not autoplay. I, however, came to know that autoplay is not supported for embedded players. The code I used for autoplay is:
- (void)webViewDidFinishLoad:(UIWebView *)wbView{
// NSString *script = @"var message = 'api_play'; var vid = document.getElementById('video'); var window = vid.contentWindow; window.postMessage('{\"event\":\"command\",\"func\":\"' + message + '\",\"args\":\"\"}', '*');";
NSString *script = @"var vid = document.getElementById('video'); var window = vid.contentWindow; window.postMessage('{\"method\":\"play\"}', vid.src.split('?')[0]);";
NSLog(@"%@",script);
[_webView stringByEvaluatingJavaScriptFromString:script];
//the above portion did not work so I tried this one too but of no use...
script = @"var vid = document.getElementById('video'); var window = vid.contentWindow; window.api(\"play\"); alert('done'); vid.src = '';";
[_webView stringByEvaluatingJavaScriptFromString:script];
}
But autoplay is not a major problem. The big problem here is that sometimes video does not stop when I get out of this screen. I tried multiple things and multiple scripts but the problem did not go the code I used is:
// NSString *script = @"var message = 'api_unload'; var vid = document.getElementById('video'); var window = vid.contentWindow; window.postMessage('{\"event\":\"command\",\"func\":\"' + message + '\",\"args\":\"\"}', '*'); vid.src = '';";
NSString *script = @"var vid = document.getElementById('video'); var window = vid.contentWindow; window.postMessage('{\"method\":\"pause\"}', vid.src.split('?')[0]);";
NSLog(@"%@",script);
[_webView stringByEvaluatingJavaScriptFromString:script];
I also tried to use this:
NSString *script = @"var vid = document.getElementById('video'); var window = vid.contentWindow; window.api(\"pause\"); vid.src = '';";
NSLog(@"%@",script);
[_webView stringByEvaluatingJavaScriptFromString:script];
None worked.
Simply doing
[_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"about://blank"]]];
does not work either. I face same problems with youtube videos too.
I am running out of options. Any person experienced same issues?
I am currently using iPad3 but I know the same thing happen on other ipads too.
Upvotes: 0
Views: 495
Reputation: 25
This will auto play an embed vimeo
http://vimeo.com/moogaloop.swf?clip_id=71788444&server=www.vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1&autoplay=1
Take note to the &autoplay=1 at the end
Upvotes: 0