我实际上是尝试使用HTLM5将本地视频播放到UIWebView中。
我实际上是这样做的:
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];
我的故事板上有一个名为webView的UIWebView,具有弱/非原子属性
@property (weak, nonatomic) IBOutlet UIWebView *webView;
当我启动应用程序时,没有任何反应:屏幕仍然是白色,没有视频播放。
答案 0 :(得分:0)
使用此:
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];
请参阅this了解如何使用html5播放视频
答案 1 :(得分:0)
只需将基本网址更改为
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];