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,我为此设置了所有必需的权限,但仍无效。
答案 0 :(得分: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">