From 7f6b500c82122325c326b6dcacaf7af8039b2b33 Mon Sep 17 00:00:00 2001 From: Olivier Bouillet <62574056+freeboub@users.noreply.github.com> Date: Tue, 17 Sep 2024 15:57:26 +0200 Subject: [PATCH] fix(android): ensure maxbitrate & selectedVideoTrack interact correctly (#4155) --- .../exoplayer/ReactExoplayerView.java | 23 ++++++++++++++----- docs/pages/component/props.mdx | 3 +++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java b/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java index 499e729b..0714115e 100644 --- a/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -565,6 +565,11 @@ public class ReactExoplayerView extends FrameLayout implements reLayout(playerControlView); } + /// returns true is adaptive bitrate shall be used + public boolean isUsingVideoABR() { + return videoTrackType == null || "auto".equals(videoTrackType); + } + public void setDebug(boolean enableDebug) { this.enableDebug = enableDebug; refreshDebugState(); @@ -2041,16 +2046,21 @@ public class ReactExoplayerView extends FrameLayout implements TrackSelectionOverride selectionOverride = new TrackSelectionOverride(groups.get(groupIndex), tracks); - DefaultTrackSelector.Parameters selectionParameters = trackSelector.getParameters() + DefaultTrackSelector.Parameters.Builder selectionParameters = trackSelector.getParameters() .buildUpon() .setExceedAudioConstraintsIfNecessary(true) .setExceedRendererCapabilitiesIfNecessary(true) .setExceedVideoConstraintsIfNecessary(true) .setRendererDisabled(rendererIndex, false) - .clearOverridesOfType(selectionOverride.getType()) - .addOverride(selectionOverride) - .build(); - trackSelector.setParameters(selectionParameters); + .clearOverridesOfType(selectionOverride.getType()); + + if (trackType == C.TRACK_TYPE_VIDEO && isUsingVideoABR()) { + selectionParameters.setMaxVideoBitrate(maxBitRate == 0 ? Integer.MAX_VALUE : maxBitRate); + } else { + selectionParameters.addOverride(selectionOverride); + } + + trackSelector.setParameters(selectionParameters.build()); } private boolean isFormatSupported(Format format) { @@ -2181,7 +2191,8 @@ public class ReactExoplayerView extends FrameLayout implements public void setMaxBitRateModifier(int newMaxBitRate) { maxBitRate = newMaxBitRate; - if (player != null) { + if (player != null && isUsingVideoABR()) { + // do not apply yet if not auto trackSelector.setParameters(trackSelector.buildUponParameters() .setMaxVideoBitrate(maxBitRate == 0 ? Integer.MAX_VALUE : maxBitRate)); } diff --git a/docs/pages/component/props.mdx b/docs/pages/component/props.mdx index e3069d17..184f7c60 100644 --- a/docs/pages/component/props.mdx +++ b/docs/pages/component/props.mdx @@ -361,6 +361,9 @@ Sets the desired limit, in bits per second, of network bandwidth consumption whe Default: 0. Don't limit the maxBitRate. +Note: This property can interact with selectedVideoTrack. +To use `maxBitrate`, selectedVideoTrack shall be undefined or `{type: SelectedVideoTrackType.AUTO}`. + Example: ```javascript