Can a local video be played using UIWebView?
In my app for iPad I have to show some videos and PDFs. All the videos and PDFs are local. For PDFs I ha开发者_运维知识库ve used UIWebView and it is working. Now I would like to know that, can I also use same UIWebView to play videos as well. All the PDFs are working on a single UIWebView and I would like to play all the videos on that same UIWebView. Is it possible to play local videos on a UIWebView? If it is then how can I do it?
Regards PC
Assuming the video type is supported, I think this should work fine. HTML5 =D
[webView loadHTMLString:@"<video src=\"yourVideo.mp4\">Alt Text</video>"
baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle]bundlePath]]];
NB: Not tested
This says you can by embedding in a local HTML file.
[self.webView_ loadHTMLString:@"<html><body>"
"<video controls>"
"<source src=\"CategoryImage_Preterit.mp4\" type=\"video/mp4\">"
"</video>"
"<img src=\"89.jpg\" alt=\"Smiley face\" width=\"142\" height=\"242\">"
"</body>"
"</html>" baseURL:[NSURL URLWithString:[self getBasePath]]];
-(NSString*)getBasePath
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory,
NSUserDomainMask, YES);
NSMutableString *cacheDirectory = [NSMutableString stringWithString:[paths objectAtIndex:0]];
[cacheDirectory appendString:@"/"];
NSRange renge= NSMakeRange(0, cacheDirectory.length);
[cacheDirectory replaceOccurrencesOfString:@"/" withString:@"//" options:NSCaseInsensitiveSearch range:renge];
renge= NSMakeRange(0, cacheDirectory.length);
[cacheDirectory replaceOccurrencesOfString:@" " withString:@"%20" options:NSCaseInsensitiveSearch range:renge];
[cacheDirectory insertString:@"file://" atIndex:0];
return cacheDirectory;
}
精彩评论