Open a-radwan opened 6 years ago
I only implemented str subtitle parser, so it can't support vtt file.
To whom who wants to use this library with VTT format subtitle, you can do the following,
Here you can find my formatter. Stackoverflow question link
+ (NSString *)srtSubtitleFromVTT:(NSString *)content {
NSArray *lines = [self split:content];
NSString *output = @"";
NSInteger i = 0;
NSError *error;
NSString *newLine;
for (NSString *line in lines) {
newLine = line;
NSCharacterSet* notDigits = [[NSCharacterSet decimalDigitCharacterSet] invertedSet];
if([[line stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"\n\r "]] rangeOfCharacterFromSet:notDigits].location == NSNotFound) {
continue;
}
NSString *pattern1 = @"(\\d{2}):(\\d{2}):(\\d{2})\\.(\\d{3})"; // '01:52:52.554'
NSString *pattern2 = @"(\\d{2}):(\\d{2})\\.(\\d{3})"; // '00:08.301'
NSRegularExpression* regex = [NSRegularExpression regularExpressionWithPattern: pattern1 options:0 error:&error];
NSArray* matches = [regex matchesInString:line options:0 range: NSMakeRange(0, line.length)];
NSString *pattern ;
NSString *template;
if (matches.count) {
pattern = pattern1;
template = @"$1:$2:$3,$4";
} else {
regex = [NSRegularExpression regularExpressionWithPattern: pattern2 options:0 error:&error];
matches = [regex matchesInString:line options:0 range: NSMakeRange(0, line.length)];
if (matches.count) {
pattern = pattern2;
template = @"00:$1:$2,$3";
}
}
if (matches.count && !error) {
i++;
output = [output stringByAppendingString:@"\r\n\r\n"];
output = [output stringByAppendingString:[@(i) stringValue]];
output = [output stringByAppendingString:@"\r\n"];
newLine = [line stringByReplacingWithPattern:pattern withTemplate:template error:&error];
}
if([newLine containsString:@"WEBVTT"]) {
continue;
}
output = [output stringByAppendingString:newLine];
output = [output stringByAppendingString:@"\r\n"];
}
return output;
}
+ (NSArray *)split:(NSString *)content {
NSArray *lines = [content componentsSeparatedByString: @"\n"];
if (lines.count == 1) {
lines = [content componentsSeparatedByString: @"\r\n"];
if (lines.count == 1) {
lines = [content componentsSeparatedByString: @"\n"];
}
}
return lines;
}
Hi @a-radwan, the function stringByReplacingWithPattern
is deprecated I think.
@allenlinli ,its a utility I have implemented
- (NSString *)stringByReplacingWithPattern:(NSString *)pattern withTemplate:(NSString *)template error:(NSError **)error {
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:pattern
options:NSRegularExpressionCaseInsensitive
error:error];
return [regex stringByReplacingMatchesInString:self
options:0
range:NSMakeRange(0, self.length)
withTemplate:template];
}
Why the video player doesn't supports subtitles with VTT format.
Installed with
Issue Description
The video player doesn't display remote subtitles with VTT format. I tried it for remote link url
I also tried a locally vtt file