File tree Expand file tree Collapse file tree 1 file changed +4
-15
lines changed
Sora/MediaUtils/CustomPlayer/Helpers Expand file tree Collapse file tree 1 file changed +4
-15
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ struct SubtitleCue: Identifiable {
1313 let endTime : Double
1414 let text : String
1515 let lines : [ String ]
16-
16+
1717 init ( startTime: Double , endTime: Double , text: String ) {
1818 self . startTime = startTime
1919 self . endTime = endTime
@@ -46,7 +46,8 @@ class VTTSubtitlesLoader: ObservableObject {
4646 return
4747 }
4848
49- let detectedFormat = self . determineSubtitleFormat ( from: url)
49+ let trimmed = subtitleContent. trimmingCharacters ( in: . whitespacesAndNewlines)
50+ let detectedFormat : SubtitleFormat = trimmed. contains ( " WEBVTT " ) ? . vtt : . srt
5051
5152 DispatchQueue . main. async {
5253 switch detectedFormat {
@@ -55,7 +56,7 @@ class VTTSubtitlesLoader: ObservableObject {
5556 case . srt:
5657 self . cues = self . parseSRT ( content: subtitleContent)
5758 case . unknown:
58- if subtitleContent . trimmingCharacters ( in : . whitespacesAndNewlines ) . hasPrefix ( " WEBVTT " ) {
59+ if trimmed . contains ( " WEBVTT " ) {
5960 self . cues = self . parseVTT ( content: subtitleContent)
6061 } else {
6162 self . cues = self . parseSRT ( content: subtitleContent)
@@ -65,18 +66,6 @@ class VTTSubtitlesLoader: ObservableObject {
6566 } . resume ( )
6667 }
6768
68- private func determineSubtitleFormat( from url: URL ) -> SubtitleFormat {
69- let fileExtension = url. pathExtension. lowercased ( )
70- switch fileExtension {
71- case " vtt " , " webvtt " :
72- return . vtt
73- case " srt " :
74- return . srt
75- default :
76- return . unknown
77- }
78- }
79-
8069 private func parseVTT( content: String ) -> [ SubtitleCue ] {
8170 let contentLines = content. components ( separatedBy: . newlines)
8271 var subtitleCues : [ SubtitleCue ] = [ ]
You can’t perform that action at this time.
0 commit comments