实际上,我尝试播放本地视频到一个UIWebView的,与HTLM5。
我真正做到这一点的是:
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];
我有我的故事板弱/非原子属性的UIWebView的web视图命名
@property (weak, nonatomic) IBOutlet UIWebView *webView;
当我启动应用程序,没有发生:屏幕仍然是白色,没有视频播放。
用这个:
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];
更多的,请参阅该如何使用播放HTML5视频
只是改变基本URL作为
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];