我尝试使用UIWebView从网站(带有HTML5视频标签)播放.mp4视频。 iPhone / iPad设备和模拟器仅显示带有敲击播放按钮的黑框。 如果我只是在Safari Mac版本上调用此网站,则可以播放它。 怎么回事?
它不是本地文件。 html看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="../css/shared-culture.css" />
</head>
<body>
<section class="base">
<hgroup>
<h1>creative commons</h1>
<h2>a shared culture</h2>
</hgroup>
<p>To celebrate our 2008 fundraising campaign, Creative Commons has
released “A Shared Culture,” a short video by renowned filmmaker <a
href="http://en.wikipedia.org/wiki/Jesse_Dylan">Jesse Dylan</a>. Known for
helming a variety of films, music videos, and the Emmy Award-winning <a
href="http://my.barackobama.com/page/invite/yeswecanvideo">“Yes We Can”</a>
Barack Obama campaign video collaboration with rapper will.i.am, Dylan created
“A Shared Culture” to help spread the word about the Creative Commons mission. </p>
<!-- height="240" width="360" -->
<video id="video1" controls="controls">
<source src="../video/shared-culture.mp4" type="video/mp4"/>
<source src="../video/shared-culture.webm" type="video/webm"/>
<div class="errmsg">
<p>Your Reading System does not support (this) video.</p>
<pre><code>
<video id="video1" controls="controls">
<source src="../video/shared-culture.mp4" type="video/mp4"/>
<source src="../video/shared-culture.webm" type="video/webm"/>
</video>
</code></pre>
</div>
</video>
<p>In the video, some of the leading thinkers behind Creative Commons
describe how the organization is helping “save the world from failed sharing”
through free tools that enable creators to easily make their work available to
the public for legal sharing and remix. Dylan puts the Creative Commons system
into action by punctuating the interview footage with dozens of photos that have
been offered to the public for use under CC licenses. Similarly, he used two
CC-licensed instrumental pieces by Nine Inch Nails as the video’s soundtrack
music. These tracks, “17 Ghosts II” and “21 Ghosts III,” come from the Nine Inch
Nails album Ghosts I-IV, which was released earlier this year under a Creative
Commons BY-NC-SA license. (See <a
href="http://creativecommons.org/videos/a-shared-culture">attribution</a>.)
</p>
</section>
</body>
</html>
答案 0 :(得分:9)
它可能不是iPhone友好格式。
将mp4文件拖到iMovie中,然后点击分享 - &gt; 导出电影,然后选择一种与iPhone兼容的格式。
答案 1 :(得分:4)
视频无法在UIWebView中播放的方式之一是托管视频文件的Web服务器不支持字节范围。 UIWebView不会立即下载整个.mp4文件;相反,它通过请求文件的部分来流式传输视频。如今大多数服务器都支持字节范围,但如果你的服务器不支持字节范围,或者由于某些原因你已将其关闭,那么你将无法向iOS设备提供视频。
答案 2 :(得分:2)
听起来像编解码器问题。如果在计算机上的VLC中打开文件,可以看到该文件使用的编解码器,转到Window-&gt; Media Information-&gt; Codec Details。答案here链接到Apple的文档,您将在其中找到支持的视频和音频编解码器:
答案 3 :(得分:1)
您使用的相对../
路径可能存在问题。尝试使用完整的绝对路径 - 从http://
开始。
答案 4 :(得分:0)
我也有这个问题,我有2个.mp4
,但有一个可以使用,有一个不可以,我尝试将类型文件格式.mp4
格式化为.mp4
以获取IPad和它的工作,我认为你应该试试。
答案 5 :(得分:0)
我正在C#.NET Core Ios Webview App中搜索相同的内容。对我来说,在WebView控件上设置这些开关(在Webview中设置html之后):
WebView.AllowsLinkPreview = true;
WebView.AllowsInlineMediaPlayback = true;
WebView.AllowsPictureInPictureMediaPlayback = true;
为我工作。
答案 6 :(得分:-1)
在iPhone上播放mp4视频编程并不是很难。我们需要做一个额外的拖放。
请采取新的单一视图项目。然后在ViewController.m文件中复制并粘贴此代码
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize webView;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
webView=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0,screenWidth,screenHeight)];
NSURL *url = [[NSBundle mainBundle] URLForResource:@"testingHTML" withExtension:@"html"];
NSLog(@"%@",url);
[self.webView loadRequest:[NSURLRequest requestWithURL:url]];
// NSURL *nsurl=[NSURL URLWithString:url];
//NSURLRequest *nsrequest=[NSURLRequest requestWithURL:nsurl];
// [webView loadRequest:nsrequest];
[self.view addSubview:webView];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
然后创建名为testingHTML.html
的HTML文件并将以下代码复制并粘贴到HTML文件
中<!DOCTYPE html>
<html>
<head></head>
<body>
<center> <video width="250" height="304" controls preload>
<source src="video1.mp4" type="video/mp4">
</video> </center>
<p>Thanks to Md Kamrul Hasan .....mdkamrul.hasan@marquette.edu</p>
</body>
</html>
将MP4类型的视频拖放到两个位置:
首先:将视频从HDD拖到项目标签[Xcode的左侧标签] 第二:从Xcode左侧标签,再次将同一视频文件拖到项目---&gt;构建阶段---&gt;复制捆绑资源
通常,复制包资源包含项目文件,但有时它们不包含视频文件。
现在运行项目并享受视频...... !!
祝你好运