1

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

4

1 回答 1

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使用计时器自动更改了文本......我只能通过自定义播放来播放和暂停播放器和暂停按钮...

于 2014-01-16T04:56:51.050 回答