2

I downloaded an YouTube video which had subtitles. I uploaded it on my platform and when I stream the video I don't subtitles.

AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:url options:nil];
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:avAsset];
AVMediaSelectionGroup* subtitle = [avAsset mediaSelectionGroupForMediaCharacteristic:AVMediaCharacteristicLegible];
[playerItem selectMediaOption:subtitle.options[0] inMediaSelectionGroup:subtitle];

The value of variable 'subtitle' is nil.

Is there something wrong with the code or the video has to be configured differently?

A_G
  • 2,260
  • 3
  • 23
  • 56

1 Answers1

0

This amazing SO answer explains the way AVPlayer handles subtitles.

You will need to either "burn" the subbitles in to the video using some video editing software or create .vtt files and include them in the mast playlist (.m3u8) file. Then using the code you have pasted above you should be able to toggle the captions on or off.

rorschach
  • 61
  • 5