From dbf1a4e034ee3d005fc3dc35f70fb7abadfcf14f Mon Sep 17 00:00:00 2001 From: Jeferson Daniel Date: Tue, 30 Jun 2020 14:00:16 -0300 Subject: [PATCH] Fix exoplayer aspect ratio update on source changes (#2053) * Fix exoplayer aspect ratio update on source changes * Update CHANGELOG.md --- CHANGELOG.md | 1 + .../com/brentvatne/exoplayer/AspectRatioFrameLayout.java | 4 ++++ .../main/java/com/brentvatne/exoplayer/ExoPlayerView.java | 5 +++++ .../java/com/brentvatne/exoplayer/ReactExoplayerView.java | 2 ++ 4 files changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5fefee0f..45f586a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - Added preventsDisplaySleepDuringVideoPlayback (#2019) - Reverted the JS fullscreening for Android. [#2013](https://github.com/react-native-community/react-native-video/pull/2013) - Set iOS request headers without needing to edit RCTVideo.m. [#2014](https://github.com/react-native-community/react-native-video/pull/2014) +- Fix exoplayer aspect ratio update on source changes [#2053](https://github.com/react-native-community/react-native-video/pull/2053) ### Version 5.1.0-alpha5 diff --git a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/AspectRatioFrameLayout.java b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/AspectRatioFrameLayout.java index 5079451b..ea2cd4dd 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/AspectRatioFrameLayout.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/AspectRatioFrameLayout.java @@ -67,6 +67,10 @@ public final class AspectRatioFrameLayout extends FrameLayout { return videoAspectRatio; } + public void invalidateAspectRatio() { + videoAspectRatio = 0; + } + /** * Sets the resize mode which can be of value {@link ResizeMode.Mode} * diff --git a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ExoPlayerView.java b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ExoPlayerView.java index 2b43b45e..afa5106c 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ExoPlayerView.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ExoPlayerView.java @@ -200,6 +200,11 @@ public final class ExoPlayerView extends FrameLayout { shutterView.setVisibility(VISIBLE); } + public void invalidateAspectRatio() { + // Resetting aspect ratio will force layout refresh on next video size changed + layout.invalidateAspectRatio(); + } + private final class ComponentListener implements SimpleExoPlayer.VideoListener, TextOutput, ExoPlayer.EventListener { diff --git a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java index 5df1f3bb..4e6fea58 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -410,6 +410,8 @@ class ReactExoplayerView extends FrameLayout implements player.setPlaybackParameters(params); } if (playerNeedsSource && srcUri != null) { + exoPlayerView.invalidateAspectRatio(); + ArrayList mediaSourceList = buildTextSources(); MediaSource videoSource = buildMediaSource(srcUri, extension); MediaSource mediaSource;