Skip to content

video_player_android-v2.12.2

@voledyaev voledyaev tagged this 02 Sep 18:19
`VideoSize.pixelWidthHeightRatio` was never read, so videos stored with non-square pixels (anamorphic content) reported their **coded** size instead of their **display** size. `VideoPlayerValue.size` therefore carried the wrong aspect ratio and such videos rendered stretched.

Example of a real affected file: coded `1080x720` with a `3:8` pixel aspect ratio displays as `405x720`, but `size` was reported as `1080x720` — a 2.67x horizontal stretch.

This scales the reported width by the pixel aspect ratio, which is what media3's own [`PlayerView`](https://github.com/androidx/media/blob/release/libraries/ui/src/main/java/androidx/media3/ui/PlayerView.java) does:

```java
float videoAspectRatio = (height == 0 || width == 0) ? 0 : (width * videoSize.pixelWidthHeightRatio) / height;
```

Both event listeners are updated:

- **Texture path** — ExoPlayer reports a `pixelWidthHeightRatio` that already accounts for any applied rotation (`MediaCodecVideoRenderer` inverts it for 90°/270°), so the ratio is applied to the reported width regardless of the rotation correction.
- **Platform view path** — `Format.pixelWidthHeightRatio` describes the unrotated frame, so the ratio is applied *before* the existing width/height swap.

The scaling is skipped unless the ratio is greater than 0 and not 1, so playback of ordinary square-pixel video is byte-for-byte unchanged.

Verified on a physical anamorphic sample (`1080x720`, SAR `3:8`) on Android 15: previously stretched, now rendered at the correct 9:16 display aspect. iOS is unaffected — `video_player_avfoundation` already reports `presentationSize`, which is pixel-aspect corrected, which is why this bug is Android-only.

*(No before/after screenshots: the sample videos available to me are private medical content and cannot be published.)*

Fixes https://github.com/flutter/flutter/issues/132934
Fixes https://github.com/flutter/flutter/issues/94234

## Pre-Review Checklist

[^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
Assets 2
Loading