在 uiwebview 中播放本地视频
我将本地 html 文件加载到 ipad 应用程序中:
NSURL *baseURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
NSString *path = [[NSBundle mainBundle] pathForResource:@"lieferant1" ofType:@"html"];
NSString *content = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
[webView loadHTMLString:content baseURL:baseURL];
显示网页,我的 html 文件的内容:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
<p>
<video>
<source src="banane.m4v">
</video>
</p>
因此,banane.m4v
位于我的根目录中,仅在某些组中,但不在实际目录中。
但我的网页视图中的视频部分保持黑色。没有视频被加载。我将我的 html 文件和 .m4v
视频上传到我的网络服务器,以检查其编码是否正确,但一切正常,用我的 iPad 浏览 html 文件。
一些想法有什么问题吗?
i load a local html file into an ipad application:
NSURL *baseURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
NSString *path = [[NSBundle mainBundle] pathForResource:@"lieferant1" ofType:@"html"];
NSString *content = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
[webView loadHTMLString:content baseURL:baseURL];
the webpage gets displayed, content of my html file:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
<p>
<video>
<source src="banane.m4v">
</video>
</p>
so, banane.m4v
is in my root, just in some groups, but not in real directories.
but the video section in my webview keeps black. no video gets loaded. i uploaded my html file and my .m4v
video to my webserver to check if its not encoded properly, but everything works fine, surfing the html file with my ipad.
some ideas whats wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
天哪
,
controls
是一个神奇的词。:X
oh my god
where
controls
is the magic word.:X
我可能是错的(或者愚蠢的),但是,你尝试过
file:///banane.m4v
(为 root 添加额外的“/”)I may be wrong (or silly) but, did you try
file:///banane.m4v
(Add the extra '/' for root)对于每个经历过被划掉的游戏符号的人来说,
当您拖动电影文件(mp4 也可以,只需确保编解码器正常 - 最简单的方法是使用 QuickTime 导出到 iPhone)时,会出现一个对话框。
确保在“添加到目标”下勾选您的应用程序。
或者,如果您已经将视频复制到项目中,则在 Xcode 的文件浏览器中单击它,您将在右侧看到一个选项来选择目标。
For everyone that experiences a crossed out play symbol,
When you drag your movie-files (mp4's work as well, just make sure the codec is okay - easiest way is to export for iPhone with QuickTime) a dialog appears.
Make sure you tick your app under "add to targets".
Or if you already copied your video into the project, if you click it in Xcode's file browser, you'll have an option on the right-hand side to select targets.
您需要在
UIWebView
上设置allowsInlineMediaPlayback
属性:You need to set the
allowsInlineMediaPlayback
property on theUIWebView
: