Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIWebview dos not playing mp4 Video

I tried to play a .mp4 video from a website ( with the HTML5 Video Tag ) with the UIWebView. The iPhone / iPad Device and Simulator only shows a black frame with a struck out play button. If I just called this website on the Safari Mac Version, it is possible to play it. Whats the matter?

It isn't a local file. The html looks like this:

    <?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>
like image 429
iach Avatar asked Dec 18 '12 10:12

iach


6 Answers

It may not be in an iPhone-friendly format.

Drag the mp4 file into iMovie and then click on Share -> Export Movie and select one of the iPhone-compatible formats.

like image 64
Vinny Coyne Avatar answered Nov 16 '22 15:11

Vinny Coyne


One of the ways that video can fail to play in a UIWebView is if the web server hosting the video file doesn't support byte ranges. UIWebView doesn't download the entire .mp4 file at once; instead, it streams the video by requesting portions of the file. Most servers these days support byte ranges, but if yours doesn't, or if you've turned it off for some reason, you won't be able to serve video to an iOS device.

like image 34
Caleb Avatar answered Nov 16 '22 14:11

Caleb


Sounds like a codec issue. You can see what codecs the file uses if you open it in VLC on you computer , go to Window->Media Information->Codec Details. The answer here links to Apple's docs where you will find supported video and audio codecs:

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

like image 3
Brendon Avatar answered Nov 16 '22 15:11

Brendon


It may be a problem with the relative ../ path you're using. Try using a full absolute path - starting with http://.

like image 1
Luke Avatar answered Nov 16 '22 14:11

Luke


I also have this problem,I have 2 .mp4 but one can use and one not, I try to format type file.mp4 to .mp4 for IPad and It's work,I think you should try.

like image 1
Masataga.Takashi Avatar answered Nov 16 '22 14:11

Masataga.Takashi


I was searching for the same thing in a C#.NET Core Ios Webview App. For me setting these switches on the WebView control (after setting the html in the webview):

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

Worked for me.

like image 1
ikwillem Avatar answered Nov 16 '22 16:11

ikwillem