我有问题,我不能通过html5在webview中播放视频,我的代码
webView = (WebView) findViewById(R.id.web);//new WebView(this);
webView.setBackgroundColor(android.R.color.transparent);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setPluginsEnabled(true);
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setDefaultZoom(WebSettings.ZoomDensity.FAR);
webView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
webView.loadUrl("file:///android_asset/index.html");
和mycode html
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<video autoplay="autoplay" controls="controls" style="align:center;" autobuffer onclick="this.play();">
<source src="birtday2527.theora.ogv" type="video/ogg" codecs="theora, vorbis"/>
<source src="birtday2527.mp4" type="video/mp4"/>
</video>
</body>
我通过测试得到了nexus。
答案 0 :(得分:1)
Webview = (WebView)findViewById(R.id.VWebview);
vWebview.getSettings().setJavaScriptEnabled(true);
vWebview.getSettings().setPluginsEnabled(true);
ViewContent(raw);
InputStream fileStream = getResources().openRawResource(R.raw.test);
int fileLen = fileStream.available();
byte[] fileBuffer = new byte[fileLen];
fileStream.read(fileBuffer);
fileStream.close();
String displayText = new String(fileBuffer);
vWebview.loadDataWithBaseURL("fake://not/needed", displayText, "text/html", "utf-8", "");
这是
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Hello World</title>
<body>
<div>
<p>
<video src="file:///android_asset/test.m4v" poster="file:///android_asset/test.jpg" onclick="this.play();"/>
</p>
</div>
</body>
</html>
答案 1 :(得分:0)
我认为webkit视频播放器只是启动视频播放器意图,您可以使用意图ACTION_VIEW直接调用它,并使用“video / *”mime类型。例如:
Intent newIntent = new Intent(android.content.Intent.ACTION_VIEW);
newIntent.setDataAndType(Uri.fromFile(file),mimeType);
newIntent.setFlags(newIntent.FLAG_ACTIVITY_NEW_TASK);
try {
context.startActivity(newIntent);
} catch (android.content.ActivityNotFoundException e) {
Toast.makeText(_context, "No app for this type of file.", 4000).show();
}