From 51e22abfe35978ee3fd1a7b3dc6f6c769d1b24bc Mon Sep 17 00:00:00 2001 From: Olivier Bouillet <62574056+freeboub@users.noreply.github.com> Date: Sat, 4 May 2024 15:20:59 +0200 Subject: [PATCH] fix(ios): fix text track selection by index (#3728) * fix(ts): onPlaybackRateChangeData was not correctly typed * fix: ensure tracks are well displayed in the sample * fix(ios): text tracks selection by index. regression due to codegen rework * chore: make selection by index testable (need a small manual patch) * chore(ios): fix linter warning --- examples/basic/src/VideoPlayer.tsx | 32 +++++++++++++------ .../SelectedTrackCriteria.swift | 4 +-- ios/Video/Features/RCTPlayerOperations.swift | 16 ++++++---- 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/examples/basic/src/VideoPlayer.tsx b/examples/basic/src/VideoPlayer.tsx index 7b858627..c44ee372 100644 --- a/examples/basic/src/VideoPlayer.tsx +++ b/examples/basic/src/VideoPlayer.tsx @@ -104,6 +104,9 @@ class VideoPlayer extends Component { seekerWidth = 0; + // internal usage change to index if you want to select tracks by index instead of lang + textTracksSelectionBy = 'lang'; + srcAllPlatformList = [ { description: 'local file landscape', @@ -300,7 +303,10 @@ class VideoPlayer extends Component { if (selectedTrack?.language) { this.setState({ textTracks: data.textTracks, - selectedTextTrack: { + selectedTextTrack: this.textTracksSelectionBy === 'index' ? { + type: 'index', + value: selectedTrack?.index, + }: { type: 'language', value: selectedTrack?.language, }, @@ -804,7 +810,7 @@ class VideoPlayer extends Component { console.log('on value change ' + itemValue); this.setState({ selectedTextTrack: { - type: 'language', + type: this.textTracksSelectionBy === 'index' ? 'index': 'language', value: itemValue, }, }); @@ -814,13 +820,21 @@ class VideoPlayer extends Component { if (!track) { return; } - return ( - - ); + if (this.textTracksSelectionBy === 'index') { + return ( + ); + } else { + return ( + ); + } })} )} diff --git a/ios/Video/DataStructures/SelectedTrackCriteria.swift b/ios/Video/DataStructures/SelectedTrackCriteria.swift index 41d68aff..b4217817 100644 --- a/ios/Video/DataStructures/SelectedTrackCriteria.swift +++ b/ios/Video/DataStructures/SelectedTrackCriteria.swift @@ -1,6 +1,6 @@ struct SelectedTrackCriteria { let type: String - let value: Any? + let value: String? let json: NSDictionary? @@ -13,6 +13,6 @@ struct SelectedTrackCriteria { } self.json = json self.type = json["type"] as? String ?? "" - self.value = json["value"] + self.value = json["value"] as? String } } diff --git a/ios/Video/Features/RCTPlayerOperations.swift b/ios/Video/Features/RCTPlayerOperations.swift index 3f255159..9c80c85f 100644 --- a/ios/Video/Features/RCTPlayerOperations.swift +++ b/ios/Video/Features/RCTPlayerOperations.swift @@ -45,9 +45,11 @@ enum RCTPlayerOperations { } } } else if type == "index" { - if let value = criteria?.value, let index = value as? Int { - if textTracks.count > index { - selectedTrackIndex = index + if let value = criteria?.value { // check value is provided + if let indexValue = Int(value as String) { // ensure value is an integer an String to Snt + if textTracks.count > indexValue { // ensure value is in group range + selectedTrackIndex = indexValue + } } } } @@ -106,9 +108,11 @@ enum RCTPlayerOperations { // } else if ([type isEqualToString:@"default"]) { // option = group.defaultOption; */ } else if type == "index" { - if let value = criteria?.value, let index = value as? Int { - if group.options.count > index { - mediaOption = group.options[index] + if let value = criteria?.value { // check value is provided + if let indexValue = Int(value as String) { // ensure value is an integer an String to Snt + if group.options.count > indexValue { // ensure value is in group range + mediaOption = group.options[indexValue] + } } } } else { // default. invalid type or "system"