fix(android): ensure maxbitrate & selectedVideoTrack interact correctly (#4155)

This commit is contained in:
Olivier Bouillet 2024-09-17 15:57:26 +02:00 committed by GitHub
parent 1ef2b3a977
commit 7f6b500c82
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 6 deletions

View File

@ -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));
}

View File

@ -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