Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking β€œSign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add ios support for accessing WebVTT Subtitle Content #3541

Merged
Prev Previous commit
Next Next commit
refactor: return a string of the subtitles
Push the parsing/formatting to the consumer side.
coofzilla committed Feb 22, 2024
commit 4d5729c3eeeb32b8749116f137af3c38aa40e42c
11 changes: 2 additions & 9 deletions ios/Video/RCTVideo.swift
Original file line number Diff line number Diff line change
@@ -1389,15 +1389,8 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
}

func handleLegibleOutput(strings: [NSAttributedString]) {
let subtitles = strings.map { subtitle in
Dictionary(subtitle.string
.split(separator: "\n")
.compactMap { line -> (String, String)? in
let parts = line.split(separator: "=", maxSplits: 1).map(String.init)
return parts.count == 2 ? (parts[0], parts[1]) : nil
}, uniquingKeysWith: { _, last in last })
if let subtitles = strings.first {
self.onSubtitleTracks?(["subtitleTracks": subtitles.string])
}

self.onSubtitleTracks?(["subtitleTracks": subtitles])
}
}