The following script works flawless, but the size of my videoplayer will get f\'d after changing my surfaceview from portrait to landscape. Tried several options like
Same problem here:
I believe the problem is the Vitamio library as I have experienced a similar problem when dealing with the Vitamio SDK. Resizing didn't work for me, when using a SurfaceView
and invoking setLayoutParams(ViewGroup.LayoutParams params)
. The below code works fine using the standard Android media-framework, but importing the vitamio packages breaks it.
RelativeLayout.LayoutParams video_VIEWLAYOUT = (RelativeLayout.LayoutParams) videoView.getLayoutParams(); video_VIEWLAYOUT.width = screenWidth; video_VIEWLAYOUT.height = (int) (((float)videoHeight / (float)videoWidth) *(float)screenWidth); videoView.setLayoutParams(video_VIEWLAYOUT);
My recommendation would be to try using the io.vov.vitamio.widget.VideoView
instead of a android.view.SurfaceView
.
use this method and call it inside onConfigurationChanged method :
private void setVideoSize() {
// // Get the dimensions of the video
// mVideoView is your video view object.
int videoWidth = mVideoView.getVideoWidth();
int videoHeight = mVideoView.getVideoHeight();
float videoProportion = (float) videoWidth / (float) videoHeight;
// Get the width of the screen
int screenWidth = getWindowManager().getDefaultDisplay().getWidth();
int screenHeight = getWindowManager().getDefaultDisplay().getHeight();
float screenProportion = (float) screenWidth / (float) screenHeight;
// Get the SurfaceView layout parameters
android.view.ViewGroup.LayoutParams lp = mVideoView.getLayoutParams();
if (videoProportion > screenProportion) {
lp.width = screenWidth;
lp.height = (int) ((float) screenWidth / videoProportion);
} else {
lp.width = (int) (videoProportion * (float) screenHeight);
lp.height = screenHeight;
}
// Commit the layout parameters
mVideoView.setLayoutParams(lp);
}
Now on change of orientation your videoview will be resized.