开发者

pause a video (mp4) running inside a uiwebview

I am loading videos(mp4) and Audio(mp3) files into a UIwebview. It's straight forward and works nicely

NSURLRequest *request = [[NSURLRequest alloc] initWithURL: videoURL cachePolicy: NSURLRequestUseProtocolCachePolicy timeoutInterval开发者_如何学C: 30.0];  
[webView loadRequest: request];  
[request release];

Question: How do I prevent the video / audio from autoplay ? I want the video to pause and let the user click "play" assuming he wants to play it.

Thanks.


Answering my own question

using the following code will do the job

NSString *videoHTML = [NSString stringWithFormat: @"<html><head><style></style></head><body><video id='video_with_controls' height='438' width='672' controls autobuffer autoplay='false'><source src='%@' title='' poster='icon2.png' type='video/mp4' durationHint='durationofvideo'/></video><ul></body></html>",videoURL];

webView.opaque = NO;
webView.backgroundColor = [UIColor clearColor];
[webView loadHTMLString:videoHTML baseURL:nil]; 


You must be using the video tag in your UIWebView to play the video. You'll have to use javascript to control the video element within your UIWebView. You can use the [UIWebView stringByEvaluatingJavaScriptFromString:] method to execute the javascript needed to pause the video. Then it should just be a matter of writing the JS to look up the video element on the page and call pause() on it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜