Swiftpack.co - mhergon/AVPlayerViewController-Subtitles as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by mhergon.
mhergon/AVPlayerViewController-Subtitles v1.3.2
Easy way to show SRT files on AVPlayerViewController
⭐️ 198
🕓 2 weeks ago
iOS tvOS
.package(url: "https://github.com/mhergon/AVPlayerViewController-Subtitles.git", from: "v1.3.2")

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.3.x Swift 5.0 iOS 8
1.2.x Swift 3.0 iOS 8
1.0.x Swift 2.x iOS 8

Usage with player

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

Screenshoot

Usage without player

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

import AVPlayerViewControllerSubtitles
// 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.
Copyright 2017 Marc Hervera.

GitHub

link
Stars: 198
Last commit: 2 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

Swift 5 & some updates
13 weeks ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics