Skip to content

sonysum/AVPlayerViewController-Subtitles

 
 

Repository files navigation

Logo

issuesstarslicense

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.x Swift iOS 8

Usage

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()

Screenshot

Screenshoot

Contact

License

Licensed under Apache License v2.0.
Copyright 2015-2016 Marc Hervera.

About

Easy way to show SRT files on AVPlayerViewController

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 94.7%
  • Ruby 5.3%