我有一个名为videoplay.html以下内容的html文件
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
</head>
<body>
<p>
This is demo html file for playing movie file embedded.
</p>
<p>
<video controls>
<source src="myvideoname.mov">
</video>
</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
使用以下代码(Loading from application bundle)它加载html内容并显示电影,并能够播放电影文件.
NSURL *baseURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
NSString *path = [[NSBundle mainBundle] pathForResource:@"videoplay" ofType:@"html"];
NSString *content = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
[self.webView loadHTMLString:content baseURL:baseURL];
Run Code Online (Sandbox Code Playgroud)
使用以下代码(Loading from Document folder of application)它加载html内容但显示黑色部分而不是电影文件.
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir =[documentPaths objectAtIndex:0]
NSString …Run Code Online (Sandbox Code Playgroud)