gpt4 book ai didi

android - 如何通过 html 5 在 webview 中播放视频

转载 作者:行者123 更新时间:2023-11-30 04:38:12 24 4
gpt4 key购买 nike

我有问题,我无法通过 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 s。

最佳答案

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>

关于android - 如何通过 html 5 在 webview 中播放视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6466536/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com