Skip to main content
Version: 11.8.0

How to change how a video should fit inside a container on Android

You may want to alter how a video is sized inside the player's frame. By default, a video player respects the aspect ratio of the video. This means that black bars can appear on the sides of the player, or above and below the video, when its aspect ratio differs from the player's aspect ratio.

Instead, you may want the video to cover the entire player. Note that this either

  • cuts off the content that falls outside of the player, or
  • deforms the content, so it no longer matches its original aspect ratio.

Implementation

Use Player.setAspectRatio to change how the video is fitted inside the player, using one of the AspectRatio values:

  • FIT: fit the video inside the player, preserving its aspect ratio. This is the default.
  • FILL: fill the player with the video, deforming the video if needed.
  • ASPECT_FILL: fill the player with the video, preserving its aspect ratio and cropping the video if needed.

The snippet below demonstrates how you could use this API:

theoPlayerView.player.aspectRatio = AspectRatio.ASPECT_FILL