У меня есть html файл с именем videoplay.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 позволяло пользователю размещать видео в самой папке документа, чтобы мои видеофайлы были только в папке с документами.
Обновление для Bounty Я нашел что-то следующее. Но все же он работает только для небольших видеороликов (менее 50 МБ), если видеоролики больше (более 100 МБ), они не работают.
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];
Как мне нужно реализовать это в моем проекте, для меня нет другого способа.