2013-04-05 58 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 ...我只能通過自定義播放和暫停按鈕播放和暫停播放器...