使内容嵌入视频到iframe中| android

时间:2019-04-24 16:02:27

标签: javascript java android iframe

我有一个Webview,其中有一个嵌入式iframe,可以显示来自不同站点的视频。该应用程序具有旋转功能,可隐藏活动中的所有其他视图并使Webview全屏显示(宽度和高度= match_parent)。

当处于纵向模式时,Web视图可以完美地适合内容,但是当屏幕旋转时,iframe中的视频突然变得比Web视图高,并且Web视图变得可滚动(您可以上下滚动以查看控件和标题)。在横向模式下,像在纵向模式下一样,它不能滚动,仅适合所有内容。

我试图弄乱容器的高度和宽度以及div,但没有运气。

这是我如何在Webview中放置内容:

<style>.video-container { position: absolute; background-color: black;padding-bottom: 56.25%; padding-top: 0px; height: auto; width: auto; top: 0; left: 0; right: 0; bottom: 0; overflow: hidden; }.video-container iframe { position: absolute; top:0; left: 0; right: 0; bottom: 0; width: 100%; height: 100%; overflow: hidden; }.body {background-color: black;}</style><div class="video-container"><iframe width="480" height="270" src="https://www.youtube.com/embed/UtagUSECwOw?feature=oembed" scrolling="no" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="0"></iframe></div>

然后将其加载到webview中,如下所示:

wbVideoPlayer.loadDataWithBaseURL("", getFixedIframe(content.getContentUrl()), "text/html", "UTF-8", "");

这是我的onConfigurationChanged方法:

public void onConfigurationChanged(Configuration config) {
        super.onConfigurationChanged(config);
        switch (config.orientation) {

            case Configuration.ORIENTATION_LANDSCAPE:
                getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
                getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
                hideAll();
                flVideo.setBackground(ContextCompat.getDrawable(this, android.R.color.black));

                width = dm.widthPixels; //320
                height = dm.heightPixels; //480

                wbVideoPlayer.getSettings().setLoadWithOverviewMode(true);
                wbVideoPlayer.getSettings().setUseWideViewPort(true);
                wbVideoPlayer.setPadding(0, 0, 0, 0);
                wbVideoPlayer.setInitialScale(1);
                wbVideoPlayer.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);

                LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
                flVideoLayout.setLayoutParams(lp);

                break;

            case Configuration.ORIENTATION_PORTRAIT:
                getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
                getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
                showAll();
                flVideo.setBackground(ContextCompat.getDrawable(this, android.R.color.white));

                LinearLayout.LayoutParams lp1 = new LinearLayout.LayoutParams(width, (int) (250 * density));
                flVideoLayout.setLayoutParams(lp1);

                break;
        }

    }

任何帮助将不胜感激。谢谢!

0 个答案:

没有答案