Swiftpack.co - peantunes/SimpleSubtitles as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by peantunes.
peantunes/SimpleSubtitles 0.2.0
A project that allows show subtitles when you don't want to embed it on the HLS files.
⭐️ 6
🕓 2 years ago
iOS tvOS
.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: 6
Last commit: 1 year ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

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