我一直试图使用iframe播放全屏视频,但我无法让它发挥作用。以下是我使用的代码:
public String getHTML() {
String html= "<iframe width=\"100%\" height=\"100%\" frameborder=\"0\" scrolling=\"no\" align=\"center\"" +
"src=\"http://www2.whatsupcams.com/wucf_mod_2.php?id=si_bohinj2&autoplay=true\">" +
"</iframe>";
return html;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}
this.setContentView(R.layout.activity_webcam);
mWebView = (WebView) this.findViewById(R.id.webView);
mWebView.setBackgroundColor(Color.BLACK);
mWebView.getSettings().setBuiltInZoomControls(true);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setFocusable(true);
mWebView.setFocusableInTouchMode(true);
mWebView.setWebChromeClient(new WebChromeClient());
mWebView.setWebViewClient(new WebViewClient());
String data_html = getHTML();
mWebView.loadData(data_html, "text/html", "UTF-8");
}
视频有效,但问题是我无法使iframe适合屏幕,对于高清屏幕来说,它太小或太大。它在当前配置下太大了,查看stackoverflow我发现:
mWebView.getSettings().setBuiltInZoomControls(true);
mWebView.getSettings().setLoadWithOverviewMode(true);
可以做到这一点,但它会使图像太小,有没有办法让iframe使用整个屏幕?我正在考虑设置缩放以适应屏幕,因为当我双击iframe时,缩放看起来像是适合填充屏幕。感谢。