无法使用的WebView播放视频 [英] Unable to play video using WebView
问题描述
我想使用的WebView功能来播放视频。
目前,我能够在我测试过(浏览器,Android版Chrome,Navegator为Android)所有浏览器打下面的HTML。不幸的是,我不能让它使用的WebView我自己的应用程序中播放:播放器的控件显示,但在点击播放按钮进行搜索栏去年底和进步圈发生,并永远不会结束。
以下是相关的code:
I'd like to play a video using WebView capabilities. Currently I'm able to play the following html in all browsers I've tested (Chrome, Chrome for Android, Navegator for Android). Unfortunately, I can not get it playing inside my own application using a WebView: the player's controls are shown, but clicking at play button make the seek bar goes to the end and a progress circle takes place and never ends. Here are the relevant code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video);
WebView webView = (WebView) findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setPluginState(PluginState.ON);
webView.setWebChromeClient(new WebChromeClient());
webView.loadUrl("file:///android_asset/www/index.html");
}
index.html的:
index.html:
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>video1</title>
</head>
<body>
<video id="video" controls height="240" width="360">
<source src="index.files/html5video/video1.m4v">
</video>
<script type="text/javascript">
var vid=document.getElementById('video');
vid.addEventListene('click', function () {
vid.play();
}, false);
</script>
</body>
您可以依赖的所有文件都放在正确的地方。
You can rely that all files are placed in the right place.
推荐答案
我知道这是一个古老的职位,但我有我的银河S3同样的问题。我这个解决它:
I know this is an old post, but I was having the same issue on my Galaxy S3. I solved it with this :
webView.SetWebChromeClient (new WebChromeClient ());
这工作就好在Nexus 7上没有这条线,但银河S3由于某种原因,它只是纺负载循环下去。
It worked just fine on Nexus 7 without this line, but on Galaxy S3 for some reason it just spun the loading circle forever.
请注意:我也有这些设置:
NOTE: I also have these set:
webView.Settings.PluginsEnabled = true;
webView.Settings.JavaScriptEnabled = true;
webView.Settings.SetPluginState (WebSettings.PluginState.On);
webView.SetWebViewClient (new WebViewClient ());
这篇关于无法使用的WebView播放视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!