【发布时间】:2016-04-25 06:37:56
【问题描述】:
我想使用 android webview 播放 youtube 视频。 但我想让我的 webview 适合 youtube 视频大小。到目前为止,我的实现如下所示。
String vid = TextUtils.extractYoutubeVId(body);
if (StringUtils.isBlank(vid)) {
return null;
}
String html = "<html > <head></head> <body style=\"margin:0 0 0 0; padding:0 0 0 0;\"> <iframe width=\"100%\" height=\"100%\" src=\"http://www.youtube.com/embed/___\" frameborder=\"0\"></iframe> </body> </html> ";
html = html.replace("___", vid);
mImportedVideoWebview.setWebChromeClient(new WebChromeClient());
WebSettings webSettings = mImportedVideoWebview.getSettings();
webSettings.setJavaScriptEnabled(true);
mImportedVideoWebview.loadData(html, "text/html", "utf-8");
mImportedVideoWebview 只是一个 WebView,它的宽度是 MATCH_PARENT,高度是 350dp。
通过使用上面的代码,我可以播放 youtube 视频。
但是,我想将我的 webview 宽度设置为屏幕宽度,并将我的 webview 高度与 youtube 视频高度成比例。请大家帮帮我!
谢谢!
【问题讨论】: