Easy way to show SRT files on MPMoviePlayerController
Import
#import "MPMoviePlayerController+Subtitles.h"
Use it!
// Video file
NSString *filePathStr = [[NSBundle mainBundle] pathForResource:@"example" ofType:@"mp4"];
NSURL *fileURL = [NSURL fileURLWithPath:filePathStr];
// Subtitles file
NSString *subtitlesPathStr = [[NSBundle mainBundle] pathForResource:@"example" ofType:@"srt"];
// Create MoviePlayer
MPMoviePlayerViewController *player = [[MPMoviePlayerViewController alloc] initWithContentURL:fileURL];
[player.moviePlayer openSRTFileAtPath:subtitlesPathStr
completion:^(BOOL finished) {
// Activate subtitles
[player.moviePlayer showSubtitles];
// Show video
[self presentMoviePlayerViewControllerAnimated:player];
} failure:^(NSError *error) {
NSLog(@"Error: %@", error.description);
}];
// Process string and prepare to play with video
- (void)openWithSRTString:(NSString*)srtString completion:(void (^)(BOOL finished))success failure:(void (^)(NSError *error))failure;
// Open subtitle file and prepare to play with video
- (void)openSRTFileAtPath:(NSString *)localFile completion:(void (^)(BOOL finished))success failure:(void (^)(NSError *error))failure;
// Show subtitles
- (void)showSubtitles;
// Hide subtitles
- (void)hideSubtitles;
Requires Xcode 6+, targeting either iOS 6.0+ and above