8

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?

Josh Brown
  • 52,385
  • 10
  • 54
  • 80
user722056
  • 101
  • 1
  • 5

3 Answers3

4

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

Community
  • 1
  • 1
jbat100
  • 16,757
  • 4
  • 45
  • 70
  • 1
    Do you have any code for this? I mean how to integrate this python code to MPMoviePlayerConroller code in iOS. – Mrunal Nov 21 '11 at 15:20
  • 1
    @Mason and do you think that was what the poster was referring to? – jbat100 Oct 23 '12 at 09:56
  • 1
    @jbat100 After re-reading the original question I see that I was wrong, and will undo the down vote when SO allows it in a few hours. My apologies. – Mason G. Zhwiti Oct 23 '12 at 14:00
2

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+

javieralog
  • 1,337
  • 9
  • 10
  • 2
    Does 'closedCaptionDisplayEnabled' turn on/off the soft-subtitle embedded in the video file? What if the file has multiple subtitle tracks, can I choose between, for example, english or french programmatically? The documentation says almost nothing, any help you can provide is greatly appreciated. Thanks! – Joseph Lin Jan 17 '12 at 16:11
  • 1
    Note that closed caption are different in that they are imbedded in the video stream (and require demuxing) while subtitles are a separate file, or separate stream. – jbat100 Oct 23 '12 at 19:12
2

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

J.R.
  • 199
  • 1
  • 2
  • 1
    That demo is for the built-in player, not the one that you get in code when you use MPMoviePlayerController – Jess Bowers Apr 11 '12 at 21:51
  • This may have changed, but in iOS 6, if the app is showing the video in full/wide screen, the CC button appears there as well. Though it would be nice if the CC could be enabled by the app itself. – Mason G. Zhwiti Oct 23 '12 at 07:30