Fix(android): avoid video resizing flickering (#3751)
* 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
This commit is contained in:
parent
2e623ca0fb
commit
9716f4cb36
@ -4,16 +4,13 @@ import android.content.Context;
|
|||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.media3.common.AdViewProvider;
|
import androidx.media3.common.AdViewProvider;
|
||||||
import androidx.media3.common.C;
|
import androidx.media3.common.C;
|
||||||
import androidx.media3.common.PlaybackException;
|
import androidx.media3.common.Format;
|
||||||
import androidx.media3.common.PlaybackParameters;
|
|
||||||
import androidx.media3.common.Player;
|
import androidx.media3.common.Player;
|
||||||
import androidx.media3.common.Timeline;
|
|
||||||
import androidx.media3.common.Tracks;
|
import androidx.media3.common.Tracks;
|
||||||
import androidx.media3.common.VideoSize;
|
import androidx.media3.common.VideoSize;
|
||||||
import androidx.media3.common.text.Cue;
|
import androidx.media3.common.text.Cue;
|
||||||
import androidx.media3.common.util.Assertions;
|
import androidx.media3.common.util.Assertions;
|
||||||
import androidx.media3.exoplayer.ExoPlayer;
|
import androidx.media3.exoplayer.ExoPlayer;
|
||||||
import androidx.media3.exoplayer.trackselection.TrackSelectionArray;
|
|
||||||
import androidx.media3.ui.SubtitleView;
|
import androidx.media3.ui.SubtitleView;
|
||||||
|
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
@ -27,6 +24,7 @@ import android.widget.FrameLayout;
|
|||||||
|
|
||||||
import com.brentvatne.common.api.ResizeMode;
|
import com.brentvatne.common.api.ResizeMode;
|
||||||
import com.brentvatne.common.api.SubtitleStyle;
|
import com.brentvatne.common.api.SubtitleStyle;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -247,19 +245,22 @@ public final class ExoPlayerView extends FrameLayout implements AdViewProvider {
|
|||||||
layout(getLeft(), getTop(), getRight(), getBottom());
|
layout(getLeft(), getTop(), getRight(), getBottom());
|
||||||
};
|
};
|
||||||
|
|
||||||
private void updateForCurrentTrackSelections() {
|
private void updateForCurrentTrackSelections(Tracks tracks) {
|
||||||
if (player == null) {
|
if (tracks == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
TrackSelectionArray selections = player.getCurrentTrackSelections();
|
ImmutableList<Tracks.Group> groups = tracks.getGroups();
|
||||||
for (int i = 0; i < selections.length; i++) {
|
for (Tracks.Group group: groups) {
|
||||||
if (player.getRendererType(i) == C.TRACK_TYPE_VIDEO && selections.get(i) != null) {
|
if (group.getType() == C.TRACK_TYPE_VIDEO && group.length > 0) {
|
||||||
// Video enabled so artwork must be hidden. If the shutter is closed, it will be opened in
|
// get the first track of the group to identify aspect ratio
|
||||||
// onRenderedFirstFrame().
|
Format format = group.getTrackFormat(0);
|
||||||
|
|
||||||
|
// update aspect ratio !
|
||||||
|
layout.setAspectRatio(format.height == 0 ? 1 : (format.width * format.pixelWidthHeightRatio) / format.height);
|
||||||
return;
|
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);
|
shutterView.setVisibility(this.hideShutterView ? View.INVISIBLE : View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -293,8 +294,7 @@ public final class ExoPlayerView extends FrameLayout implements AdViewProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTracksChanged(Tracks tracks) {
|
public void onTracksChanged(Tracks tracks) {
|
||||||
updateForCurrentTrackSelections();
|
updateForCurrentTrackSelections(tracks);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user