【问题标题】:how to play video in webview by html 5如何通过html 5在webview中播放视频
【发布时间】:2011-06-24 10:28:39
【问题描述】:

我有问题,我的代码无法通过 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");

这里是我的代码 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。

【问题讨论】:

    标签: android


    【解决方案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>
    

    【讨论】:

    【解决方案2】:

    我认为 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();
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-05-17
      • 1970-01-01
      • 1970-01-01
      • 2013-06-02
      • 1970-01-01
      • 2013-10-15
      • 1970-01-01
      相关资源
      最近更新 更多