How use app closedcaption settings instead of syst

2019-08-21 04:54发布

问题:

In my application i have closed caption settings and i am using AVPLayer to play video/live content without showing default controls. In my app i can able or disable closed captions like switch based on that switch status i am storing BOOL value in userdefaults. Based on userdefaults i am trying to enable or disable cc for avplayer using below api.

[self.player setClosedCaptionDisplayEnabled:enable];

Now problem is Even if i off cc in app but iphone system settings cc enabled that time i am getting cc in avplayer. If i off system cc then my app settings are effecting in avplayer.

Can you please suggest is there any way to bypass system settings for avplayer. If cannot can you please provide apple document link to show as a proof to clinet that we cannot do this like that.

回答1:

You should set

self.player.appliesMediaSelectionCriteriaAutomatically = FALSE;

Instead of this, which is deprecated.

[self.player setClosedCaptionDisplayEnabled:enable];

By default, AVPlayer applies selection criteria based on system preferences. To override the default criteria for any media selection group, use -[AVPlayer setMediaSelectionCriteria:forMediaCharacteristic:].

EDIT

This method will be used:

@method setMediaSelectionCriteria:forMediaCharacteristic:

@abstract Applies automatic selection criteria for media that has the specified media characteristic.

@param criteria An instance of AVPlayerMediaSelectionCriteria.

@param mediaCharacteristic The media characteristic for which the selection criteria are to be applied. Supported values include AVMediaCharacteristicAudible, AVMediaCharacteristicLegible, and AVMediaCharacteristicVisual.

@discussion Criteria will be applied to an AVPlayerItem when:

a) It is made ready to play

b) Specific media selections are made by -[AVPlayerItem selectMediaOption:inMediaSelectionGroup:] in a different group. The automatic choice in one group may be influenced by a specific selection in another group.

c) Underlying system preferences change, e.g. system language, accessibility captions.

Specific selections made by -[AVPlayerItem selectMediaOption:inMediaSelectionGroup:] within any group will override automatic selection in that group until -[AVPlayerItem selectMediaOptionAutomaticallyInMediaSelectionGroup:] is received.

  • (void)setMediaSelectionCriteria:(nullable AVPlayerMediaSelectionCriteria *)criteria forMediaCharacteristic:(AVMediaCharacteristic)mediaCharacteristic NS_AVAILABLE(10_9, 7_0);

Documentation for the same is here