如何将外部 .vtt 字幕文件添加到 tvOS 中的 AVPlayerViewController [英] How to add external .vtt subtitle file to AVPlayerViewController in tvOS

查看:39
本文介绍了如何将外部 .vtt 字幕文件添加到 tvOS 中的 AVPlayerViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 tvOS 中将外部 WebVTT 文件添加到我的 AVPlayer?

How do I add an external WebVTT file to my AVPlayer in tvOS?

我一直在观看 Apple 的这个HTTP 实时流媒体的新功能" 他们讨论了实现外部 WebVTT 文件的不同方法.

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.

整个字幕领域对我来说都很陌生,所以我很难很好地掌握这个概念.在视频中,他们谈论了许多我不太了解的不同事物,例如(字幕播放列表).然而,我主要关心的是将 .vtt 文件添加到我的 AVPlayer.

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.

在视频中他们谈到了这个 AVMediaSelectionGroup() 但我对如何使用以及如何使用我的 AVPlayerViewController 实现这一点感到非常困惑:

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()

    }
}

AVMediaSelectionGroup 似乎没有任何添加字幕的方法?我能找到的最接近的东西(提到的字幕)是以下方法:

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

推荐答案

虽然在苹果文档中几乎没有提到它,但我在一篇文章中看到字幕需要嵌入 HLS 流.

While it was almost mentioned no where in the apple documentation, I read in an article that subtitles need to be embedded in the HLS stream.

字幕不打算手动添加..虽然我确实找到了一个 StackOverflow 帖子显示了一个黑客.不确定它是否有效.

Subtitles are not intended to be added manually.. though I did find a StackOverflow post showing a hack. Unsure if it works or not.

看到我使用的是 VIMEO Pro,提供的 HLS 流嵌入了 WebVTT 字幕(我上传到 vimeo),从而解决了我的问题.

Seeing that I use VIMEO Pro, the HLS stream that is provided has the WebVTT subtitles (that I uploaded to vimeo) embedded, thus solving my problem.

这篇关于如何将外部 .vtt 字幕文件添加到 tvOS 中的 AVPlayerViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆