如何在有视频的网站中响应全屏按钮

时间:2012-10-09 06:28:02

标签: android webview android-webview android-view android-video-player

我使用webview播放来自varios网站的视频,其中一些还有一个全屏按钮

enter image description here

我希望webview能够响应全屏按钮。

如果我设置webSettings.setUseWideViewPort(false);,那么当点击全屏按钮时视频会卡住,我可以在logcat上看到以下错误:

10-09 08:32:27.970: D/gralloc(31814): unmmap  pid(1876), vaddr(0x589dc000)
10-09 08:32:27.970: E/gralloc(31814): [GR_MD] unmapping from 0x5786c000, size=33427456
10-09 08:32:27.970: D/gralloc(31814): unmmap  pid(1876), vaddr(0x5a9fb000)
10-09 08:32:27.970: E/gralloc(31814): [GR_MD] unmapping from 0x5984d000, size=33427456
10-09 08:32:27.975: D/gralloc(31814): unmmap  pid(1876), vaddr(0x5e616000)
10-09 08:32:27.975: E/gralloc(31814): [GR_MD] unmapping from 0x5d42a000, size=33427456

我正在使用Android 4.0.1,这是我的代码:

setWebViewSettings(mVideoWebView);
String data_html = "<!DOCTYPE HTML> <html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:og=\"http://opengraphprotocol.org/schema/\" xmlns:fb=\"http://www.facebook.com/2008/fbml\"> <head></head> <body style=\"margin:0 0 0 0; padding:0 0 0 0;\"> <iframe src=\"http://www.dailymotion.com/embed/video/xu4vre\" width=\"300\" height=\"162"\" frameborder=\"0\"></iframe> </body> </html> ";
mVideoWebView.loadData(data_html, "text/html", null);


public static void setWebViewSettings(WebView webview) {
    WebSettings webSettings = webview.getSettings();
    webSettings.setPluginState(PluginState.ON);
    webSettings.setJavaScriptEnabled(true);
    webSettings.setAllowFileAccess(true);
    webSettings.setLoadWithOverviewMode(false); // zoom y/n
    webSettings.setUseWideViewPort(true); // true = like desktop
    webSettings.setPluginsEnabled(true);

    //webSettings.setAllowContentAccess(true);
    webSettings.setAllowFileAccess(true);
    //webSettings.setAllowFileAccessFromFileURLs(true);
    //webSettings.setAllowUniversalAccessFromFileURLs(true);
    webSettings.setDatabaseEnabled(true);
    webSettings.setGeolocationEnabled(true);
    webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
    webSettings.setDomStorageEnabled(true);
}

1 个答案:

答案 0 :(得分:0)

在这里找到我的答案: https://stackoverflow.com/a/12850816/475472

我必须创建新的WebChromeClient,覆盖onShowCustomView(View view, WebChromeClient.CustomViewCallback callback)onHideCustomView()