Android 如何通过HTML5在webview中播放视频
我有问题,我不能用html5在webview中播放视频,我的代码Android 如何通过HTML5在webview中播放视频,android,Android,我有问题,我不能用html5在webview中播放视频,我的代码 webView = (WebView) findViewById(R.id.web);//new WebView(this); webView.setBackgroundColor(android.R.color.transparent); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setPluginsEnabled(t
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 s。我认为webkit视频播放器只是启动了视频播放器intent,您可以使用intent ACTION\u视图直接调用它,使用“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();
}
我认为webkit视频播放器只是启动了视频播放器intent,您可以使用intent ACTION_视图直接调用它,使用“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();
}
这是
<!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>
你好,世界
这是
<!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>
你好,世界
什么是显示文本和fake://not/neededwhat 是显示文本和fake://not/needed