Search code examples
iosavplayerclosed-captions

How to enable/disable device wise closed caption settings on iOS?


When the accessibility option is turned on the device, we're not able to turn off the closed caption by setting the closedCaptionEnabled option for the AVPlayer instance as we normally would. Is there a way to bypass such option or even to test if it's enabled to lock the CC button if necessary?


Solution

  • You can iterate through each AVPlayerItemTrack and enable/disable it as you wish.

    This is how I do in one of my project. I show table of available CC tracks and when the user selects one I iterate through each track, enable the on that user selected and disable rest.

        //_selectedTrackIndex = userSelectedIndex;
        -(void) setSelectedTrackEnabled {
            for (AVPlayerItemTrack * t in [_playerItem tracks]) {
                if (counter == _selectedTrackIndex) {
                    [t setEnabled:YES];
                } else {
                    [t setEnabled:NO];
                }
            }
        }