Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple srt files parsing support #13

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 10 additions & 4 deletions Example/MPMoviePlayerControllerSubtitles.xcodeproj/project.pbxproj
Expand Up @@ -25,7 +25,8 @@
4B79B1C7184E90C700701BFC /* MainViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B79B1C5184E90C700701BFC /* MainViewController.m */; };
4B79B1C8184E90C700701BFC /* MainViewController~ipad.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4B79B1C6184E90C700701BFC /* MainViewController~ipad.xib */; };
4B79B1CA184E911B00701BFC /* MediaPlayer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4B79B1C9184E911B00701BFC /* MediaPlayer.framework */; };
4B79B1D0184E939B00701BFC /* example.srt in Resources */ = {isa = PBXBuildFile; fileRef = 4B79B1CF184E939B00701BFC /* example.srt */; };
C6F404761BC6762D00DA283C /* example-en.srt in Resources */ = {isa = PBXBuildFile; fileRef = C6F404741BC6762D00DA283C /* example-en.srt */; settings = {ASSET_TAGS = (); }; };
C6F404791BC677C700DA283C /* example-es.srt in Resources */ = {isa = PBXBuildFile; fileRef = C6F404781BC677C700DA283C /* example-es.srt */; settings = {ASSET_TAGS = (); }; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -63,7 +64,9 @@
4B79B1C5184E90C700701BFC /* MainViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MainViewController.m; sourceTree = "<group>"; };
4B79B1C6184E90C700701BFC /* MainViewController~ipad.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = "MainViewController~ipad.xib"; sourceTree = "<group>"; };
4B79B1C9184E911B00701BFC /* MediaPlayer.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MediaPlayer.framework; path = System/Library/Frameworks/MediaPlayer.framework; sourceTree = SDKROOT; };
4B79B1CF184E939B00701BFC /* example.srt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = example.srt; sourceTree = "<group>"; };
C6F404731BC6741B00DA283C /* Constants.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Constants.h; sourceTree = "<group>"; };
C6F404741BC6762D00DA283C /* example-en.srt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "example-en.srt"; sourceTree = "<group>"; };
C6F404781BC677C700DA283C /* example-es.srt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "example-es.srt"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -135,6 +138,7 @@
4B79B1D1184E95E800701BFC /* Example files */,
4B79B1CB184E915100701BFC /* MPMoviePlayerController+Subtitles */,
4B79B19C184E90AA00701BFC /* Supporting Files */,
C6F404731BC6741B00DA283C /* Constants.h */,
);
path = MPMoviePlayerControllerSubtitles;
sourceTree = "<group>";
Expand Down Expand Up @@ -181,7 +185,8 @@
isa = PBXGroup;
children = (
4B20EEE1184F8829007EB5B2 /* example.mp4 */,
4B79B1CF184E939B00701BFC /* example.srt */,
C6F404741BC6762D00DA283C /* example-en.srt */,
C6F404781BC677C700DA283C /* example-es.srt */,
);
name = "Example files";
sourceTree = "<group>";
Expand Down Expand Up @@ -262,10 +267,11 @@
buildActionMask = 2147483647;
files = (
4B79B1A0184E90AA00701BFC /* InfoPlist.strings in Resources */,
C6F404761BC6762D00DA283C /* example-en.srt in Resources */,
4B79B1C8184E90C700701BFC /* MainViewController~ipad.xib in Resources */,
4B79B1D0184E939B00701BFC /* example.srt in Resources */,
4B20EEE2184F8829007EB5B2 /* example.mp4 in Resources */,
4B79B1A8184E90AA00701BFC /* Images.xcassets in Resources */,
C6F404791BC677C700DA283C /* example-es.srt in Resources */,
4B20EEE4184F88E6007EB5B2 /* MainViewController~iphone.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
18 changes: 18 additions & 0 deletions Example/MPMoviePlayerControllerSubtitles/Constants.h
@@ -0,0 +1,18 @@
//
// Constants.h
// MPMoviePlayerControllerSubtitles
//
// Created by ShafqatMuneer on 08/10/2015.
// Copyright © 2015 mhergon. All rights reserved.
//

#ifndef Constants_h
#define Constants_h

enum LanguageOption {
OFF = 0,
ENGLISH = 1,
SPANISH = 2
};

#endif /* Constants_h */
Expand Up @@ -13,4 +13,5 @@
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "Constants.h"
#endif
11 changes: 8 additions & 3 deletions Example/MPMoviePlayerControllerSubtitles/MainViewController.m
Expand Up @@ -48,15 +48,20 @@ - (IBAction)showVideoAction:(UIButton *)sender {
NSURL *fileURL = [NSURL fileURLWithPath:filePathStr];

// Subtitles file
NSString *subtitlesPathStr = [[NSBundle mainBundle] pathForResource:@"example" ofType:@"srt"];
NSString *subtitlesPathStr_en = [[NSBundle mainBundle] pathForResource:@"example-en" ofType:@"srt"];
NSString *subtitlesPathStr_es = [[NSBundle mainBundle] pathForResource:@"example-es" ofType:@"srt"];

NSMutableDictionary *localFilesDictionary = [NSMutableDictionary dictionary];
[localFilesDictionary setObject:subtitlesPathStr_en forKey:@"en"];
[localFilesDictionary setObject:subtitlesPathStr_es forKey:@"es"];

// Create MoviePlayer
MPMoviePlayerViewController *player = [[MPMoviePlayerViewController alloc] initWithContentURL:fileURL];
[player.moviePlayer openSRTFileAtPath:subtitlesPathStr
[player.moviePlayer openSRTFileAtPath:localFilesDictionary
completion:^(BOOL finished) {

// Activate subtitles
[player.moviePlayer showSubtitles];
[player.moviePlayer showSubtitlesWithOption:SPANISH];

// Show video
[self presentMoviePlayerViewControllerAnimated:player];
Expand Down
30 changes: 30 additions & 0 deletions Example/MPMoviePlayerControllerSubtitles/example-es.srt
@@ -0,0 +1,30 @@
1
00:00:00,220 --> 00:00:01,215
Spanish First Text Example

2
00:00:03,148 --> 00:00:05,053
Spanish Second Text Example
with multiline support

3
00:00:08,004 --> 00:00:09,884
Spanish Third Text Example

4
00:00:11,300 --> 00:00:12,900
Spanish Fourth Text Example
with multiline support

5
00:00:15,500 --> 00:00:16,700
Spanish Fifth Text Example

6
00:00:18,434 --> 00:00:20,434
Spanish Sixth Text Example
with multiline support

7
00:00:22,600 --> 00:00:23,700
Spanish Last Text Example
8 changes: 4 additions & 4 deletions MPMoviePlayerController+Subtitles.h
Expand Up @@ -11,10 +11,10 @@
@interface MPMoviePlayerController (Subtitles)

#pragma mark - Methods
- (void)openWithSRTString:(NSString *)srtString completion:(void (^)(BOOL finished))success failure:(void (^)(NSError *error))failure;
- (void)openSRTFileAtPath:(NSString *)localFile completion:(void (^)(BOOL finished))success failure:(void (^)(NSError *error))failure;
- (void)showSubtitles;
- (void)hideSubtitles;
- (void)openSRTFileAtPath:(NSDictionary *)localFilesDictionary completion:(void (^)(BOOL finished))success failure:(void (^)(NSError *error))failure;
- (void)openWithSRTString:(NSDictionary *)srtStringsDictionary completion:(void (^)(BOOL finished))success failure:(void (^)(NSError *error))failure;
- (BOOL)showSubtitlesWithOption:(enum LanguageOption)option;
- (BOOL)hideSubtitles;

@end