2
    WebView wvVideo = (WebView) findViewById(R.id.wvVideo);
    String ytVideo= "<html><body><iframe width='350' height='160' src='www.youtube.com/watch?v=yqNGzYsPN6M' frameborder='0' allowfullscreen></iframe></body></html>";
    wvVideo.getSettings().setPluginsEnabled(true);
    wvVideo.getSettings().setAllowFileAccess(true);
    wvVideo.getSettings().setPluginState(PluginState.ON);
    wvVideo.getSettings().setBuiltInZoomControls(true);
    wvVideo.getSettings().setJavaScriptEnabled(true);
    wvVideo.loadData(ytVideo, "text/html", "utf-8");

它只显示缩略图,当我点击它时,它没有播放。只是显示黑屏。我的 API 目标是 15,我为此设置了所有必需的权限,但仍然无法正常工作。

4

1 回答 1

0

您的设置似乎很好。
至于我,以下设置在我播放 HTML5 视频的项目中完成了工作。试试看

   webview.getSettings().setJavaScriptEnabled(true);
    webview.getSettings().setDomStorageEnabled(true); // I think you will need this one
    webview.getSettings().setPluginState(PluginState.ON);
    webview.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);// no need I think

    webview.getSettings().setLoadWithOverviewMode(true);
    webview.getSettings().setUseWideViewPort(true);
    webview.getSettings().setBuiltInZoomControls(true);
    webview.setInitialScale(1);

   webview.setWebChromeClient(new WebChromeClient()); // dont forget this one

将 android:hardwareAccelerated="true" 添加到清单文件中。

   <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" 
        android:hardwareAccelerated="true">
于 2013-06-19T04:34:15.920 回答