简体   繁体   English

android VideoView 调整视频大小

[英]android VideoView resizes video

I have a custom VideoView, I'm overriding onMeasure method to make video fill the screen, while keeping proportions of the video file.我有一个自定义的 VideoView,我正在覆盖 onMeasure 方法以使视频填满屏幕,同时保持视频文件的比例。

Everything works fine, but with some videos, it has a strange behaviour:一切正常,但对于某些视频,它有一个奇怪的行为:

I put an interrupt point in onMeasure method and run in debug mode.我在 onMeasure 方法中放置了一个中断点并在调试模式下运行。

When video loads, it fills the screen as expected, but after some seconds, exactly when the mouse pointer disappears, the video resizes to its original size, not filling the screen, and without passing again over the interrupt point (onMeasure method is not called).当视频加载时,它按预期填满屏幕,但几秒钟后,恰好当鼠标指针消失时,视频将调整为原始大小,不填满屏幕,并且不会再次越过中断点(不调用 onMeasure 方法) )。

If I move the mouse again, the video fills the screen until the pointer disappears.如果我再次移动鼠标,视频会填满屏幕,直到指针消失。

I'm using Android 4.4.4.我使用的是安卓 4.4.4。

In case someone has the same problem, I'll post what I did:如果有人遇到同样的问题,我会发布我所做的:

    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
    FrameLayout fralayout = (FrameLayout) findViewById(R.id.framelayoutparent);
    FrameLayout.LayoutParams lpFraParams = (FrameLayout.LayoutParams) fralayout.getLayoutParams();
    lpFraParams.width = metrics.widthPixels-1;
    lpFraParams.height = metrics.heightPixels-1;
    fralayout.setLayoutParams(lpFraParams);

Previously I didn't substract one pixel to width and height, substracting one pixel did the trick.以前我没有用宽度和高度减去一个像素,减去一个像素就可以了。 This FrameLayout is the parent of the VideoView.此 FrameLayout 是 VideoView 的父级。

I don't understand why it had that behaviour.我不明白为什么它有这种行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM