From 52b8ec197aa7aeee19fcf846e2cd4418bbd07356 Mon Sep 17 00:00:00 2001 From: Olivier Bouillet Date: Sat, 6 Apr 2024 14:22:01 +0200 Subject: [PATCH] fix: ensure tracks are well displayed in the sample --- examples/basic/src/VideoPlayer.tsx | 29 +++++++++-- ios/Video/Features/RCTPlayerOperations.swift | 51 -------------------- ios/Video/RCTVideo.swift | 2 +- 3 files changed, 27 insertions(+), 55 deletions(-) diff --git a/examples/basic/src/VideoPlayer.tsx b/examples/basic/src/VideoPlayer.tsx index 98e1e17f02..0d53b10bd6 100644 --- a/examples/basic/src/VideoPlayer.tsx +++ b/examples/basic/src/VideoPlayer.tsx @@ -706,10 +706,11 @@ class VideoPlayer extends Component { AudioTrack {this.state.audioTracks?.length <= 0 ? ( - empty + empty ) : ( { console.log('on audio value change ' + itemValue); @@ -736,10 +737,11 @@ class VideoPlayer extends Component { )} TextTrack {this.state.textTracks?.length <= 0 ? ( - empty + empty ) : ( { console.log('on value change ' + itemValue); @@ -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', @@ -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, }, }); diff --git a/ios/Video/Features/RCTPlayerOperations.swift b/ios/Video/Features/RCTPlayerOperations.swift index 265ab23529..3f25515923 100644 --- a/ios/Video/Features/RCTPlayerOperations.swift +++ b/ios/Video/Features/RCTPlayerOperations.swift @@ -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! diff --git a/ios/Video/RCTVideo.swift b/ios/Video/RCTVideo.swift index cb22e870f0..daa2bcb8c9 100644 --- a/ios/Video/RCTVideo.swift +++ b/ios/Video/RCTVideo.swift @@ -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]) } }