I created a widget that is an extension of SurfaceView (very similar to VideoView ), and I'm working on stretching the video all the way to the deviceβs screen when performing certain actions. I looked at the onMeasure VideoView function and rewrote it as follows:
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { if (mStretchVideo) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); } else { int width = getDefaultSize(mVideoWidth, widthMeasureSpec); int height = getDefaultSize(mVideoHeight, heightMeasureSpec); if (mVideoWidth > 0 && mVideoHeight > 0) { if (mVideoWidth * height > width * mVideoHeight) { height = width * mVideoHeight / mVideoWidth; } else if (mVideoWidth * height < width * mVideoHeight) { width = height * mVideoWidth / mVideoHeight; } } setMeasuredDimension(width, height); } }
It seems like it's okay if I stop the video completely and start playing again. Now I am trying to force update this SurfaceView after setting the stretch frame so that the video is stretched while it is playing, but I could not figure out how to force the update on the SurfaceView . I tried android.view.View.invalidate() , android.view.View.refreshDrawableState() and called android.view.View.measure(int, int) directly with various combinations, but did not succeed. Any ideas?
source share