在webView Android中播放DailyMotion视频

时间:2013-02-05 17:16:55

标签: android webview

我尝试在网页浏览中嵌入dailyMotion视频,但是我得到了预览但是当我尝试播放时,它无效。

我一直在网上寻找解决方案,我找不到任何有效的例子。

这个代码

String data_html = "<!DOCTYPE HTML> <html>"
            + "<head>"
            + "<style>"
            + "body"
            + "{"
            + "margin:0;"
            + "padding:0;"
            + "height: 100%;"
            + "width: 100%;"
            + "background-color: #000;"
            + "color: #fff;"
            + "font-family: sans-serif;"
            + "overflow: hidden;"
            + "-webkit-tap-highlight-color: rgba(0, 0, 0, 0);" /* Disable ugly Android highlight */
            + "}"
            + "</style>"
            + "</head>"
            + "<body>"
            + "<iframe src=\"http://www.dailymotion.com/embed/video/xu4vre\" width=\"300\" height=\"160\" frameborder=\"0\"></iframe>"
            + "</body>" + "</html>";

    webView.loadData(data_html, "text/html", null); 

1 个答案:

答案 0 :(得分:1)

在Dailymotion中获取您的视频嵌入代码并将其分配为videoHtml;

    webView = (WebView) findViewById(R.id.webView1);
    videoHtml = "<iframe frameborder=\"0\" width=\"480\" height=\"270\" src=\"http://www.dailymotion.com/embed/video/xznb64\"></iframe><br /><a href=\"http://www.dailymotion.com/video/xznb64_leyla-ile-mecnun-dan-evlilik-programlarina-gonderme_news\" target=\"_blank\">Leyla İle Mecnun&#039;dan Evlilik Programlarına...</a> <i>ile  <a href=\"http://www.dailymotion.com/trthaber\" target=\"_blank\">trthaber</a></i>";
    webView.loadData(videoHtml, "text/html", "UTF-8");
    webView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setPluginsEnabled(true);
相关问题