2012-12-18 106 views
8

我试图用UIWebView从网站(带有HTML5视频标签)播放.mp4视频。 iPhone/iPad设备和模拟器仅显示黑色框架,并弹出播放按钮。 如果我只是在Safari Mac版本上调用此网站,则可以播放它。 最新情况?UIWebview dos不能播放mp4视频

这不是本地文件。该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> 
&lt;video id="video1" controls="controls"&gt;      
    &lt;source src="../video/shared-culture.mp4" type="video/mp4"/&gt; 
    &lt;source src="../video/shared-culture.webm" type="video/webm"/&gt;  
&lt;/video&gt; 
         </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

是从本地文件的视频,你可以发布你的HTML代码。 – arthankamal

+0

如果您只想播放该网站中的视频,请查看[VideoPlayerKit](https://github.com/ign/VideoPlayerKit)。 –

+1

刚刚查看了http://my.barackobama.com上的网页源代码。 。 ./ video/shared-culture.mp4',它声明的电影嵌入标签的属性为:'type =“application/x-shockwave-flash”'。对于Apple HLS,您需要MPEG2.TS容器中的H.264/AVC。 HLS文档在这里:https://developer.apple.com/resources/http-streaming/ –

回答

2

听起来像一个编解码器问题。如果您在计算机上的VLC中打开它,可以看到该文件使用的编解码器,请转至窗口 - >媒体信息 - >编解码器详细信息。答案here链接到苹果的文档,你会发现支持的视频和音频编解码器:

https://developer.apple.com/library/ios/#documentation/mediaplayer/reference/MPMoviePlayerController_Class/Reference/Reference.html

https://developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/MultimediaPG/UsingAudio/UsingAudio.html

9

它可能不是在iPhone友好的格式。

将mp4文件到iMovie,然后点击分享 - >导出影片和选择的iPhone兼容的格式之一。

+0

我必须使用Adobe Media Encoder重新编码我的视频才能使其工作(iOS 8.3)。我的视频相当短(3秒)。 – Chris

1

这可能是因为您使用相对路径../一个问题。尝试使用完整的绝对路径 - 从http://开始。

4

一个是视频可能无法在一个UIWebView玩的方式是,如果托管的视频文件的Web服务器不支持字节范围。 UIWebView不会一次下载整个.mp4文件;相反,它通过请求文件的一部分来流式传输视频。现在大多数服务器都支持字节范围,但如果您的系统不支持,或者由于某种原因关闭了字节范围,则无法将视频提供给iOS设备。

0

我也有这个问题,我有2个.mp4但一个可以使用和一个没有,我尝试类型的文件.mp4格式化为.mp4 iPad和它的工作,我想你应该尝试。

-1

在iPhone上播放mp4视频编程不是很难。只是我们需要做一次额外的拖放操作。

请拍一个新的单视图项目。然后在ViewController.m文件只是在HTML文件复制并粘贴此代码

#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文件

复制并粘贴下面的代码

<!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 [email protected]</p> 

    </body> 
</html> 

将MP4类型的视频拖放到两个位置:

第一步:将视频从HDD拖动到项目选项卡[Xcode的左标签] 第二:从Xcode左侧选项卡,再次拖动相同的视频文件到项目--->构建阶段--->复制捆绑软件资源

通常情况下,复制束资源具有项目文件,但有时不包含视频文件。

立即运行该项目,享受视频......!

好运

+0

https://drive.google.com/file/d/0B-YyYsAL0QKLRWJRdHVxbXhwNUU/view?usp=sharing –

+0

我尝试在两个网页视图中播放两个视频,但只播放单曲视频。 –