I am playing local video file using MediaPlayer and SurfaceView. SurfaceView is the only control in activity, while my video files are QVGA or other. Problem is that video is getting stretched, How can i play video in its original size e.g. qvga with remaining area black.
From iteration,
When i am forcefully sets layout_height/width of Surfaceview in XML, video displayed fine.
surface_holder.setFixedSize(w,h)
has no effect, neither mp.setdisplay().
Please guide in this.
UPDATE
XML flie
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/home_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<SurfaceView
android:id="@+id/surface"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="10dip" />
</framelayout>
MediaPlayer usage is as per following link
Thanks in advance.
On your SurfaceView in XML are you using wrap_content ? This should fix your problem if not. You may need to paste a little more code for further investigation if that doesn't fix your problem.
Change your surface view width to wrap_content as well.
Setting your SurfaceView layout to wrap_content will not size a video to play at the proper aspect ratio.
wrap_content is synonymous with fill_parent for a SurfaceView.
What you want to do is get the dimensions of your video from the MediaPlayer object. You can then set the aspect ratio of the SurfaceView to match the video.
Some Basic initialization
Then the good stuff. I have omitted error checking here to reduce code, MediaPlayer calls should be wrapped in a try{}.
Note that this code makes some assumptions about the dimensions of your video. As-is, it maximizes the width and assumes that the height is not greater than the height of the screen.
You may want to fit height instead of width, also you could check the dimension calculation and ensure that it is not greater than the screen or screen - other_layout_elements.
here is the code I currently use in a project:
...
the layout I'm using (you can just ignore the progress bar)