我需要在xcode中的视频下显示字幕..我知道我们可以使用.srt文件来显示字幕..我可以解析.srt文件..但我的问题是我不知道如何制作文字要在视频下显示的.srt文件,如何设置时间间隔..有人请帮帮我
答案 0 :(得分:0)
我从堆栈溢出链接获得它....我忘记了链接...该链接中的代码是这个 -
NSString *path = [[NSBundle mainBundle] pathForResource:@"srtfilename" ofType:@"srt"];
NSString *string = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:NULL];
NSScanner *scanner = [NSScanner scannerWithString:string];
while (![scanner isAtEnd])
{
@autoreleasepool
{
NSString *indexString;
(void) [scanner scanUpToCharactersFromSet:[NSCharacterSet newlineCharacterSet] intoString:&indexString];
NSString *startString;
(void) [scanner scanUpToString:@" --> " intoString:&startString];
// My string constant doesn't begin with spaces because scanners
// skip spaces and newlines by default.
(void) [scanner scanString:@"-->" intoString:NULL];
NSString *endString;
(void) [scanner scanUpToCharactersFromSet:[NSCharacterSet newlineCharacterSet] intoString:&endString];
NSString *textString;
// (void) [scanner scanUpToCharactersFromSet:[NSCharacterSet newlineCharacterSet] intoString:&textString];
// BEGIN EDIT
(void) [scanner scanUpToString:@"\r\n\r\n" intoString:&textString];
textString = [textString stringByReplacingOccurrencesOfString:@"\r\n" withString:@" "];
// Addresses trailing space added if CRLF is on a line by itself at the end of the SRT file
textString = [textString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
// END EDIT
NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:
indexString , @"index",
startString, @"start",
endString , @"end",
textString , @"text",
nil];
NSLog(@"%@", dictionary); } }
我做了解析srt文件...我在电影播放器(MPMovieControlStyleNone)视图中添加了UITextView ....我确实通过使用startString和endString使用计时器自动更改文本...我只能播放和暂停播放器通过自定义播放和暂停按钮......