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>
次のコードを使用している間(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];
次のコードを使用し(Loading from Document folder of application)
ます。htmlコンテンツをロードしますが、ムービーファイルの代わりに黒い部分を表示します。
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir =[documentPaths objectAtIndex:0]
NSString *pathOfHTmlFile = [documentsDir stringByAppendingPathComponent:@"videoplay.html"];
NSString *content = [NSString stringWithContentsOfFile:pathOfHTmlFile encoding:NSUTF8StringEncoding error:nil];
[self.webView loadHTMLString:content baseURL:[NSURL URLWithString:documentsDir]];
上記のコードに何が欠けているので、コードが機能しませんか?何か案が ?
UIFileSharingEnabled機能を備えたアプリケーションが必要です。これにより、ユーザーはビデオをドキュメントフォルダー自体に配置できるため、ビデオファイルはドキュメントフォルダーのみに配置されます。
バウンティのアップデート 私は次のようなものを見つけました。ただし、それでも、ビデオが大きい(約100 MBを超える)場合は、小さいビデオ(約50 MB未満)でのみ機能します。
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir =[documentPaths objectAtIndex:0];
NSString *pathOfHTmlFile = [documentsDir stringByAppendingPathComponent:@"videoplay.html"];
NSString *content = [NSString stringWithContentsOfFile:pathOfHTmlFile encoding:NSUTF8StringEncoding error:nil];
documentsDir = [documentsDir stringByReplacingOccurrencesOfString:@"/" withString:@"//"];
documentsDir = [documentsDir stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
NSURL *baseURL = [NSURL URLWithString:[NSString stringWithFormat:@"file:/%@//", documentsDir]];
NSLog(@"Baseurl--->%@",baseURL);
[self.webView loadHTMLString:content baseURL:baseURL];
これを自分のプロジェクトに実装する必要があるので、他に方法はありません。