0

I am having a problem. The aspect ratio of my media player becomes messed up after onResume is called

private void aspectRatio(MediaPlayer vp)
{

    Integer videoHeight;
    Integer videoWidth;
    //Obtain current video's dimensions for keeping aspect Ration the same on all devices
    videoHeight = vp.getVideoHeight();
    videoWidth = vp.getVideoWidth();

    //Get width of screen
    Integer screenWidth = getWindowManager().getDefaultDisplay().getWidth();
    Integer screenHeight = getWindowManager().getDefaultDisplay().getHeight();

    Log.i("AspectRatio VP WxH", videoHeight.toString() +" x " + videoWidth.toString());
    Log.i("AspectRatio Screen WxH", screenHeight.toString() + " x " + screenWidth.toString());
    ViewGroup.LayoutParams viewParameters = view.getLayoutParams();

    float ratioWidth = (float)screenWidth/(float)videoWidth;
    float ratioHeight = (float)screenHeight/(float)videoHeight;
    float aspectRatio = (float)videoWidth/(float)videoHeight;

    if(ratioWidth>ratioHeight)
    {
        viewParameters.width = (int)(screenHeight * aspectRatio);
        viewParameters.height= screenHeight;
    }
    else if(ratioWidth < ratioHeight)
    {
        viewParameters.width = screenWidth;
        viewParameters.height = (int) (screenHeight / aspectRatio);
    }

    Integer x = viewParameters.width;
    Integer y = viewParameters.height;
    Log.i("Screen", x.toString() + " " + y.toString());
    view.setLayoutParams(viewParameters);
}

that was the function that gets the aspect ratio and puts it to my surfaceView. The problem is that after onResume() its width is much smaller than it is supposed to be. Can yuou see what is wrong?

Raigex
  • 1,205
  • 12
  • 32

1 Answers1

0

The aspect ratio got messed up because when surface changed it was created again. Now I changed it so that the aspect ratio gets set in onSurfaceChanged also. It currently works without problems.

Raigex
  • 1,205
  • 12
  • 32