Home

Awesome

<p align="center" > <img src="https://raw.github.com/mhergon/MPMoviePlayerController-Subtitles/master/assets/logo.png" alt="Logo" title="Logo" width=250> </p>

issues ā€ƒ stars ā€ƒ license

MPMoviePlayerController-Subtitles is a library to display subtitles on iOS. It's built as a Swift extension and it's very easy to integrate.

How To Get Started

Installation with CocoaPods

platform :ios, '8.0'
pod "MPMoviePlayerController-Subtitles"

Manually installation

Download (right-click) and add to your project.

Requirements

VersionLanguageMinimum iOS Target
2.2.xSwift 3.xiOS 8
2.0.xSwift 2.xiOS 8
1.xObjective-CiOS 6

Usage with player

import MPMoviePlayerControllerSubtitles
// Video file
let videoFile = Bundle.main.path(forResource: "trailer_720p", ofType: "mov")

// Subtitle file
let subtitleFile = Bundle.main.path(forResource: "trailer_720p", ofType: "srt")
let subtitleURL = URL(fileURLWithPath: subtitleFile!)

// Movie player
let moviePlayerView = MPMoviePlayerViewController(contentURL: URL(fileURLWithPath: videoFile!))
presentMoviePlayerViewControllerAnimated(moviePlayerView)

// Add subtitles
moviePlayerView?.moviePlayer.addSubtitles().open(file: subtitleURL)
moviePlayerView?.moviePlayer.addSubtitles().open(file: subtitleURL, encoding: String.Encoding.utf8)

// Change text properties
moviePlayerView?.moviePlayer.subtitleLabel?.textColor = UIColor.red

// Play
moviePlayerView?.moviePlayer.play()

Screenshot

<p align="center" > <img src="https://raw.github.com/mhergon/MPMoviePlayerController-Subtitles/master/assets/screenshot.png" alt="Screenshoot" title="Screenshoot"> </p>

Usage without player

From version 2.2 you can search text in the SubRip file or text without need play any file.

import MPMoviePlayerControllerSubtitles
// Subtitle file
let subtitleFile = Bundle.main.path(forResource: "trailer_720p", ofType: "srt")
let subtitleURL = URL(fileURLWithPath: subtitleFile!)

// Subtitle parser
let parser = Subtitles(file: subtitleURL, encoding: .utf8)

// Do something with result
let subtitles = parser.searchSubtitles(at: 2.0) // Search subtitle at 2.0 seconds

Contact

License

Licensed under Apache License v2.0. <br> Copyright 2017 Marc Hervera.