From 89df9d69ff96f7d6ff3d493bf1a3eb9c3da51c3c Mon Sep 17 00:00:00 2001 From: Olivier Bouillet <62574056+freeboub@users.noreply.github.com> Date: Mon, 2 Sep 2024 19:08:27 +0200 Subject: [PATCH] fix(ios): ensure we don't disable tracks when not necessary (causes black screen) (#4130) --- ios/Video/Features/RCTPlayerOperations.swift | 6 +++++- ios/Video/RCTVideo.swift | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ios/Video/Features/RCTPlayerOperations.swift b/ios/Video/Features/RCTPlayerOperations.swift index 9c80c85f..d1ca88a9 100644 --- a/ios/Video/Features/RCTPlayerOperations.swift +++ b/ios/Video/Features/RCTPlayerOperations.swift @@ -15,11 +15,15 @@ enum RCTPlayerOperations { let trackCount: Int! = player?.currentItem?.tracks.count ?? 0 // The first few tracks will be audio & video track - var firstTextIndex = 0 + var firstTextIndex = -1 for i in 0 ..< trackCount where player?.currentItem?.tracks[i].assetTrack?.hasMediaCharacteristic(.legible) ?? false { firstTextIndex = i break } + if firstTextIndex == -1 { + // no sideLoaded text track available (can happen with invalid vtt url) + return + } var selectedTrackIndex: Int = RCTVideoUnset diff --git a/ios/Video/RCTVideo.swift b/ios/Video/RCTVideo.swift index 2e405c76..3aaf532c 100644 --- a/ios/Video/RCTVideo.swift +++ b/ios/Video/RCTVideo.swift @@ -613,6 +613,10 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH textTracks: self._textTracks ) + if validTextTracks.isEmpty { + DebugLog("Strange state, not valid textTrack") + } + if validTextTracks.count != self._textTracks.count { self.setTextTracks(validTextTracks) }