我需要在xcode的视频下显示字幕..我知道我们可以用.srt文件来显示字幕..我可以解析.srt文件..但我的问题是,我不知道如何使.srt文件中的文本在视频下显示,如何设置时间间隔。有谁能帮帮我
发布于 2014-01-16 12:56:51
我是从堆栈溢出链接获得的.我忘了那个链接。链接中的代码是这样的-
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自动更改了文本...我只能通过自定义的播放和暂停按钮来播放和暂停播放器...
https://stackoverflow.com/questions/15833735
复制相似问题