Skip to content

Commit

Permalink
fix: ensure tracks are well displayed in the sample
Browse files Browse the repository at this point in the history
  • Loading branch information
freeboub committed Apr 6, 2024
1 parent 85fb438 commit 52b8ec1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 55 deletions.
29 changes: 26 additions & 3 deletions examples/basic/src/VideoPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -706,10 +706,11 @@ class VideoPlayer extends Component {
<View style={styles.generalControls}>
<Text style={styles.controlOption}>AudioTrack</Text>
{this.state.audioTracks?.length <= 0 ? (
<Text style={styles.controlOption}>empty</Text>
<Text style={styles.emptyPickerItem}>empty</Text>
) : (
<Picker
style={styles.picker}
itemStyle={styles.pickerItem}
selectedValue={this.state.selectedAudioTrack?.value}
onValueChange={itemValue => {
console.log('on audio value change ' + itemValue);
Expand All @@ -736,10 +737,11 @@ class VideoPlayer extends Component {
)}
<Text style={styles.controlOption}>TextTrack</Text>
{this.state.textTracks?.length <= 0 ? (
<Text style={styles.controlOption}>empty</Text>
<Text style={styles.emptyPickerItem}>empty</Text>
) : (
<Picker
style={styles.picker}
itemStyle={styles.pickerItem}
selectedValue={this.state.selectedTextTrack?.value}
onValueChange={itemValue => {
console.log('on value change ' + itemValue);
Expand Down Expand Up @@ -929,6 +931,13 @@ const styles = StyleSheet.create({
paddingRight: 2,
lineHeight: 12,
},
pickerContainer: {
width: 100,
alignSelf: 'center',
color: 'white',
borderWidth: 1,
borderColor: 'red',
},
IndicatorStyle: {
flex: 1,
justifyContent: 'center',
Expand Down Expand Up @@ -966,10 +975,24 @@ const styles = StyleSheet.create({
width: 12,
},
picker: {
color: 'white',
flex: 1,
flexDirection: 'row',
justifyContent: 'center',
width: 100,
height: 40,
},
pickerItem: {
color: 'white',
width: 100,
height: 40,
},
emptyPickerItem: {
color: 'white',
marginTop: 20,
marginLeft: 20,
flex: 1,
width: 100,
height: 40,
},
});

Expand Down
51 changes: 0 additions & 51 deletions ios/Video/Features/RCTPlayerOperations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,57 +78,6 @@ enum RCTPlayerOperations {
}
}

// UNUSED
static func setStreamingText(player: AVPlayer?, criteria: SelectedTrackCriteria?) async {
let type = criteria?.type
var mediaOption: AVMediaSelectionOption!

guard let group = await RCTVideoAssetsUtils.getMediaSelectionGroup(asset: player?.currentItem?.asset, for: .legible) else {
return
}

if type == "disabled" {
// Do nothing. We want to ensure option is nil
} else if (type == "language") || (type == "title") {
let value = criteria?.value as? String
for i in 0 ..< group.options.count {
let currentOption: AVMediaSelectionOption! = group.options[i]
var optionValue: String!
if type == "language" {
optionValue = currentOption.extendedLanguageTag
} else {
optionValue = currentOption.commonMetadata.map(\.value)[0] as! String
}
if value == optionValue {
mediaOption = currentOption
break
}
}
// } 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]
}
}
} else { // default. invalid type or "system"
#if os(tvOS)
// Do noting. Fix for tvOS native audio menu language selector
#else
await player?.currentItem?.selectMediaOptionAutomatically(in: group)
return
#endif
}

#if os(tvOS)
// Do noting. Fix for tvOS native audio menu language selector
#else
// If a match isn't found, option will be nil and text tracks will be disabled
await player?.currentItem?.select(mediaOption, in: group)
#endif
}

static func setMediaSelectionTrackForCharacteristic(player: AVPlayer?, characteristic: AVMediaCharacteristic, criteria: SelectedTrackCriteria?) async {
let type = criteria?.type
var mediaOption: AVMediaSelectionOption!
Expand Down
2 changes: 1 addition & 1 deletion ios/Video/RCTVideo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1471,7 +1471,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
let audioTracks = await RCTVideoUtils.getAudioTrackInfo(self._player)
let textTracks = await RCTVideoUtils.getTextTrackInfo(self._player)

self.onTextTracks?(["textTracks": textTracks])
self.onTextTracks?(["textTracks": self._textTracks?.compactMap { $0.json } ?? textTracks.compactMap(\.json)])
self.onAudioTracks?(["audioTracks": audioTracks])
}
}
Expand Down

0 comments on commit 52b8ec1

Please sign in to comment.