Prateek Chaubey
Prateek Chaubey

Reputation: 645

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 have 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

Upvotes: 3

Views: 2383

Answers (3)

iKushal
iKushal

Reputation: 2869

  [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;

}

Upvotes: 0

James Webster
James Webster

Reputation: 32066

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

Upvotes: 2

FluffulousChimp
FluffulousChimp

Reputation: 9185

This says you can by embedding in a local HTML file.

Upvotes: 0

Related Questions