10

我尝试使用 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”&lt;/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>
4

7 回答 7

10

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

将 mp4 文件拖到 iMovie 中,然后单击“共享” -> “导出电影”并选择一种与 iPhone 兼容的格式。

于 2013-02-21T17:23:13.117 回答
4

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

于 2013-02-22T17:13:46.533 回答
3

听起来像一个编解码器问题。如果您在计算机上的 VLC 中打开文件,您可以查看该文件使用的编解码器,转到 Window->Media Information->Codec Details。此处的答案链接到 Apple 的文档,您可以在其中找到支持的视频和音频编解码器:

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

于 2013-02-19T16:15:31.693 回答
1

../您使用的相对路径可能有问题。尝试使用完整的绝对路径 - 从http://.

于 2013-02-21T19:46:45.033 回答
1

我在 C#.NET Core Ios Webview 应用程序中搜索相同的内容。对我来说,在 WebView 控件上设置这些开关(在 webview 中设置 html 之后):

WebView.AllowsLinkPreview = true;
WebView.AllowsInlineMediaPlayback = true;
WebView.AllowsPictureInPictureMediaPlayback = true;

为我工作。

于 2018-09-28T15:55:09.177 回答
0

我也有这个问题,我有2个,.mp4但一个可以使用,一个不能,我尝试将类型文件格式化.mp4.mp4iPad并且它的工作,我认为你应该尝试。

于 2014-02-10T08:27:48.850 回答
-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 左侧选项卡,再次将相同的视频文件拖到项目--->构建阶段--->复制捆绑资源

通常,Copy bundle Resources 包含项目文件,但有时它们不包含视频文件。

现在运行项目并欣赏视频......!

祝你好运

于 2015-08-23T18:50:36.537 回答