Skip to content

shafqat-muneer/MPMoviePlayerController-Subtitles

 
 

Repository files navigation

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

About

Easy way to show SRT files on MPMoviePlayerController

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Objective-C 95.6%
  • Ruby 4.4%