6

In my program im trying to have video in full screen but without break aspect ratio of the playing video ,

in android default player it has button in upper left corner when you press it it shift video to full view without distortion of video which maintain aspect ratio:

as image below :

enter image description here

im try to get full screen video with the following code :

 <?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent" 
       android:layout_height="fill_parent" > 
     <VideoView android:id="@+id/myvideoview" 
         android:layout_width="fill_parent" 
         android:layout_alignParentRight="true"
          android:layout_alignParentLeft="true" 
         android:layout_alignParentTop="true"
          android:layout_alignParentBottom="true" 
         android:layout_height="fill_parent"> 
      </VideoView> 
   </RelativeLayout> 

This above code lead to full screen video BUT without maintain Aspest Ratio

please can any body advice me in how to get full screen video Without Break Aspect Ratio .

My videos stored in raw folder of App resource folder .

please supply full working code .

I searched alot here and in google but i cant find my target ,

another post found here in stackoverflow with the same question but with no correct answer in this link :

Full screen videoview without stretching the video .

im using videoview to display my videos in my App as follow:

  public class Video extends Activity {   
    private VideoView videoview;    
      @Override  
         public void onCreate(Bundle icicle) {  
              super.onCreate(icicle);      
               setContentView(R.layout.main);   
   videoview = (VideoView) findViewById(R.id.count_videoview);  
   videoview.setVideoURI(Uri.parse("android.resource://" + getPackageName()
          +"/"+R.raw.first_video));    
   videoview.setMediaController(new MediaController(this));    
   videoview.requestFocus();    
   videoview.start();   
                 }
          } 

Thanks in advance .

Community
  • 1
  • 1
androidqq6
  • 1,526
  • 2
  • 22
  • 47
  • Add link to [similar question](http://stackoverflow.com/questions/12211837/full-screen-videoview-without-stretching-the-video#comment16405010_12211837), Note that the rewarded answer in that link doesn't work. – yorkw Sep 30 '12 at 20:06
  • @yorkw link added and post updated , please take alook , thanks – androidqq6 Sep 30 '12 at 23:27
  • Check the answer from here: http://stackoverflow.com/questions/8240051/android-mediaplayer-video-aspect-ratio-issue – execomrt Aug 16 '13 at 18:33
  • try this http://stackoverflow.com/a/38971707/1153703 – Bikesh M Aug 16 '16 at 09:53

1 Answers1

0

Get the height and width of the original video.
Get the height and width of the screen(in current orientation).

float ratioWidth = screenWidth / videoWidth;
float ratioHeight = screenHeight / videoHeight;
float fullWidth;
float fullHeight;
if (ratioWidth < ratioHeight ) {  
    fullWidth = videoWidth * ratioWidth;
    fullHeight = videoHeight * ratioWidth;
} else {
    fullWidth = videoWidth * ratioHeight;
    fullHeight = videoHeight * ratioHeight;
}

Set fullWidth and fullHeight to the VideoView.

Ron
  • 24,175
  • 8
  • 56
  • 97
  • please provide full working code , im using videoview class to display video on my app ,im not expert in android , thanks – androidqq6 Sep 30 '12 at 23:11