5

I'm creating custom video player, and i want to create toggle button for CC.

I saw this post : IOS AVPlayer cannot disable closed captions

So I tried :

AVMediaSelectionGroup *group = [self.avPlayer.currentItem.asset mediaSelectionGroupForMediaCharacteristic:AVMediaCharacteristicLegible];

[self.avPlayer.currentItem  selectMediaOption:nil inMediaSelectionGroup:group];

Didn't work.. cc still visible.

also tried :

AVPlayerItemLegibleOutput *output = [[AVPlayerItemLegibleOutput alloc] init];
[output setDelegate:self queue:dispatch_get_main_queue()];
[output setSuppressesPlayerRendering:true];
[self.avPlayer.currentItem addOutput:output];

It's hide the the cc, but how can I unhide them? ,I tried:

[output setSuppressesPlayerRendering:true];

but the cc freeze on the screen.

thanks!

Maor
  • 3,340
  • 3
  • 29
  • 38

1 Answers1

3

Objective C: This one works for me. Even I wanted to do the same thing.

To off subtitles

AVMediaSelectionGroup *subtitleSelectionGroup = [_playerItem.asset mediaSelectionGroupForMediaCharacteristic:AVMediaCharacteristicLegible];
              
[_playerItem selectMediaOption:NULL inMediaSelectionGroup:subtitleSelectionGroup];

To show it again I do this:

AVMediaSelectionOption* option = [subtitleSelectionGroup.options objectAtIndex:subtitleIndex-1]; // I did -1 because OFF was 0 for my case 
         
[_playerItem selectMediaOption:option inMediaSelectionGroup:subtitleSelectionGroup];
   
Emin A. Alekperov
  • 1,067
  • 1
  • 16
  • 26