How to display subtitles within MPMoviePlayerController

后端 未结 3 2077
刺人心
刺人心 2021-02-09 00:12

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

相关标签:
3条回答
  • 2021-02-09 00:53

    No code needed... AFAIK the button automatically shows up if the soft-subs are encoded in the video.

    See here: http://www.bitfield.se/isubtitle/on_iphone_ipod.html

    0 讨论(0)
  • 2021-02-09 01:17

    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.

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

    0 讨论(0)
  • 2021-02-09 01:17

    If your media file has embedded captions MPMoviePlayerViewController will show a button to enable/disable captions. By default, captions are disabled and can not be activated programatically.

    Instead, you could use AVPlayer with closedCaptionDisplayEnabled property. But only iOS 4+

    0 讨论(0)
提交回复
热议问题