Skip to content

Commit

Permalink
fix(android): track selection parameter has change in last release. (T…
Browse files Browse the repository at this point in the history
…heWidlarzGroup#3594)

Move all setSelectedTrack to String instead of Dynamic

Co-authored-by: Olivier Bouillet <[email protected]>
  • Loading branch information
freeboub and Olivier Bouillet authored Mar 22, 2024
1 parent 3d7444a commit d5c8b51
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1635,7 +1635,7 @@ public void disableTrack(int rendererIndex) {
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) {
Expand All @@ -1661,25 +1661,26 @@ public void setSelectedTrack(int trackType, String type, Dynamic value) {
} 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;
}
}
} 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;
Expand Down Expand Up @@ -1827,19 +1828,19 @@ private int getGroupIndexForDefaultLocale(TrackGroupArray groups) {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,10 @@ public void setPreventsDisplaySleepDuringVideoPlayback(final ReactExoplayerView
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);
}
Expand All @@ -265,10 +265,10 @@ public void setSelectedVideoTrack(final ReactExoplayerView videoView,
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);
}
Expand All @@ -277,10 +277,10 @@ public void setSelectedAudioTrack(final ReactExoplayerView videoView,
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);
}
Expand Down
17 changes: 10 additions & 7 deletions examples/basic/src/VideoPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
};

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

Expand Down

0 comments on commit d5c8b51

Please sign in to comment.