如何在MPMoviePlayerController中显示字幕 [英] How to display subtitles within MPMoviePlayerController
问题描述
我制作了一个自定义视频播放器,所有按钮都正常工作。我需要知道当视频具有该选项时MPMoviePlayerController显示字幕的代码是什么。我没有找到任何一个例子或者知道这个字幕按钮背后的代码的人。我在哪里可以找到这个?
I built a custom video player, all buttons are working. I need to know what is the code that does the MPMoviePlayerController display subtitles when the video has that option. I did not find anywhere an example or someone who knew what code is behind this subtitle button. Where can I find this?
推荐答案
您必须实现自己的字幕文件解析器。 .srt文件格式非常简单,此处是关于如何解析它的讨论。
You will have to implement your own subtitle file parser. The .srt file format is quite simple, here is a discussion about how to parse it.
更具挑战性的一点是然后同步字幕显示(可能只是 UILabel
放在 MPMoviePlayerController
view),包含当前的电影时间。您应该编写一个类,您可以要求 subtitleStringAtTimeInterval
:类似的东西(它将字幕保留在内存中并使字幕提取更快)。然后定期更新字幕(使用 NSTimer
或在每个字幕更新之间短时间间隔休眠的后台线程)。
The more challenging bit is to then synchronize the subtitle display (probably just a UILabel
placed on top of the MPMoviePlayerController
view), with the current movie time. You should write a class which you can ask for subtitleStringAtTimeInterval
: kind of thing (which keeps the subtitles in memory and makes subtitle fetching faster). Then update the subtitles at regular intervals (with NSTimer
or a background thread which sleeps for a short time interval between each subtitle update).
这篇关于如何在MPMoviePlayerController中显示字幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!