Skip to content

Commit

Permalink
fix(ios): fix text track selection by index (#3728)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
freeboub authored May 4, 2024
1 parent 4c63988 commit 51e22ab
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 17 deletions.
32 changes: 23 additions & 9 deletions examples/basic/src/VideoPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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,
},
});
Expand All @@ -814,13 +820,21 @@ class VideoPlayer extends Component {
if (!track) {
return;
}
return (
<Picker.Item
label={track.language}
value={track.language}
key={track.language}
/>
);
if (this.textTracksSelectionBy === 'index') {
return (
<Picker.Item
label={`${track.index}`}
value={track.index}
key={track.index}
/>);
} else {
return (
<Picker.Item
label={track.language}
value={track.language}
key={track.language}
/>);
}
})}
</Picker>
)}
Expand Down
4 changes: 2 additions & 2 deletions ios/Video/DataStructures/SelectedTrackCriteria.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
struct SelectedTrackCriteria {
let type: String
let value: Any?
let value: String?

let json: NSDictionary?

Expand All @@ -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
}
}
16 changes: 10 additions & 6 deletions ios/Video/Features/RCTPlayerOperations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
}
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 51e22ab

Please sign in to comment.