Question:
How do I add an external WebVTT file to my AVPlayer in tvOS?
Description:
I've been watching this "What's New in HTTP Live Streaming" by Apple where they talk about different ways in implementing an external WebVTT file.
The whole subtitle domain is quite new to me, so I'm having hard time grasping the concept quite well. Within the video they talk about many different things which I do not quite understand such as ( Subtitle playlist ). However, getting passed all that my main concern is adding .vtt file to my AVPlayer.
In the video they talk about this AVMediaSelectionGroup()
but I'm quite confused on how to use and how to implement this with my AVPlayerViewController
:
class PlayerViewController: AVPlayerViewController {
override func viewDidLoad() {
self.setupVideoPlayerView()
}
private func setupVideoPlayerView()
{
let path = "https://link.to.my.video.mp4"
let subTitlePath = "https://link.to.my.webvtt.file.vtt"
let nsURL = URL(string: path)
let avPlayer = AVPlayer(url: nsURL!)
self.player = avPlayer
self.player!.seek(to: kCMTimeZero)
self.player!.play()
}
}
The AVMediaSelectionGroup
doesn't seem to have any methods to add a subtitle? The closest thing I was able to find (that mentioned subtitles) are the following methods:
//Where self is the instance of AVPlayerViewController
self.allowedSubtitleOptionLanguages
self.requiresFullSubtitles