How to implement subtitles using .srt file with avplayer in iOS. When using the avplayer is there a way to use .srt file in avplayer to show the subtitle on the player
Asked
Active
Viewed 3,192 times
4
-
1How to ask questions: https://stackoverflow.com/help/how-to-ask and https://stackoverflow.com/help/minimal-reproducible-example – Magnas Jul 31 '20 at 06:42
1 Answers
3
You can't just put .srt file in your AVPlayer and show them. If you can put subtitles inside your .m3u8 HLS stream on server side - this will be the solution to handle subtitles by AVPLayer automatically.
Until then - I'm using this library
Very simple to use and is handling all for you.

Pete Streem
- 360
- 5
- 14
-
Thanks. This is working only for avplayerviewcontroller but our requirement is show the subtitle over the AVPlayer. how can get player.addSubtitles() – Alok Kumar Aug 04 '20 at 11:38
-
2@AlokKumar I'm also using just AVPlayer with this library. If you have a class, for example VideoPlayer.swift and there is your AVPlayer item, the best way is to make extension like VideoPlayer+Subtitles.swift - https://codeshare.io/anyENY . And then call it like here - https://codeshare.io/5go7NB from you VideoPlayer.swift class. – Pete Streem Aug 04 '20 at 22:17
-
Sorry for such a mess comment. If you won't deal with that - I'll update my original answer. – Pete Streem Aug 04 '20 at 22:17
-
1@AlokKumar Also, don't forget about periodic time observer. I hope you already implemented it. If not - https://codeshare.io/2E8gbv – Pete Streem Aug 04 '20 at 22:19
-
1AHHHHHHHHHHHHHHHHH OMG. I have been on a project FOR WEEKS. Trying to find a way to control captions that come separately from video files. Your additional codeshares were very helpful to someone with purely SwiftUI experience. This post is like gold to me. Thank you. – Alex Hartford Dec 03 '21 at 23:09
-
@AlexHartford do you think you could share that SwiftUI implementation? – Jordi Bruin Dec 30 '21 at 17:37
-
1@JordiBruin 95% of my implementation came from adaptations of the codeshares posted by Pete. – Alex Hartford Jan 03 '22 at 15:55
-
@PeteStreem if i use this library in my app can i upload my app on app store? – Amin Rezaew Apr 25 '22 at 19:28
-
@AlexHartford if i use this library in my app can i upload my app on app store? – Amin Rezaew Apr 26 '22 at 09:42
-
1