Video is not started inside WebView in android API 25

≡放荡痞女 提交于 2019-12-25 01:25:25

问题


I'm new to android and sorry in advance if my question is trivial but I was not able to find any solution for it.

I'm working on an android project and I have a WebView that displays a web page from the assets directory, my web page has a video element as shown below

<!DOCTYPE html> 
<html> 
<head>
    <meta charset="utf-8">
    <title>video player</title>
</head>
<body> 
    <video width="400" controls autoplay loop muted>
        <source src="./assets/video/video1.webm" type="video/webm">
    </video>
</body> 
</html>

Below is java code from the fragment that is responsible of displaying web page:

mWebView.setWebContentsDebuggingEnabled(true);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
mWebView.getSettings().setMediaPlaybackRequiresUserGesture(false);
mWebView.getSettings().setAllowFileAccess(true);
mWebView.setWebChromeClient(new WebChromeClient());
mWebView.setWebViewClient(new WebViewClient());
mWebView.loadUrl("file:///android_asset/www/video1.html");

I also modified AndroidManifest by adding android:hardwareAccelerated="true" for both activity and application.

When I test application on android TV emulator with API level 22 video start automatically and video controls are working properly, but when I test it using TV emulator with API level 25 video is not displayed only controls are shown but the video never started either from controls or automatically, only a white block is displayed.

Edit 1: add full HTML page, manifest configuration and java code for displaying HTML page.


回答1:


I'm answering my question for anyone who face same issue.

It seems that the issue is emulator related. Today I received my android TV box and when I test my application on it, it is working fine with no issues.



来源:https://stackoverflow.com/questions/53691526/video-is-not-started-inside-webview-in-android-api-25

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!