6

I have an existing Xamarin Forms application, for Android and iOS, which shows some HTML content from local storage (the purpose is to view this content while offline) in WebView.

After the latest iOS update (12.2), the videos in that HTML stopped working. White background is shown on the place of the video, with the symbol "Play" but no action is possible.

The problem

I have tried changing the video tag to include autoplay, mute, but no success.

<video width="560" height="315" controls>
<source src="Absolute-3D.mp4" type="video/mp4">
</video>

I expect it to continue working as it was before the update, but something is blocking it.

  • Can you share the web url which contains the video? – nevermore Apr 11 '19 at 07:19
  • Hi @JackHua-MSFT, unfortunately the video is private.. I can't share it. What would you like to see? – Ana Kochevska Apr 11 '19 at 09:56
  • I need a webUrl that can reproduce this problem. Then I can test it on my side. – nevermore Apr 12 '19 at 08:20
  • 2
    Same problem here using JWplayer embbed in a webview. I sended a bugreport. It works in the safari browser but not inapp ! – Maypeur Apr 12 '19 at 13:50
  • Hi @JackHua-MSFT, Here is an example: https://github.com/anakochevska/VideoIssue – Ana Kochevska Apr 15 '19 at 14:04
  • I have the same problem. What I can ad is a warning in the Safari console, when tapping on the play button: Unhandled Promise Rejection: NotAllowedError: The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission. – butters Apr 15 '19 at 19:32
  • Well, when I run your example with a iOS 12.2 simluator, I can see a White background and a play button there, then I click the play button, the video played. Am I missing something or I need a real device? – nevermore Apr 17 '19 at 05:39
  • Oh, I didn’t recognize that this wasn’t mentioned when reading the post. The bug only occurs on a real device with iOS 12.2. Everything still works fine on the iOS 12.2 simulator. I also tried three or four different local videos on a real device in an html video tag. None of them worked, same behaviour Ana describes. – butters Apr 17 '19 at 15:19
  • 1
    Yes, the bug is only shown on real device, with iOS 12.2 . – Ana Kochevska Apr 18 '19 at 06:33

5 Answers5

2

It is a UIWebView bug , I add the below code, it works now.

self.webView.mediaPlaybackRequiresUserAction = NO;
self.webView.allowsPictureInPictureMediaPlayback = YES;
zhubch
  • 194
  • 1
  • 1
  • 8
  • Yes! "webView.mediaPlaybackRequiresUserAction = NO;" solved it for me. If you don't want auto-play, make sure you don't have "autoplay" in your HTML. I should point out that I'm not using Xamarin though. – Ernie Thomason May 10 '19 at 15:24
1

Try setting mediaPlaybackRequiresUserAction to NO for the webview. I'm seeing the same issue (UIWebView and WKWebView both) in iOS 12.2. Works fine in iOS 12.1 and earlier.

When debugging, you see this error in safari console:

Unhandled Promise Rejection: NotAllowedError: The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission

https://developer.apple.com/documentation/uikit/uiwebview/1617954-mediaplaybackrequiresuseraction?language=objc

https://developer.apple.com/documentation/webkit/wkwebviewconfiguration/1614727-mediaplaybackrequiresuseraction?language=objc

1800 INFORMATION
  • 131,367
  • 29
  • 160
  • 239
0

I replaced the UIWebView (Which is now deprecated) by the WKWebView and it seems to works again without changing anything in the html code.

There is a message in the console that say fullscreen is not authorized in the current context. For me too it only happens on real device.

Maypeur
  • 387
  • 4
  • 18
  • I haven't gotten WKWebView to work yet using a local video file on an actual device. I'm using loadHTMLString. Maybe a security issue. – Ernie Thomason May 10 '19 at 15:10
0

Unhandled Promise Rejection: NotAllowedError: The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission. It's not solved yet.

Jayxiang
  • 71
  • 3
-1

You need to add this to your plist

NSIncludesSubdomains and NSTemporaryExceptionAllowsInsecureHTTPLoads

Like this:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
    <key>NSIncludesSubdomains</key>
    <true/>
    <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
    <true/>
</dict>
visc
  • 4,794
  • 6
  • 32
  • 58