Video from local storage not playing in WebView (X

2020-03-03 05:17发布

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.

5条回答
SAY GOODBYE
2楼-- · 2020-03-03 05:55

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.

查看更多
乱世女痞
3楼-- · 2020-03-03 06:08

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>
查看更多
女痞
4楼-- · 2020-03-03 06:09

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

self.webView.mediaPlaybackRequiresUserAction = NO;
self.webView.allowsPictureInPictureMediaPlayback = YES;
查看更多
姐就是有狂的资本
5楼-- · 2020-03-03 06:11

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

查看更多
We Are One
6楼-- · 2020-03-03 06:17

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.

查看更多
登录 后发表回答