没有中断宽高比的全屏视频

and*_*qq6 6 android fullscreen android-video-player android-videoview

在我的程序中我试图在全屏播放视频但没有播放视频的宽高比,

在Android默认播放器中,当你按下它时它左上角有一个按钮,它将视频转换为全视图,而不会保留宽高比的视频失真:

如下图所示:

在此输入图像描述

我尝试使用以下代码获取全屏视频:

 <?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> 
Run Code Online (Sandbox Code Playgroud)

上面的代码导致全屏视频不保持Aspest Ratio

请任何机构建议我如何获得全屏视频没有中断宽高比.

我的视频存储在App资源文件夹的原始文件夹中.

请提供完整的工作代码.

我在这里和谷歌搜索了很多,但我找不到我的目标,

另一篇文章在stackoverflow中找到了相同的问题但在此链接中没有正确的答案:

全屏视频视图,无需拉伸视频.

我使用videoview在我的应用程序中显示我的视频如下:

  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();   
                 }
          } 
Run Code Online (Sandbox Code Playgroud)

提前致谢 .

Ron*_*nie 0

获取原始视频的高度和宽度。
获取屏幕的高度和宽度(在当前方向)。

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;
}
Run Code Online (Sandbox Code Playgroud)

设置fullWidthfullHeightVideoView