AVPlayerViewController-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 "AVPlayerViewController-Subtitles"
Manually installation
Download (right-click) and add to your project.
Requirements
Version | Language | Minimum iOS Target |
---|---|---|
1.1.x | Swift 3.0 | iOS 8 |
1.0.x | Swift 2.x | iOS 8 |
Usage
import AVPlayerViewControllerSubtitles
// 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 moviePlayer = AVPlayerViewController()
moviePlayer.player = AVPlayer(url: URL(fileURLWithPath: videoFile!))
present(moviePlayer, animated: true, completion: nil)
// Add subtitles
moviePlayer.addSubtitles().open(file: subtitleURL)
moviePlayer.addSubtitles().open(file: subtitleURL, encoding: String.Encoding.utf8)
// Change text properties
moviePlayer.subtitleLabel?.textColor = UIColor.red
// Play
moviePlayer.player?.play()
Screenshot
Contact
License
Licensed under Apache License v2.0.
Copyright 2015-2016 Marc Hervera.