I'm actually trying to play a local video into an UIWebView, with HTLM5.
What I do actually is this :
NSString *embedHTML = [NSString stringWithFormat:@"\
<html><head>\
<style type=\"text/css\">\
body {\
background-color: transparent;\
color: white;\
}\
</style>\
</head><body style=\"margin:0\">\
< src=\"%@\" \
</embed>\
</body></html>", [[NSBundle mainBundle] pathForResource:@"ash(1).mov" ofType:nil]];
[webView setOpaque:NO];
NSString *html = [NSString stringWithFormat:embedHTML, webView.frame.size.width, webView.frame.size.height];
[webView loadHTMLString:html baseURL:nil];
I have on my storyboard an UIWebView named webView with weak / nonatomic property
@property (weak, nonatomic) IBOutlet UIWebView *webView;
When I launch the app, nothing happen : the screen still white and no video is playing.
Use this:
NSString *embedHTML = [NSString stringWithFormat:@"<html><style></style></head><body><video src=\"%@ controls autoplay height=\"400 width=\"320></video><ul></body></html>", [[NSBundle mainBundle] pathForResource:@"ash(1)" ofType:@"mov"]];
[webView setOpaque:NO];
//NSString *html = [NSString stringWithFormat:embedHTML, webView.frame.size.width, webView.frame.size.height];
NSURL *url = [NSURL URLWithString:[[NSBundle mainBundle] pathForResource:@"ash(1)" ofType:@"mov"]];
[webView loadHTMLString:embedHTML baseURL:url];
Refer more this to how to play video using html5
just change base url as
NSString *videoPath =[[NSBundle mainBundle] pathForResource:@"xxx" ofType:@"mov"];
NSString *htmlString=[NSString stringWithFormat:@"<body> <video src=\"%@\" controls autoplay height=\"400\" width=\"300\" > </video> </body>", videoPath];
NSURL *baseURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
[xwebview loadHTMLString:htmlString baseURL:baseURL];
来源:https://stackoverflow.com/questions/11115937/play-embedded-video-in-uiwebview-with-html5