1

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

在此处输入图像描述

我希望 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);
}
4

1 回答 1

0

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

我必须创建一个新的WebChromeClient、压倒一切onShowCustomView(View view, WebChromeClient.CustomViewCallback callback)onHideCustomView()

于 2012-10-22T04:58:12.913 回答