Latest 0.0.1
Homepage https://github.com/SeunghoHong/ExSubtitle
License MIT
Platforms ios 8.0, requires ARC
Authors

title: ExSubtitle
date:
version: 0.0.1

Overview

ExSubtitle provides interface for external subtitle that is not supported by AVPlayer.

  • parses an external subtitle with source
  • notifies a timed text and additional information based on the playback position of AVPlayer

Supported format

  • TTML (application/xml+ttml, application/ttml+xml)
  • WebVTT (text/vtt)
  • SRT (application/x-subrip)
  • SMI (application/smil+xml)
  • ASS (application/x-ass)

Interface definition

ExSubtitle

Constants

Mimetype

Constants that describe types of subtitle.

enum MimeType {
    case smi, srt, ass, vtt, ttml
}
Name Description
ttml TimedTextMarkupLanguage
vtt WebVTT
srt SubRip
smi SAMI
ass SubStationAlpha

Methods

init(player:)

Applicaton should create the ExSubtitle instance with an AVPlayer.

Declaration:

init(player: AVPlayer)

Parameters:

Name Description
player AVPlayer

Example:

var asset = AVAsset(url: url)
var playerItem = AVPlayerItem(asset: asset)
var player = AVPlayer(playerItem: playerItem)

var exSubtitle = ExSubtitle(player: player)

parse(from:mimetype:)

Applicaton should get the subtitle data and mimtype from the file or url resource.

Declaration:

func parse(from data: Data, mimetype: MimeType)

Parameters:

Name Description
onCue No description.

// TODO: error handling

Example:

self.exSubtitle.parse(from: data, mimetype: .ttml)

setOnCue(_:)

ExSubtitle notities the timed text and information as Cue class via onCue listener.

Declaration:

func setOnCue(_ onCue: @escaping ((Cue) -> Void))

Parameters:

Name Description
onCue No description.

Example:

self.exSubtitle.setOnCue {
    $0.payloads.forEach {
        print("($0.text)")
    }
}

Cue

Properties

start

Declaration

var start: CMTime
end

Declaration

var end: CMTime
payloads

Declaration

typealias Styles = (region: Style?, style: Style?)
typealias Payload = (text: String, setting: String?, styles: Styles?)

var payloads: [Payload]

Latest podspec

{
    "name": "ExSubtitle",
    "version": "0.0.1",
    "summary": "Supported external subtitle for AVPlayer",
    "description": "parses an external subtitle with data.nnotifies a timed text and additional information based on the playback position of AVPlayer.",
    "homepage": "https://github.com/SeunghoHong/ExSubtitle",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Seungho Hong": "[email protected]"
    },
    "platforms": {
        "ios": "8.0"
    },
    "swift_version": "4.2",
    "source": {
        "git": "https://github.com/SeunghoHong/ExSubtitle.git",
        "tag": "0.0.1"
    },
    "source_files": "ExSubtitle/**/*.swift",
    "requires_arc": true
}

Pin It on Pinterest

Share This