Programmatically change background color subtitles in AVPlayer

Hello,


I work with HLS streams with webvtt subtitles in the main playlist. I create an AVPlayer object and I want to overide the default style for my subtitles, so I create a AVTextStyleRule.


let textStyle:AVTextStyleRule = AVTextStyleRule(textMarkupAttributes: [
     kCMTextMarkupAttribute_CharacterEdgeStyle as String: kCMTextMarkupCharacterEdgeStyle_DropShadow,
     kCMTextMarkupAttribute_BackgroundColorARGB as String: [0.0,0.0,0.0,0.0]
     kCMTextMarkupAttribute_BaseFontSizePercentageRelativeToVideoHeight as String: 5.5,
])!


it works fine for edge style and for font size, but it's like opacity for "BackgroundColorARGB" attribute doesn't work in swift 2.0.

For example, if I put :

[0.0,1.0,0.0,0.0]

as value for :

kCMTextMarkupAttribute_BackgroundColorARGB

I obtain a red background with 50% of opacity. If I change opacity to 1.0, I also obtain a red background with 50% of opacity.


Is it a bug in swift 2.0 or can I change opacity with another attribute ?


thanks,

nobody ?

Are these followed?


@const kCMTextMarkupAttribute_BackgroundColorARGB

@abstract The background color for the shape holding the text.


@discussion Value must be a CFArray of 4 CFNumbers representing alpha, red, green, and blue fields with values between 0.0 and 1.0. The

red, green and blue components are interpreted in the sRGB color space. The alpha indicates the opacity from 0.0 for transparent to

1.0 for 100% opaque.

The color applies to the geometry (e.g., a box) containing the text. The container's background color may have an

alpha of 0 so it is not displayed even though the text is displayed. The color behind individual characters

is optionally controllable with the kCMTextMarkupAttribute_CharacterBackgroundColorARGB attribute.


If used, this attribute must be applied to the entire attributed string (i.e.,

CFRangeMake(0, CFAttributedStringGetLength(...))).


-=-


If so, do an option-clean build folder and try again.

I tried doing this via a helper method written in Objective-C, the rest of the code being in Swift. Did not work either.

I cannot change the font, nor the alpha of the background color.

I seem to have the same issue. By any chance, did you manage to solve it?

iOS Settings -> General -> Accessibility -> (Media) Subtitles & Captioning -> Style -> Create New Style... -> (Background) Opacity -> Turn On `Video Override`


I think the user must turn on the above setting by himself to make your code work.

The default settings of `Video Override` for Background Color is ON, so you can change it to RED.

But the default setting of `Video Override` for Background Opacity is OFF, so you cannot modify it.

Programmatically change background color subtitles in AVPlayer
 
 
Q