fix(ios): ensure behavior is correct with empty text track list (#4123)
* fix(ios): ensure behavior is correct with empty text track list
This commit is contained in:
parent
7a2b4014f4
commit
3a32d67087
@ -78,6 +78,11 @@ export const srcAllPlatformList = [
|
|||||||
uri: 'https://bitmovin-a.akamaihd.net/content/sintel/hls/playlist.m3u8',
|
uri: 'https://bitmovin-a.akamaihd.net/content/sintel/hls/playlist.m3u8',
|
||||||
startPosition: 50000,
|
startPosition: 50000,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
description: 'mp3 with texttrack',
|
||||||
|
uri: 'https://traffic.libsyn.com/democracynow/wx2024-0702_SOT_DeadCalm-LucileSmith-FULL-V2.mxf-audio.mp3', // an mp3 file
|
||||||
|
textTracks: [], // empty text track list
|
||||||
|
},
|
||||||
{
|
{
|
||||||
description: 'BigBugBunny sideLoaded subtitles',
|
description: 'BigBugBunny sideLoaded subtitles',
|
||||||
// sideloaded subtitles wont work for streaming like HLS on ios
|
// sideloaded subtitles wont work for streaming like HLS on ios
|
||||||
|
@ -42,7 +42,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
private var _repeat = false
|
private var _repeat = false
|
||||||
private var _isPlaying = false
|
private var _isPlaying = false
|
||||||
private var _allowsExternalPlayback = true
|
private var _allowsExternalPlayback = true
|
||||||
private var _textTracks: [TextTrack]?
|
private var _textTracks: [TextTrack] = []
|
||||||
private var _selectedTextTrackCriteria: SelectedTrackCriteria?
|
private var _selectedTextTrackCriteria: SelectedTrackCriteria?
|
||||||
private var _selectedAudioTrackCriteria: SelectedTrackCriteria?
|
private var _selectedAudioTrackCriteria: SelectedTrackCriteria?
|
||||||
private var _playbackStalled = false
|
private var _playbackStalled = false
|
||||||
@ -598,7 +598,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
}
|
}
|
||||||
|
|
||||||
func playerItemPrepareText(asset: AVAsset!, assetOptions: NSDictionary?, uri: String) async -> AVPlayerItem {
|
func playerItemPrepareText(asset: AVAsset!, assetOptions: NSDictionary?, uri: String) async -> AVPlayerItem {
|
||||||
if (self._textTracks == nil) || self._textTracks?.isEmpty == true || (uri.hasSuffix(".m3u8")) {
|
if self._textTracks.isEmpty == true || (uri.hasSuffix(".m3u8")) {
|
||||||
return await self.playerItemPropegateMetadata(AVPlayerItem(asset: asset))
|
return await self.playerItemPropegateMetadata(AVPlayerItem(asset: asset))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -612,7 +612,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
textTracks: self._textTracks
|
textTracks: self._textTracks
|
||||||
)
|
)
|
||||||
|
|
||||||
if validTextTracks.count != self._textTracks?.count {
|
if validTextTracks.count != self._textTracks.count {
|
||||||
self.setTextTracks(validTextTracks)
|
self.setTextTracks(validTextTracks)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -963,8 +963,8 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
|
|
||||||
func setSelectedTextTrack(_ selectedTextTrack: SelectedTrackCriteria?) {
|
func setSelectedTextTrack(_ selectedTextTrack: SelectedTrackCriteria?) {
|
||||||
_selectedTextTrackCriteria = selectedTextTrack
|
_selectedTextTrackCriteria = selectedTextTrack
|
||||||
if _textTracks != nil { // sideloaded text tracks
|
if !_textTracks.isEmpty { // sideloaded text tracks
|
||||||
RCTPlayerOperations.setSideloadedText(player: _player, textTracks: _textTracks!, criteria: _selectedTextTrackCriteria)
|
RCTPlayerOperations.setSideloadedText(player: _player, textTracks: _textTracks, criteria: _selectedTextTrackCriteria)
|
||||||
} else { // text tracks included in the HLS playlist§
|
} else { // text tracks included in the HLS playlist§
|
||||||
Task {
|
Task {
|
||||||
await RCTPlayerOperations.setMediaSelectionTrackForCharacteristic(player: _player, characteristic: AVMediaCharacteristic.legible,
|
await RCTPlayerOperations.setMediaSelectionTrackForCharacteristic(player: _player, characteristic: AVMediaCharacteristic.legible,
|
||||||
@ -979,8 +979,11 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
}
|
}
|
||||||
|
|
||||||
func setTextTracks(_ textTracks: [TextTrack]?) {
|
func setTextTracks(_ textTracks: [TextTrack]?) {
|
||||||
_textTracks = textTracks
|
if textTracks == nil {
|
||||||
|
_textTracks = []
|
||||||
|
} else {
|
||||||
|
_textTracks = textTracks!
|
||||||
|
}
|
||||||
// in case textTracks was set after selectedTextTrack
|
// in case textTracks was set after selectedTextTrack
|
||||||
if _selectedTextTrackCriteria != nil { setSelectedTextTrack(_selectedTextTrackCriteria) }
|
if _selectedTextTrackCriteria != nil { setSelectedTextTrack(_selectedTextTrackCriteria) }
|
||||||
}
|
}
|
||||||
@ -1294,7 +1297,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
_playerItem = nil
|
_playerItem = nil
|
||||||
_source = nil
|
_source = nil
|
||||||
_chapters = nil
|
_chapters = nil
|
||||||
_textTracks = nil
|
_textTracks = []
|
||||||
_selectedTextTrackCriteria = nil
|
_selectedTextTrackCriteria = nil
|
||||||
_selectedAudioTrackCriteria = nil
|
_selectedAudioTrackCriteria = nil
|
||||||
_presentingViewController = nil
|
_presentingViewController = nil
|
||||||
@ -1448,7 +1451,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
"orientation": orientation,
|
"orientation": orientation,
|
||||||
],
|
],
|
||||||
"audioTracks": audioTracks,
|
"audioTracks": audioTracks,
|
||||||
"textTracks": self._textTracks?.compactMap { $0.json } ?? textTracks.map(\.json),
|
"textTracks": self._textTracks.compactMap { $0.json } ?? textTracks.map(\.json),
|
||||||
"target": self.reactTag as Any])
|
"target": self.reactTag as Any])
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1646,7 +1649,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
if onTextTracks != nil {
|
if onTextTracks != nil {
|
||||||
Task {
|
Task {
|
||||||
let textTracks = await RCTVideoUtils.getTextTrackInfo(self._player)
|
let textTracks = await RCTVideoUtils.getTextTrackInfo(self._player)
|
||||||
self.onTextTracks?(["textTracks": self._textTracks?.compactMap { $0.json } ?? textTracks.compactMap(\.json)])
|
self.onTextTracks?(["textTracks": self._textTracks.compactMap { $0.json } ?? textTracks.compactMap(\.json)])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user