请看重点:重点在最下边哦
android:screenOrientation设定该活动的方向,该值可以是任何一个下面的字符串:
"unspecified"
- 默认值,由于系统方向
"landscape"
- 横向
"portrait"
- 纵向
"user"
- 用户当前的首选方向
"behind"
- 与活动堆栈下的活动相同方向
"sensor"
- 跟物理方向传感器确定方向,取决于用户手持方向,根據物理方向傳感器確定方向. 取決於用戶手持的方向横竖有关當
"nosensor"
- 是Action默认关闭传感器,不随手持传感器确定方向,不会有变化
浅谈JZVideoPlayerStandard防京东视频播放第三方,因为在视频横竖屏切换的时候因为不走生命周期,只是调用之前的流,不想重新绘制的,但在横屏和竖屏时还会有此控件还是重新调用,重新实例化。
public void startWindowFullscreen() { Log.i(TAG, "startWindowFullscreen " + " [" + this.hashCode() + "] "); hideSupportActionBar(getContext()); ViewGroup vp = (JZUtils.scanForActivity(getContext()))//.getWindow().getDecorView(); .findViewById(Window.ID_ANDROID_CONTENT); View old = vp.findViewById(R.id.jz_fullscreen_id); if (old != null) { vp.removeView(old); } textureViewContainer.removeView(JZMediaManager.textureView); try { Constructorconstructor = (Constructor ) JZVideoPlayer.this.getClass().getConstructor(Context.class); JZVideoPlayer jzVideoPlayer = constructor.newInstance(getContext()); jzVideoPlayer.setId(R.id.jz_fullscreen_id); FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); vp.addView(jzVideoPlayer, lp); jzVideoPlayer.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN); jzVideoPlayer.setUp(dataSourceObjects, currentUrlMapIndex, JZVideoPlayerStandard.SCREEN_WINDOW_FULLSCREEN, objects); jzVideoPlayer.setState(currentState); jzVideoPlayer.addTextureView(); JZVideoPlayerManager.setSecondFloor(jzVideoPlayer); // final Animation ra = AnimationUtils.loadAnimation(getContext(), R.anim.start_fullscreen); // jzVideoPlayer.setAnimation(ra); JZUtils.setRequestedOrientation(getContext(), FULLSCREEN_ORIENTATION); onStateNormal(); jzVideoPlayer.progressBar.setSecondaryProgress(progressBar.getSecondaryProgress()); jzVideoPlayer.startProgressTimer(); CLICK_QUIT_FULLSCREEN_TIME = System.currentTimeMillis(); } catch (Exception e) { e.printStackTrace(); } }
这样也就重新绘制图像View,只不过流没有初始化而已,但我横竖屏切换时候是先初始化View然后走的onConfigurationChanged方法,这时候View视图已经生成完毕,导致我在切换时无法对view作出更多的控制。
所以找寻源码在点击横竖屏按钮时做想要的处理。再就是第一次进入状态、横竖切换状态、back返回状态
@Override public void onClick(View v) { try { int i = v.getId(); if (i == cn.jzvd.R.id.fullscreen) { if (currentScreen == SCREEN_WINDOW_FULLSCREEN) { //竖屏 } else { //横屏 } } else{
//back键 竖屏 }
}catch (Exception e){
e.printStackTrace();
}
super.onClick(v)
;}