gpt4 book ai didi

android - 全屏视频无中断纵横比

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:45:10 26 4
gpt4 key购买 nike

在我的程序中,我试图全屏播放视频,但不破坏播放视频的纵横比,

在 android 默认播放器中,它在左上角有一个按钮,当您按下它时,它会将视频切换到全 View 而不会失真,保持纵横比:

如下图:

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>

上面的代码导致全屏视频但是没有保持Aspest Ratio

请任何人建议我如何在不中断纵横比的情况下获得全屏视频。

我的视频存放在App资源文件夹的raw文件夹中。

请提供完整的工作代码

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

在 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();
}
}

提前致谢。

最佳答案

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

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

关于android - 全屏视频无中断纵横比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12375102/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com