Full Screen Video Without Break Aspect Ratio
Asked Answered
L

1

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 .

Lacuna answered 11/9, 2012 at 17:43 Comment(4)
Add link to similar question, Note that the rewarded answer in that link doesn't work.Cutting
@Cutting link added and post updated , please take alook , thanksLacuna
Check the answer from here: #8240551Fourwheeler
try this https://mcmap.net/q/331820/-videoview-to-match-parent-height-and-keep-aspect-ratioBiracial
N
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.

Nester answered 30/9, 2012 at 18:9 Comment(1)
please provide full working code , im using videoview class to display video on my app ,im not expert in android , thanksLacuna

© 2022 - 2024 — McMap. All rights reserved.