Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9125167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:44:25+00:00 2026-06-17T06:44:25+00:00

I have written a sample app that reproduces the problem: https://github.com/blundell/VideoRatioProblemPerDevice The VideoView documentation

  • 0

I have written a sample app that reproduces the problem:

https://github.com/blundell/VideoRatioProblemPerDevice

The VideoView documentation states:

Displays a video file. … takes care of computing its measurement from the video so that it can be used in any layout manager, and provides various display options such as scaling

The problem is the Samsung Galaxy S3 is doing weird things to the video and not respecting the ratio of the video. (also happening on an HTC device).

Activity with full screen fragment:

What I have found is when the video is played on the Samsung Galaxy S3 it will play in an incorrect ratio. It looks like it has been stretched to the height of the view without any regard for the ratio of the original video.

here:
s3

However if I play the video on a Samsung Galaxy Nexus the video is in the correct ratio.

here:
n

If I force the video to take up the full size of the fragment it looks ok on the S3 (because the ratio of the screen is the ratio of the video). However I don’t want to do this as it screws up the fragment being used in other places i.e. tablets.

The code is:

An Activity with a Fragment with a VideoView. It can be seen here: GITHUB CODE LINK

if you want some code here is hte VideoPlayerFragment:

public class VideoPlayerFragment extends Fragment {

    private static final String TAG = "VideoPlayer";

    private FitVideoView videoView;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View root = inflater.inflate(R.layout.fragment_video_player, container, false);

        videoView = (FitVideoView) root.findViewById(R.id.surface);

        return root;
    }

    public void playVideo() {
        Uri uri = Uri.parse("android.resource://" + getActivity().getPackageName() + "/" + R.raw.test_vid);
        Log.d(TAG, "Uri is: " + uri);
        setVideoLocation(uri);
        if (!videoView.isPlaying()) {
            videoView.start();
        }
    }

    private void setVideoLocation(Uri uri) {
        try {
            videoView.setVideoURI(uri);
        } catch (Exception e) {
            Log.e(TAG, "VideoPlayer uri was invalid", e);
            Toast.makeText(getActivity(), "Not found", Toast.LENGTH_SHORT).show();
        }
    }

    public void pauseVideo() {
        if (videoView.isPlaying()) {
            videoView.pause();
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:44:26+00:00Added an answer on June 17, 2026 at 6:44 am

    So this issue occurs with VideoView and with MediaPlayer + SurfaceView.

    When the system asks the video for it’s width x height it is returning 640×480 when it should be returning 852×480.

    i.e.

    @Override
    public void onPrepared(MediaPlayer mp) {
        mp.getVideoWidth();
        mp.getVideoHeight();
    }
    

    This is either a bug in the MediaPlayer handling of the video container/codec or an issue with the video file itself.

    GSpot Details

    Either way I have circumvented it by adding what I know the video’s width and height is to my code. I have updated the Git Repo with this fix. hack alert

    Here’s a link to the question where I found out the different size details of my video.

    You can apply this fix to the VideoView or directly to MediaPlayer + SurfaceView your choice. Here’s the VideoView answer:

    public class FitVideoView extends VideoView {
    
        private final int mVideoWidth = 853;
        private final int mVideoHeight = 480;
        private boolean applyFix = true;
    
        public FitVideoView(Context context) {
            super(context);
        }
    
        public FitVideoView(Context context, AttributeSet attrs) {
            this(context, attrs, 0);
        }
    
        public FitVideoView(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
        }
    
        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            if (applyFix) { // A Toggle so I can see both results
                // This doesn't ask the video for it's size, but uses my hardcoded size
                applyFix(widthMeasureSpec, heightMeasureSpec);
            } else {
                // This asks the video for its size (which gives an incorrect WxH) then does the same code as below
                super.onMeasure(widthMeasureSpec, heightMeasureSpec);
            }
        }
    
        private void applyFix(int widthMeasureSpec, int heightMeasureSpec) {
            int width = getDefaultSize(mVideoWidth, widthMeasureSpec);
            int height = getDefaultSize(mVideoHeight, heightMeasureSpec);
            if (mVideoWidth > 0 && mVideoHeight > 0) {
                if (mVideoWidth * height > width * mVideoHeight) {
                    Log.d("TAG", "image too tall, correcting");
                    height = width * mVideoHeight / mVideoWidth;
                } else if (mVideoWidth * height < width * mVideoHeight) {
                    Log.d("TAG", "image too wide, correcting");
                    width = height * mVideoWidth / mVideoHeight;
                } else {
                    Log.d("TAG", "aspect ratio is correct: " + width + "/" + height + "=" + mVideoWidth + "/" + mVideoHeight);
                }
            }
            Log.d("TAG", "setting size: " + width + 'x' + height);
            setMeasuredDimension(width, height);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a sample app written in Play and Scala talking to Amazon DynamoDB
Below I have written a sample program that I have written to learn about
I am new to ExtJS and have written a sample App using Ext.application with
I have a written C++ server app that I would like to be able
i have some WinForms app (Framework to develop some simple apps), written in C#.
i have some WinForms app (Framework to develop some simple apps), written in C#.
I have written some sample program and DLL to learn the concept of DLL
I have written a sample application to write to a public and private queues
I have written grammar for a language (sample code below) //this is a procedure
I have an HTML page (written in .NET MVC) that allows a user to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.