Skip to content

Commit

Permalink
Fix(android): avoid video resizing flickering (#3751)
Browse files Browse the repository at this point in the history
* perf: ensure we do not provide callback to native if no callback provided from app

* chore: rework bufferConfig to make it more generic and reduce ReactExoplayerView code size

* chore: improve issue template

* fix(android): avoid video view flickering at playback startup
  • Loading branch information
freeboub authored May 13, 2024
1 parent 2e623ca commit 9716f4c
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions android/src/main/java/com/brentvatne/exoplayer/ExoPlayerView.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@
import androidx.core.content.ContextCompat;
import androidx.media3.common.AdViewProvider;
import androidx.media3.common.C;
import androidx.media3.common.PlaybackException;
import androidx.media3.common.PlaybackParameters;
import androidx.media3.common.Format;
import androidx.media3.common.Player;
import androidx.media3.common.Timeline;
import androidx.media3.common.Tracks;
import androidx.media3.common.VideoSize;
import androidx.media3.common.text.Cue;
import androidx.media3.common.util.Assertions;
import androidx.media3.exoplayer.ExoPlayer;
import androidx.media3.exoplayer.trackselection.TrackSelectionArray;
import androidx.media3.ui.SubtitleView;

import android.util.AttributeSet;
Expand All @@ -27,6 +24,7 @@

import com.brentvatne.common.api.ResizeMode;
import com.brentvatne.common.api.SubtitleStyle;
import com.google.common.collect.ImmutableList;

import java.util.List;

Expand Down Expand Up @@ -247,19 +245,22 @@ public void setHideShutterView(boolean hideShutterView) {
layout(getLeft(), getTop(), getRight(), getBottom());
};

private void updateForCurrentTrackSelections() {
if (player == null) {
private void updateForCurrentTrackSelections(Tracks tracks) {
if (tracks == null) {
return;
}
TrackSelectionArray selections = player.getCurrentTrackSelections();
for (int i = 0; i < selections.length; i++) {
if (player.getRendererType(i) == C.TRACK_TYPE_VIDEO && selections.get(i) != null) {
// Video enabled so artwork must be hidden. If the shutter is closed, it will be opened in
// onRenderedFirstFrame().
ImmutableList<Tracks.Group> groups = tracks.getGroups();
for (Tracks.Group group: groups) {
if (group.getType() == C.TRACK_TYPE_VIDEO && group.length > 0) {
// get the first track of the group to identify aspect ratio
Format format = group.getTrackFormat(0);

// update aspect ratio !
layout.setAspectRatio(format.height == 0 ? 1 : (format.width * format.pixelWidthHeightRatio) / format.height);
return;
}
}
// Video disabled so the shutter must be closed.
// no video tracks, in that case refresh shutterView visibility
shutterView.setVisibility(this.hideShutterView ? View.INVISIBLE : View.VISIBLE);
}

Expand Down Expand Up @@ -293,8 +294,7 @@ public void onRenderedFirstFrame() {

@Override
public void onTracksChanged(Tracks tracks) {
updateForCurrentTrackSelections();
updateForCurrentTrackSelections(tracks);
}
}

}

0 comments on commit 9716f4c

Please sign in to comment.