I want to set a video that fills the screen and preserves its aspect ratio. However, I do not want the video to match the aspect ratio of the phone.
If my screen's aspect ratio is 18.9:9 and the video's aspect ratio is 16:9, then the video appears stretched when I put it in a VideoView that inherits fill_parent. If I don't set fill_parent then the video preserves its aspect ratio but only occupies less than a 1/3 of the screen because the aspect ratio is determined by its width, not its height. This is not desirable.
I want to fill the screen vertically with the video, regardless if part of the width is clipped off.
Current Code:
window.setFormat(PixelFormat.TRANSLUCENT)
val videoView = findViewById < VideoView > (videoView)
val video = Uri.parse("android.resource://" + packageName + "/" +
R.raw.bgvideo)
videoView.setVideoURI(video)
videoView.setOnPreparedListener {
mp: MediaPlayer - >
mp.setVideoScalingMode(MediaPlayer.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING)
mp.isLooping = true
mp.setScreenOnWhilePlaying(false)
}
videoView.start()
XML:
<VideoView
android:id="@+id/videoView"
android:layout_width="2000dp"
android:layout_height="match_parent" />
<!--- Sample Foreground Content !--->
<ImageView
android:layout_width="wrap_content"
android:layout_height="250dp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="24dp"
android:contentDescription="@string/logo"
android:src="@drawable/logo" />
Current Result: