简体   繁体   中英

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.

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.

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).

If I move the mouse again, the video fills the screen until the pointer disappears.

I'm using Android 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.

I don't understand why it had that behaviour.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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