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

时间:2012-09-11 17:43:02

标签: android fullscreen android-videoview android-video-player

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

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

如下图所示:

enter image description here

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

 <?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> 

以上代码导致全屏视频 BUT ,无需维持Aspest比率

请任何机构可以告诉我如何获得没有断开宽高比的全屏视频。

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

请提供完整的工作代码

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

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

Full screen videoview without stretching the video

我正在使用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();   
                 }
          } 

提前致谢。

1 个答案:

答案 0 :(得分: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;
}

fullWidthfullHeight设置为VideoView

相关问题