首页 文章

UIWebview dos不播放mp4视频

提问于
浏览
8

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

7 回答

  • 2

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

    将mp4文件拖到iMovie中,然后单击 Share - > Export Movie 并选择一种与iPhone兼容的格式 .

  • 0

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

  • 9

    听起来像编解码器问题 . 如果在计算机上的VLC中打开文件,可以查看文件使用的编解码器,转到窗口 - >媒体信息 - >编解码器详细信息 . 答案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

  • 0

    您正在使用的相对 ../ 路径可能存在问题 . 尝试使用完整的绝对路径 - 从 http:// 开始 .

  • -1

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

  • 4

    我在C#.NET Core Ios Webview App中搜索同样的东西 . 对我来说,在WebView控件上设置这些开关(在webview中设置html之后):

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

    为我工作 .

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

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

    现在运行该项目并享受视频...... !!

    祝好运

相关问题