2

I'm trying to play a HTML5 video on a website in a UIWebView on iOS 8.

The website url is http://m.bild.de/video/clip/fifa-ballon-d-or/aufsager-ballon-dor-abend-39313060,variante=L,wantedContextId=39305342.bildMobile.html

The html code for the video looks like this:

<video controls="" preload="auto" src="http://videos-world.ak.token.bild.de/BILD/39/31/30/60/39313060,property=Video.mp4" poster="http://bilder.bild.de/fotos-skaliert/stand-aufsager-ballon-dor-abend-39313026/3,w=788,c=0.bild.jpg" style="width: 100%; height: 100%;"></video>

This code above will be loaded asynchronously and placed via javascript. I can not modify this html code.

As soon as the article is loaded i can see the play button on top of the video. When i tap it the button gets highlighted but nothing happens.

On iOS 7 it works. On iOS 8 is doesn't. When i open the article in Safari the video plays fine on iOS 7 and 8.

I've also added these two lines for the UIWebView, but it still doesn't play.

self.webView.allowsInlineMediaPlayback = YES;
self.webView.mediaPlaybackRequiresUserAction = NO;
Lukas Würzburger
  • 6,543
  • 7
  • 41
  • 75

3 Answers3

8

I had exactly the same problem (using iOS 8.3). After trying a lot of different flags (allowsInlineMediaPlayback etc.), nothing worked argh!

After some time, I've downloaded a demo from here, which worked right away in iOS 8.3

In this repository, there is a working demo of an uiwebview showing an mp4 video, loaded locally. I've changed the code to show the intended website. I've replaced my video, with the video from the demo and it worked immediately. So my problem was originated in the video, which I converted from a wmv file into H264 (mp4).

The video was around 3 seconds in length and the only way to get it working, was to put it in a new project in Adobe After Effects and export it again. After that it worked with the following code:

Objective-C:

NSString *urlAddress = @"http://mywebsite.com/";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView setAllowsInlineMediaPlayback:YES];
self.webView.mediaPlaybackRequiresUserAction = NO;
[webView loadRequest:requestObj];

HTML:

<video id="startpagevideo" loop autoplay>
    <source src="./video/mighty5.mp4" type="video/mp4;"/>
</video>

So with a properly encoded video it worked in iOS 8.3

Cheers Chris

Mohsin Khubaib Ahmed
  • 1,008
  • 16
  • 32
Chris
  • 2,296
  • 4
  • 27
  • 46
  • This answer help my problem. I added these 2 lines before webview load request `[webView setAllowsInlineMediaPlayback:YES]; self.webView.mediaPlaybackRequiresUserAction = NO;` Thank you Chris. – Dody Rachmat Wicaksono Sep 02 '15 at 23:14
0

Have you tried taking the preload attribute out? We had a similar issue with content in or UIWebView app and that seemed to resolve it.

0

Check on you app's Info.plist the key:

App Transport Security Settings > Allow Arbitrary Loads = true

I hope help someone! :)

screenshot

Danilo
  • 59
  • 4