From d5c8b514a1af23fa473f32b434612feac46fd321 Mon Sep 17 00:00:00 2001 From: Olivier Bouillet <62574056+freeboub@users.noreply.github.com> Date: Fri, 22 Mar 2024 07:58:09 +0100 Subject: [PATCH] fix(android): track selection parameter has change in last release. (#3594) Move all setSelectedTrack to String instead of Dynamic Co-authored-by: Olivier Bouillet --- .../exoplayer/ReactExoplayerView.java | 25 ++++++++++--------- .../exoplayer/ReactExoplayerViewManager.java | 12 ++++----- examples/basic/src/VideoPlayer.tsx | 17 +++++++------ 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java b/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java index 508a1a18..4343698e 100644 --- a/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -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); diff --git a/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java b/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java index ee69b28d..3b2e8c5f 100644 --- a/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java +++ b/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java @@ -253,10 +253,10 @@ public class ReactExoplayerViewManager extends ViewGroupManager { 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, + }); } };