Skip to content

Instantly share code, notes, and snippets.

@helbertgs
Created October 7, 2020 21:29
Show Gist options
  • Save helbertgs/cc5d08b4119f4b77d23976c9a95a18d0 to your computer and use it in GitHub Desktop.
Save helbertgs/cc5d08b4119f4b77d23976c9a95a18d0 to your computer and use it in GitHub Desktop.
import Clappr
import UIKit
class UIPlaybackTypePlugin: UICorePlugin {
override class var name: String { "UIPlaybackTypePlugin" }
private var label: UILabel = {
let label = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false
label.textColor = .white
label.font = UIFont.systemFont(ofSize: 28, weight: .heavy)
label.textAlignment = .right
return label
}()
@available(*, unavailable)
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
required init(context: UIObject) {
super.init(context: context)
}
override func bindEvents() {
guard let playback = core?.activePlayback else { return }
listenTo(playback, event: .assetReady) { [weak self] _ in
switch playback.playbackType {
case .live:
self?.label.text = "Live"
case .vod:
self?.label.text = "VoD"
case .unknown:
self?.label.text = "Desconhecido"
}
}
}
override func render() {
setup()
}
private func setup() {
guard let superview = core?.view else { return }
superview.addSubview(label)
label.rightAnchor.constraint(equalTo: superview.rightAnchor, constant: -32).isActive = true
label.topAnchor.constraint(equalTo: superview.topAnchor, constant: 32).isActive = true
label.widthAnchor.constraint(equalToConstant: 200).isActive = true
label.heightAnchor.constraint(equalToConstant: 24).isActive = true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment