Skip to content

Commit aa1f881

Browse files
committed
Added SubRip parser without player
v1.2
1 parent 602f6d0 commit aa1f881

File tree

6 files changed

+197
-108
lines changed

6 files changed

+197
-108
lines changed

AVPlayerViewController-Subtitles.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
Pod::Spec.new do |spec|
22
spec.name = 'AVPlayerViewController-Subtitles'
33
spec.platform = :ios, "8.0"
4-
spec.version = '1.1.2'
4+
spec.version = '1.2'
55
spec.license = { :type => 'Apache License, Version 2.0' }
66
spec.homepage = 'https://github.com/mhergon/AVPlayerViewController-Subtitles'
77
spec.authors = { 'Marc Hervera' => '[email protected]' }
88
spec.summary = 'Subtitles made easy'
9-
spec.source = { :git => 'https://github.com/mhergon/AVPlayerViewController-Subtitles.git', :tag => 'v1.1.2' }
9+
spec.source = { :git => 'https://github.com/mhergon/AVPlayerViewController-Subtitles.git', :tag => 'v1.2' }
1010
spec.source_files = 'Subtitles.swift'
1111
spec.requires_arc = true
1212
spec.module_name = 'AVPlayerViewControllerSubtitles'

Example/AVPlayerViewController-Subtitles.xcodeproj/project.pbxproj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
isa = PBXProject;
117117
attributes = {
118118
LastSwiftUpdateCheck = 0720;
119-
LastUpgradeCheck = 0720;
119+
LastUpgradeCheck = 0820;
120120
ORGANIZATIONNAME = "Marc Hervera";
121121
TargetAttributes = {
122122
4B4FC9551C2A9D60002AE636 = {
@@ -196,8 +196,10 @@
196196
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
197197
CLANG_WARN_EMPTY_BODY = YES;
198198
CLANG_WARN_ENUM_CONVERSION = YES;
199+
CLANG_WARN_INFINITE_RECURSION = YES;
199200
CLANG_WARN_INT_CONVERSION = YES;
200201
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
202+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
201203
CLANG_WARN_UNREACHABLE_CODE = YES;
202204
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
203205
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -240,8 +242,10 @@
240242
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
241243
CLANG_WARN_EMPTY_BODY = YES;
242244
CLANG_WARN_ENUM_CONVERSION = YES;
245+
CLANG_WARN_INFINITE_RECURSION = YES;
243246
CLANG_WARN_INT_CONVERSION = YES;
244247
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
248+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
245249
CLANG_WARN_UNREACHABLE_CODE = YES;
246250
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
247251
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -260,6 +264,7 @@
260264
IPHONEOS_DEPLOYMENT_TARGET = 9.2;
261265
MTL_ENABLE_DEBUG_INFO = NO;
262266
SDKROOT = iphoneos;
267+
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
263268
VALIDATE_PRODUCT = YES;
264269
};
265270
name = Release;
Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9531" systemVersion="15C50" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="16D32" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
3+
<device id="retina4_7" orientation="portrait">
4+
<adaptation id="fullscreen"/>
5+
</device>
36
<dependencies>
47
<deployment identifier="iOS"/>
5-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/>
8+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
9+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
610
</dependencies>
711
<scenes>
812
<!--View Controller-->
@@ -14,19 +18,19 @@
1418
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
1519
</layoutGuides>
1620
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
17-
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
21+
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
1822
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
1923
<subviews>
2024
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="FXG-ec-2y2">
21-
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
25+
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
2226
<fontDescription key="fontDescription" type="system" pointSize="30"/>
2327
<state key="normal" title="Show video"/>
2428
<connections>
2529
<action selector="showVideo:" destination="BYZ-38-t0r" eventType="touchUpInside" id="mP2-pB-fJh"/>
2630
</connections>
2731
</button>
2832
</subviews>
29-
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
33+
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
3034
<constraints>
3135
<constraint firstAttribute="trailing" secondItem="FXG-ec-2y2" secondAttribute="trailing" id="EFa-4Q-IzW"/>
3236
<constraint firstItem="FXG-ec-2y2" firstAttribute="top" secondItem="8bC-Xf-vdC" secondAttribute="top" id="HRz-tw-1YM"/>
@@ -37,7 +41,7 @@
3741
</viewController>
3842
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
3943
</objects>
40-
<point key="canvasLocation" x="325" y="387"/>
44+
<point key="canvasLocation" x="-127.5" y="133.5"/>
4145
</scene>
4246
</scenes>
4347
</document>

Example/AVPlayerViewController-Subtitles/ViewController.swift

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ import UIKit
1010
import MediaPlayer
1111
import AVKit
1212

13-
class ViewController: UIViewController {
1413

14+
class ViewController: UIViewController {
15+
1516
override func viewDidLoad() {
1617
super.viewDidLoad()
1718
// Do any additional setup after loading the view, typically from a nib.
19+
1820
}
1921

2022
override func didReceiveMemoryWarning() {
@@ -39,7 +41,7 @@ class ViewController: UIViewController {
3941

4042
// Add subtitles
4143
moviePlayer.addSubtitles().open(file: subtitleURL)
42-
moviePlayer.addSubtitles().open(file: subtitleURL, encoding: String.Encoding.utf8)
44+
moviePlayer.addSubtitles().open(file: subtitleURL, encoding: .utf8)
4345

4446
// Change text properties
4547
moviePlayer.subtitleLabel?.textColor = UIColor.red
@@ -48,6 +50,21 @@ class ViewController: UIViewController {
4850
moviePlayer.player?.play()
4951

5052
}
51-
53+
54+
func subtitleParser() {
55+
56+
// Subtitle file
57+
let subtitleFile = Bundle.main.path(forResource: "trailer_720p", ofType: "srt")
58+
let subtitleURL = URL(fileURLWithPath: subtitleFile!)
59+
60+
// Subtitle parser
61+
let parser = Subtitles(file: subtitleURL, encoding: .utf8)
62+
63+
// Do something with result
64+
let subtitles = parser.searchSubtitles(at: 2.0) // Search subtitle at 2.0 seconds
65+
66+
}
67+
68+
5269
}
5370

README.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,11 @@ pod "AVPlayerViewController-Subtitles"
2828

2929
| Version | Language | Minimum iOS Target |
3030
|:--------------------:|:---------------------------:|:---------------------------:|
31-
| 1.1.x | Swift 3.0 | iOS 8 |
31+
| 1.2.x | Swift 3.0 | iOS 8 |
3232
| 1.0.x | Swift 2.x | iOS 8 |
3333

3434

35-
### Usage
36-
35+
### Usage with player
3736

3837
```swift
3938
import AVPlayerViewControllerSubtitles
@@ -63,11 +62,27 @@ moviePlayer.subtitleLabel?.textColor = UIColor.red
6362
moviePlayer.player?.play()
6463
```
6564

66-
## Screenshot
65+
#### Screenshot
6766
<p align="center" >
6867
<img src="https://raw.github.com/mhergon/AVPlayerViewController-Subtitles/master/assets/screenshot.png" alt="Screenshoot" title="Screenshoot">
6968
</p>
7069

70+
### Usage without player
71+
72+
From version 1.2 you can search text in the SubRip file or text without need play any file.
73+
74+
```
75+
// Subtitle file
76+
let subtitleFile = Bundle.main.path(forResource: "trailer_720p", ofType: "srt")
77+
let subtitleURL = URL(fileURLWithPath: subtitleFile!)
78+
79+
// Subtitle parser
80+
let parser = Subtitles(file: subtitleURL, encoding: .utf8)
81+
82+
// Do something with result
83+
let subtitles = parser.searchSubtitles(at: 2.0) // Search subtitle at 2.0 seconds
84+
```
85+
7186
## Contact
7287

7388
- [Linkedin][2]

0 commit comments

Comments
 (0)