Skip to content

Commit

Permalink
fix(ios): add text tracks only if we successfully insertTimeRage (The…
Browse files Browse the repository at this point in the history
…WidlarzGroup#3557)

insertTimeRage can fail & if we add failed textTrack to our validTextTracks array, video can crash later on selectTextTrack
we also add en empty textTrack only we we have validTextTrack

related to TheWidlarzGroup#3480
  • Loading branch information
gkueny authored Mar 4, 2024
1 parent c0aa3d6 commit b73baad
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions ios/Video/Features/RCTVideoUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -299,23 +299,32 @@ enum RCTVideoUtils {
if let textTracks {
for i in 0 ..< tracks.count {
guard let track = tracks[i]?.first else { continue } // fix when there's no textTrackAsset
validTextTracks.append(textTracks[i])

let textCompTrack: AVMutableCompositionTrack! = mixComposition.addMutableTrack(withMediaType: AVMediaType.text,
preferredTrackID: kCMPersistentTrackID_Invalid)
try? textCompTrack.insertTimeRange(
CMTimeRangeMake(start: .zero, duration: videoAsset.timeRange.duration),
of: track,
at: .zero
)

do {
try textCompTrack.insertTimeRange(
CMTimeRangeMake(start: .zero, duration: videoAsset.timeRange.duration),
of: track,
at: .zero
)
validTextTracks.append(textTracks[i])
} catch {
// TODO: upgrade error by call some props callback to better inform user
print("Error occurred on textTrack insert attempt: \(error.localizedDescription)")
continue
}
}
}

return
}.then {
let emptyVttFile: TextTrack? = self.createEmptyVttFile()
if emptyVttFile != nil {
validTextTracks.append(emptyVttFile!)
if !validTextTracks.isEmpty {
let emptyVttFile: TextTrack? = self.createEmptyVttFile()
if emptyVttFile != nil {
validTextTracks.append(emptyVttFile!)
}
}

fulfill(validTextTracks)
Expand Down

0 comments on commit b73baad

Please sign in to comment.