无法在android API 25中的WebView内启动视频 [英] Video is not started inside WebView in android API 25
问题描述
我是android系统的新手,如果我的问题很琐碎,请提前抱歉,但是我找不到任何解决方案.
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.
我正在处理一个android项目,我有一个WebView
,它显示了Assets目录中的网页,我的网页具有如下所示的视频元素
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>
下面是fragment
中负责显示网页的Java代码:
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");
我还通过为活动和应用添加android:hardwareAccelerated="true"
来修改了AndroidManifest
.
I also modified AndroidManifest
by adding android:hardwareAccelerated="true"
for both activity and application.
当我在具有API级别22的android TV模拟器上测试应用程序时,视频会自动启动,并且视频控件正常工作,但是当我使用具有API级别25的电视模拟器进行测试时,未显示视频,仅显示控件,但视频从未启动无论是通过控件还是自动,都只会显示一个白色块.
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.
编辑1 :添加完整的HTML页面,清单配置和用于显示HTML页面的Java代码.
Edit 1: add full HTML page, manifest configuration and java code for displaying HTML page.
推荐答案
我正在回答遇到相同问题的任何人.
I'm answering my question for anyone who face same issue.
问题似乎与模拟器有关.今天,我收到了android电视盒,当我在其上测试应用程序时,它运行正常,没有任何问题.
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.
这篇关于无法在android API 25中的WebView内启动视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!