【问题标题】:UIWebview dos not playing mp4 VideoUIWebview 不播放 mp4 视频
【发布时间】:2012-12-18 10:26:03
【问题描述】:

我尝试使用 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>
&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>

【问题讨论】:

  • 是本地文件中的视频,您可以发布您的HTML 代码。
  • 如果您只想播放该网站中的视频,请查看VideoPlayerKit
  • 刚刚查看了http://my.barackobama.com . . ./video/shared-culture.mp4 的页面源代码,它声明了带有type="application/x-shockwave-flash" 属性的电影嵌入标签。对于 Apple HLS,您需要 MPEG2.TS 容器中的 H.264/AVC。 HLS 文档在这里:developer.apple.com/resources/http-streaming
  • @RichTolley 您应该将其作为答案而不是评论。
  • 在实际设备上玩累了吗??

标签: ios video uiwebview screen frame


【解决方案1】:

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

将 mp4 文件拖入 iMovie,然后点击 Share -> Export Movie 并选择一种与 iPhone 兼容的格式。

【讨论】:

  • 我必须使用 Adob​​e Media Encoder 重新编码我的视频才能使其正常工作 (iOS 8.3)。我的视频很短(3 秒)。
【解决方案2】:

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

【讨论】:

    【解决方案3】:

    听起来像是编解码器问题。如果您在计算机上的 VLC 中打开文件,您可以查看该文件使用的编解码器,转到 Window->Media Information->Codec Details。答案here 链接到 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

    【讨论】:

      【解决方案4】:

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

      【讨论】:

        【解决方案5】:

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

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

        为我工作。

        【讨论】:

          【解决方案6】:

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

          【讨论】:

            【解决方案7】:

            在 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 左侧选项卡,再次将相同的视频文件拖到项目--->构建阶段--->复制捆绑资源

            通常,复制包资源包含项目文件,但有时它们不包含视频文件。

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

            祝你好运

            【讨论】:

            • 我尝试在两个 webview 中播放两个视频,但只播放单个视频。
            猜你喜欢
            • 2018-04-16
            • 2021-05-06
            • 1970-01-01
            • 1970-01-01
            • 2011-05-05
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多