Skip to content

Latest commit

 

History

History
68 lines (46 loc) · 2.45 KB

File metadata and controls

68 lines (46 loc) · 2.45 KB

MPMoviePlayerController-Subtitles

Easy way to show SRT files on MPMoviePlayerController

MPMoviePlayerController-Subtitles

Usage

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);
                                   
                               }];

Architecture

    // 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;

Requirements

Requires Xcode 6+, targeting either iOS 6.0+ and above

Contact

Bitdeli Badge