diff --git a/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java b/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java index 508a1a1879..4343698e3c 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 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) { @@ -1661,7 +1661,7 @@ 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; } @@ -1669,17 +1669,18 @@ public void setSelectedTrack(int trackType, String type, Dynamic value) { } 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 @@ 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); diff --git a/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java b/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java index ee69b28d45..3b2e8c5fa9 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 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); } @@ -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); } @@ -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); } diff --git a/examples/basic/src/VideoPlayer.tsx b/examples/basic/src/VideoPlayer.tsx index c4866e97bf..a92d71bc3a 100644 --- a/examples/basic/src/VideoPlayer.tsx +++ b/examples/basic/src/VideoPlayer.tsx @@ -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, + }); } };