Swiftpack.co - peantunes/SimpleSubtitles as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
peantunes/SimpleSubtitles
A project that allows show subtitles when you don't want to embed it on the HLS files.
.package(url: "https://github.com/peantunes/SimpleSubtitles.git", from: "0.2.0")

Simple Subtitles

Supports tvOS (iOS is in development). If you are looking to use custom WebVTT subtitles without having to change the HLS header files, this is the solution. I have been looking for something like this and I think more people are looking for the same solution.

How to use

Because it is still in development for iOS, I am able to test it very well for Apple TV.

Top menu with the Subtitles menu

If you want to add support to the AppleTV menu use the sample below:

import AVKit
import UIKit
import SimpleSubtitles

class MyPlayerViewController: AVPlayerViewController {
    var subtitlesController: SubtitlesController?
    override func viewDidLoad() {
        let player = AVPlayer(url: URL(string: <<Your video URL>>)!)
        self.player = player
        let languages: [SubtitleLanguage] = [
            .init(id: "1", label: "English", url: "<< your English vtt >>"),
            .init(id: "2", label: "Português (Brasil)", url: "<< your Portuguese vtt >>")
          ]
        subtitlesController = SimpleSubtitles.make(player: player, viewController: self,
                                                   options: .init(timeAdjustForContent: 0.0,
                                                                  languagesAvailable: languages,
                                                                  defaultLanguage: languages.first
                                                   )
        )
        
        player.play()
    }
}

In case to only use the player with the information you have only to set the Language (VTT file) you want to use.

import AVKit
import UIKit
import SimpleSubtitles

class MyPlayerViewController: AVPlayerViewController {
    var subtitlesController: SubtitlesController?
    override func viewDidLoad() {
        let player = AVPlayer(url: URL(string: <<Your video URL>>)!)
        self.player = player
        subtitlesController = SimpleSubtitles.make(player: player, view: view)
        subtitlesController?.setLanguage(url: <<Your WebVTT URL>>)
        
        player.play()
    }
}

If you need to change subtitles later, just call the setLanguage(url: String) and it will load and continue from that point.

Next steps

  • support for iOS
  • support showing subtitles menu on the tvOS standard player

GitHub

link
Stars: 0
Last commit: 3 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

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