Play embedded video in UIWebView with HTML5

匿名 (未验证) 提交于 2019-12-03 00:48:01

问题:

I'm actually trying to play a local video into an UIWebView, with HTLM5.

What I do actually is this :

NSString *embedHTML = [NSString stringWithFormat:@"\ \ \ \ < src=\"%@\"  \ \ ", [[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.

回答1:

Use this:

NSString *embedHTML = [NSString stringWithFormat:@"
    ", [[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



回答2:

just change base url as

NSString *videoPath =[[NSBundle mainBundle] pathForResource:@"xxx" ofType:@"mov"];  NSString *htmlString=[NSString stringWithFormat:@"  ", videoPath];  NSURL *baseURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]; [xwebview loadHTMLString:htmlString baseURL:baseURL];


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!