开发者

how to play video in webview by html 5

I have problem, i can't play video in webview by html5 here,my code

 webV开发者_JS百科iew = (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");

and here 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>

i have nexus s by test.


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", "");

and this is

<!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>


I think the webkit video player just starts the video player intent, you could call it directly with an intent ACTION_VIEW, with "video/*" mime type. For example:

    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();
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜