AVPlayerViewController-Subtitles is a library to display subtitles on iOS. It's built as a Swift extension and it's very easy to integrate.
platform :ios, '8.0'
pod "AVPlayerViewController-Subtitles"
Download (right-click) and add to your project.
Version | Language | Minimum iOS Target |
---|---|---|
1.x | Swift | iOS 8 |
import AVPlayerViewControllerSubtitles
// Video file
let videoFile = NSBundle.mainBundle().pathForResource("trailer_720p", ofType: "mov")
// Subtitle file
let subtitleFile = NSBundle.mainBundle().pathForResource("trailer_720p", ofType: "srt")
let subtitleURL = NSURL(fileURLWithPath: subtitleFile!)
// Movie player
let moviePlayer = AVPlayerViewController()
moviePlayer.player = AVPlayer(URL: NSURL(fileURLWithPath: videoFile!))
presentViewController(moviePlayer, animated: true, completion: nil)
// Add subtitles
moviePlayer.addSubtitles().open(file: subtitleURL)
moviePlayer.addSubtitles().open(file: subtitleURL, encoding: NSUTF8StringEncoding) // optional
// Change text properties (optional)
moviePlayer.subtitleLabel?.textColor = UIColor.redColor()
// Play
moviePlayer.player?.play()
Licensed under Apache License v2.0.
Copyright 2015-2016 Marc Hervera.