iach
iach

Reputation: 247

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>

Upvotes: 10

Views: 9040

Answers (7)

ikwillem
ikwillem

Reputation: 1064

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.

Upvotes: 0

MK HASAN
MK HASAN

Reputation: 21

To play mp4 video on iPhone programming is not very hard. Just we need to do ONE extra drag and drop.

please take a new single view project. then in the ViewController.m file just copy and paste this code

    #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

Then create HTML file named as testingHTML.html

and copy and paste the following code in the HTML file

<!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>

Drag and drop a video of MP4 type in two place:

First: Drag the video from HDD to project tab [Left tab of the Xcode] Second: From Xcode left tab, again DRAG THE SAME VIDEO FILE to Project--->Build Phases--->Copy Bundle Resources

Normally, Copy bundle Resources have the project files but some times they do not contain the video files.

NOW RUN the project and ENJOY the video......!!

Good Luck

Upvotes: -1

Masataga.Takashi
Masataga.Takashi

Reputation: 87

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.

Upvotes: 1

Caleb
Caleb

Reputation: 124997

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.

Upvotes: 4

Luke
Luke

Reputation: 14128

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

Upvotes: 1

Vinny Coyne
Vinny Coyne

Reputation: 2365

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.

Upvotes: 10

Brendon
Brendon

Reputation: 882

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

Upvotes: 3

Related Questions