....I was able to narrow down the problem to the onMeasure function in the VideoView class. By creating a child class and overriding the onMeasure function, I was able to get the desired functionality.


public class VideoViewCustom extends VideoView {    private int mForceHeight = 0;    private int mForceWidth = 0;    public VideoViewCustom(Context context) {        super(context);    }    public VideoViewCustom(Context context, AttributeSet attrs) {        this(context, attrs, 0);    }    public VideoViewCustom(Context context, AttributeSet attrs, int defStyle) {        super(context, attrs, defStyle);    }    public void setDimensions(int w, int h) {        this.mForceHeight = h;        this.mForceWidth = w;    }    @Override    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {        Log.i("@@@@", "onMeasure");        setMeasuredDimension(mForceWidth, mForceHeight);    }}

Then inside my Activity I just did the following:

@Overridepublic void onConfigurationChanged(Configuration newConfig) {    super.onConfigurationChanged(newConfig);    if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);        questionVideo.setDimensions(displayHeight, displayWidth);        questionVideo.getHolder().setFixedSize(displayHeight, displayWidth);    } else {        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN, WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);        questionVideo.setDimensions(displayWidth, smallHeight);        questionVideo.getHolder().setFixedSize(displayWidth, smallHeight);    }}

The line:

questionVideo.getHolder().setFixedSize(displayWidth, smallHeight); 

is key in order to make this work. If you do the setDimensions call without this guy, the video still will not resize.

The only other thing you need to do is ensure that you call setDimensions() inside the onCreate() method as well or your video will not start buffering as the video won't be set to draw on a surface of any size.

// onCreate() questionVideo.setDimensions(initialWidth, initialHeight); 

One last key part - if you ever find yourself wondering why the VideoView isn't resizing on rotation, you need to ensure the dimensions you're resizing to are either exactly equal to the visible area or less than it. I had a really big problem where I was setting the VideoView's width/height to the entire display size when I still had the notification bar/title bar on the screen and it was not resizing the VideoView at all. Simply removing the notification bar and title bar fixed the problem.

Hopefully this helps someone in the future!


转贴:http://stackoverflow.com/questions/4434027/android-videoview-orientation-change-with-buffered-video


更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. 教你 2 种从 Linux 终端下载文件的方法
  2. 第四届大数据科学与工程国际会议(2019)
  3. 面向边缘计算的资源优化技术研究进展
  4. js之留言板与数组字符串函数
  5. Go微服务入门到容器化实践,落地可观测的微
  6. Server Core App Compatibility
  7. 不产生第三个临时变量的前提交换两组数据
  8. YOLOv5目标检测实战:Jetson Nano部署
  9. 基于安全压缩感知的大数据隐私保护
  10. 专题导读:大数据隐私保护