Search code examples
androidvideocropandroid-videoview

VideoView crop to square


Using an ImageView, I can set a square height and width (say 100dip x 100dip). Then using android:scaleType="centerCrop" gives me an image which is cropped to square regardless of aspect ratio.

Can we do this with a VideoView?

I've tried just setting a square height and width, but it just re-sizes to fill the square as best as it can while maintaining the aspect ratio, which I guess is completely expected.

It doesn't seem to have any scale or crop properties / methods unlike ImageView, but this in the VideoView documentation makes me think I'm missing something:

[VideoView] ...provides various display options such as scaling and tinting.

Any ideas would be much appreciated.


Solution

  • Source implies that it isn't natively supported in the VideoView view. You could copy the source and make it work though. :) Most likely by adding an else at line 255, modifying onMeasure to prevent it from expanding to meet the size, etc.

    Edit: Don't be surprised that the Reference documentation is slightly off or just plain wrong.