2013-04-05 59 views
1

我需要在xcode视频下显示字幕..我知道我们可以使用.srt文件来显示字幕..我可以解析.srt文件..但我的问题是我不知道如何使.srt文件中的文本显示在视频下,如何设置时间间隔..有人请帮助我如何使用.srt文件在xcode中显示字幕

+0

任何人都知道...如何在xcode中使用.srt文件 – 2013-04-17 06:05:39

+0

您得到/ – 2014-01-13 09:28:02

回答

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文件...我添加的UITextView上的电影播放器​​(MPMovieControlStyleNone)查看....我没有用startString自动更改文本和使用定时器的endString ...我只能通过自定义播放和暂停按钮播放和暂停播放器...