使只有布局土地的Andr​​oid全屏播放时videoView [英] make a fullScreen in only layout-land android when play videoView

查看:131
本文介绍了使只有布局土地的Andr​​oid全屏播放时videoView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创建Android应用程序发挥直播,我添加了videoView在我layout.xml并添加布局土地文件夹

I'm creating android app to play liveStream, I added the videoView in my layout.xml and added the folder of layout-land

我想使应用程序显示仅布局土地的视频全屏没有人像

I want to make the app shows video full screen in only layout-land not portrait

所以我增加了以下code中的onCreate():

so I added the following code in onCreate():

public void onConfigurationChanged(Configuration newConfig){
if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE
   {
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
   } else 
    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,    WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }
}

但我的问题是,当我旋转设备将重新启动活动,这导致视频停止流,我想prevent这一点。所以。我加了体现这一行

but my problem is when I rotate the device it restarts the activity and this lead the stream of video to stop and I want to prevent this. So. I added to manifest this line

 android:configChanges="keyboard|keyboardHidden|orientation|screenSize"

但是这会导致的onCreate的code()进行一次只能执行。

but this leads the code of onCreate() to be executed once only.

如何让我的应用程序持续播放视频流,当我旋转装置,使布局土地全屏那么当回肖像使其正常吗?

How to make my app plays the video stream continuously and when I rotate device to make full screen in layout land then when back to portrait make it normal?

希望任何人得到了我的意思。
先谢谢了。

Hope that anyone got my mean. Thanks in advance.

推荐答案

您应该添加您的videoview(或内容母公司)作为您的布局文件最后一个元素。并使用下一个code:

You should add your videoview (or content Parent) as last element in your layout file. and use the next code:

private RelativeLayout.LayoutParams paramsNotFullscreen; //if you're using RelativeLatout           

@Override
public void onConfigurationChanged(Configuration newConfig) 
{
    super.onConfigurationChanged(newConfig);


    if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) //To fullscreen
    {
        paramsNotFullscreen=(RelativeLayout.LayoutParams)mVideoView.getLayoutParams();
        RelativeLayout.LayoutParams params=new LayoutParams(paramsNotFullscreen);
        params.setMargins(0, 0, 0, 0);
        params.height=ViewGroup.LayoutParams.MATCH_PARENT;
        params.width=ViewGroup.LayoutParams.MATCH_PARENT;
        params.addRule(RelativeLayout.CENTER_IN_PARENT);
        mVideoView.setLayoutParams(params);

    } 
    else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) 
    {
        mVideoView.setLayoutParams(paramsNotFullscreen);
    }
}

它得到videoview的LayoutParams的副本,并在一个全局变量保存它。然后创建一个新的LayoutParams与previous值对象,但现在设置为match_parent的限制,并将其设置在videoview。您现在videoview在全屏。当你把你的设备的肖像,paramsNotFullscreen恢复previous值。

It gets a copy of videoview layoutparams and saves it in a global variable. then creates a new layoutparams object with the previous values but setting now the limits to match_parent and sets it in your videoview. You videoview now is in fullscreen. When you put your device in portrait, paramsNotFullscreen restores previous values.

对不起,我的英语不好。

Sorry, my english is bad.

这篇关于使只有布局土地的Andr​​oid全屏播放时videoView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆