简体   繁体   English

使用 AVPlayerViewController 快速显示字幕

[英]Displaying subtitles using AVPlayerViewController with swift

I am new to Swift and video streaming.我是 Swift 和视频流的新手。 I am trying to play videos in AppleTV.我正在尝试在 AppleTV 中播放视频。 Did some one try to add subtitles with AVPlayerViewController in swift from an external srt file.是否有人尝试从外部 srt 文件中快速添加带有 AVPlayerViewController 的字幕。 I am trying to do the same using code from here: https://github.com/mhergon/MPMoviePlayerController-Subtitles .我正在尝试使用这里的代码来做同样的事情: https : //github.com/mhergon/MPMoviePlayerController-Subtitles

I changed the code to suit my requirements, but it is throwing an exception:我更改了代码以满足我的要求,但它抛出了一个异常:

NSInvalidArgumentException', reason: 'Unable to parse constraint format: Unable to interpret '|' NSInvalidArgumentException',原因:'无法解析约束格式:无法解释'|' character, because the related view doesn't have a superview H:|-(20)-[l]-(20)-|字符,因为相关视图没有超视图 H:|-(20)-[l]-(20)-|

At this point in the Subtitles.swift file:此时在 Subtitles.swift 文件中:

var constraints = NSLayoutConstraint.constraintsWithVisualFormat("H:|-(20)-[l]-(20)-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: ["l" : subtitleLabel!])
    subtitleContainer?.addConstraints(constraints)

The error message complains, that there is no superview.错误消息抱怨说,没有超级视图。 Looking at the source I would assume that the container is not properly set.查看来源我会假设容器没有正确设置。 This leads to subtitleLabel not being child of a super view and that makes the constraint fail.这会导致subtitleLabel不是超级视图的子视图,从而导致约束失败。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM