我正在尝试使用 Amazon WebView 组件为 Amazon FireTV 开发视频应用程序。我无法让视频自动播放,我尝试使用 HTML5 视频 DOM 属性和事件,还设置了视频标签属性autoplay="autoplay"。这是HTML代码:
<!DOCTYPE html>
<html>
<head>
<title>Test player</title>
<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function () {
console.log('DOM Loaded!');
var player = document.getElementById('video-player');
player.autostart = true;
player.src = "http://www.w3schools.com/html/mov_bbb.mp4";
player.load();
player.addEventListener("canplay", function () { console.log('play'); document.getElementById('video-player').play(); }, false);
}, false);
</script>
</head>
<body>
<video style="background: #e0e0e0; width: 400px; height: 320px;" id="video-player" controls="controls" src="" autoplay="autoplay" >Your browser does not support Video rendering</video>
<br />
</body>
</html>
初始化WebView的Java代码如下(在onCreate方法中):
this.wrapper = (AmazonWebView) findViewById(R.id.wrapper);
factory.initializeWebView(this.wrapper, 0xFFFFFF, false, null);
this.wrapper.setFocusable(false); // Never allow focus on the WebView because it blocks the Play/Pause, Fast Forward and Rewind buttons
AmazonWebChromeClient webClient = new AmazonWebChromeClient();
this.wrapper.setWebChromeClient(webClient); // Needed in order to use the HTML5 <video> element
AmazonWebSettings browserSettings = this.wrapper.getSettings();
browserSettings.setPluginState(AmazonWebSettings.PluginState.ON);
browserSettings.setJavaScriptEnabled(true);
this.wrapper.addJavascriptInterface(new JSChannel(this.wrapper), "appChannel");
browserSettings.setUseWideViewPort(true);
我还在清单中设置了互联网权限和硬件加速。我是否需要在 Java 代码中添加一些内容才能自动播放视频?