fix(android): track selection parameter has change in last release. (#3594)

Move all setSelectedTrack to String instead of Dynamic

Co-authored-by: Olivier Bouillet <olivier@OrdinateOlivier.lan>
This commit is contained in:
Olivier Bouillet 2024-03-22 07:58:09 +01:00 committed by GitHub
parent 3d7444ab25
commit d5c8b514a1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 29 additions and 25 deletions

View File

@ -206,11 +206,11 @@ public class ReactExoplayerView extends FrameLayout implements
private String extension;
private boolean repeat;
private String audioTrackType;
private Dynamic audioTrackValue;
private String audioTrackValue;
private String videoTrackType;
private Dynamic videoTrackValue;
private String videoTrackValue;
private String textTrackType;
private Dynamic textTrackValue;
private String textTrackValue;
private ReadableArray textTracks;
private boolean disableFocus;
private boolean focusable = true;
@ -1635,7 +1635,7 @@ public class ReactExoplayerView extends FrameLayout implements
trackSelector.setParameters(disableParameters);
}
public void setSelectedTrack(int trackType, String type, Dynamic value) {
public void setSelectedTrack(int trackType, String type, String value) {
if (player == null) return;
int rendererIndex = getTrackRendererIndex(trackType);
if (rendererIndex == C.INDEX_UNSET) {
@ -1661,7 +1661,7 @@ public class ReactExoplayerView extends FrameLayout implements
} else if (type.equals("language")) {
for (int i = 0; i < groups.length; ++i) {
Format format = groups.get(i).getFormat(0);
if (format.language != null && format.language.equals(value.asString())) {
if (format.language != null && format.language.equals(value)) {
groupIndex = i;
break;
}
@ -1669,17 +1669,18 @@ public class ReactExoplayerView extends FrameLayout implements
} else if (type.equals("title")) {
for (int i = 0; i < groups.length; ++i) {
Format format = groups.get(i).getFormat(0);
if (format.id != null && format.id.equals(value.asString())) {
if (format.id != null && format.id.equals(value)) {
groupIndex = i;
break;
}
}
} else if (type.equals("index")) {
if (value.asInt() < groups.length) {
groupIndex = value.asInt();
int iValue = Integer.parseInt(value);
if (iValue < groups.length) {
groupIndex = iValue;
}
} else if (type.equals("resolution")) {
int height = value.asInt();
int height = Integer.parseInt(value);
for (int i = 0; i < groups.length; ++i) { // Search for the exact height
TrackGroup group = groups.get(i);
Format closestFormat = null;
@ -1827,19 +1828,19 @@ public class ReactExoplayerView extends FrameLayout implements
return groupIndex;
}
public void setSelectedVideoTrack(String type, Dynamic value) {
public void setSelectedVideoTrack(String type, String value) {
videoTrackType = type;
videoTrackValue = value;
setSelectedTrack(C.TRACK_TYPE_VIDEO, videoTrackType, videoTrackValue);
}
public void setSelectedAudioTrack(String type, Dynamic value) {
public void setSelectedAudioTrack(String type, String value) {
audioTrackType = type;
audioTrackValue = value;
setSelectedTrack(C.TRACK_TYPE_AUDIO, audioTrackType, audioTrackValue);
}
public void setSelectedTextTrack(String type, Dynamic value) {
public void setSelectedTextTrack(String type, String value) {
textTrackType = type;
textTrackValue = value;
setSelectedTrack(C.TRACK_TYPE_TEXT, textTrackType, textTrackValue);

View File

@ -253,10 +253,10 @@ public class ReactExoplayerViewManager extends ViewGroupManager<ReactExoplayerVi
public void setSelectedVideoTrack(final ReactExoplayerView videoView,
@Nullable ReadableMap selectedVideoTrack) {
String typeString = null;
Dynamic value = null;
String value = null;
if (selectedVideoTrack != null) {
typeString = ReactBridgeUtils.safeGetString(selectedVideoTrack, PROP_SELECTED_VIDEO_TRACK_TYPE);
value = ReactBridgeUtils.safeGetDynamic(selectedVideoTrack, PROP_SELECTED_VIDEO_TRACK_VALUE);
value = ReactBridgeUtils.safeGetString(selectedVideoTrack, PROP_SELECTED_VIDEO_TRACK_VALUE);
}
videoView.setSelectedVideoTrack(typeString, value);
}
@ -265,10 +265,10 @@ public class ReactExoplayerViewManager extends ViewGroupManager<ReactExoplayerVi
public void setSelectedAudioTrack(final ReactExoplayerView videoView,
@Nullable ReadableMap selectedAudioTrack) {
String typeString = null;
Dynamic value = null;
String value = null;
if (selectedAudioTrack != null) {
typeString = ReactBridgeUtils.safeGetString(selectedAudioTrack, PROP_SELECTED_AUDIO_TRACK_TYPE);
value = ReactBridgeUtils.safeGetDynamic(selectedAudioTrack, PROP_SELECTED_AUDIO_TRACK_VALUE);
value = ReactBridgeUtils.safeGetString(selectedAudioTrack, PROP_SELECTED_AUDIO_TRACK_VALUE);
}
videoView.setSelectedAudioTrack(typeString, value);
}
@ -277,10 +277,10 @@ public class ReactExoplayerViewManager extends ViewGroupManager<ReactExoplayerVi
public void setSelectedTextTrack(final ReactExoplayerView videoView,
@Nullable ReadableMap selectedTextTrack) {
String typeString = null;
Dynamic value = null;
String value = null;
if (selectedTextTrack != null) {
typeString = ReactBridgeUtils.safeGetString(selectedTextTrack, PROP_SELECTED_TEXT_TRACK_TYPE);
value = ReactBridgeUtils.safeGetDynamic(selectedTextTrack, PROP_SELECTED_TEXT_TRACK_VALUE);
value = ReactBridgeUtils.safeGetString(selectedTextTrack, PROP_SELECTED_TEXT_TRACK_VALUE);
}
videoView.setSelectedTextTrack(typeString, value);
}

View File

@ -225,16 +225,18 @@ class VideoPlayer extends Component {
const selectedTrack = data.audioTracks?.find((x: AudioTrack) => {
return x.selected;
});
this.setState({
audioTracks: data.audioTracks,
});
if (selectedTrack?.language) {
this.setState({
audioTracks: data.audioTracks,
selectedAudioTrack: {
type: 'language',
value: selectedTrack?.language,
},
});
} else {
this.setState({
audioTracks: data.audioTracks,
});
}
};
@ -243,17 +245,18 @@ class VideoPlayer extends Component {
return x?.selected;
});
this.setState({
textTracks: data.textTracks,
});
if (selectedTrack?.language) {
this.setState({
textTracks: data,
textTracks: data.textTracks,
selectedTextTrack: {
type: 'language',
value: selectedTrack?.language,
},
});
} else {
this.setState({
textTracks: data.textTracks,
});
}
};