How to display subtitles within MPMoviePlayerController
Asked Answered
W

3

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?

Workhorse answered 21/11, 2011 at 13:46 Comment(1)
No reason to shout!Jojo
L
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).

Lyonnesse answered 21/11, 2011 at 14:17 Comment(3)
Do you have any code for this? I mean how to integrate this python code to MPMoviePlayerConroller code in iOS.Roussillon
@Mason and do you think that was what the poster was referring to?Lyonnesse
@Lyonnesse 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.Comity
D
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+

Denudate answered 21/11, 2011 at 14:15 Comment(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!Wesle
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.Lyonnesse
D
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

Decorticate answered 23/11, 2011 at 3:57 Comment(2)
That demo is for the built-in player, not the one that you get in code when you use MPMoviePlayerControllerUnvoice
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.Comity

© 2022 - 2024 — McMap. All rights reserved.