ExoPlayer icon indicating copy to clipboard operation
ExoPlayer copied to clipboard

System caption style background being used when cue style is provided.

Open BetweenTwoBits opened this issue 8 years ago • 6 comments

Issue description

When using a CaptionManager defined caption style, SubtitleView will show the system style background behind the caption style data that is part of the cue. This can lead to blue bars showing next to the captions. Ex: elephants_dream_captions

Reproduction steps

Set system caption options:

  • Accessibility->Captions->On->Caption style->Yellow on blue
  • Playing the asset in the linked test content.

Link to test content

http://rdmedia.bbc.co.uk/dash/ondemand/elephants_dream/1/client_manifest-all.mpd

Version of ExoPlayer being used

2.7.2

Device(s) and version(s) of Android being used

Pixel C, Android 8.1.0

A full bug report captured from the device

N/A

BetweenTwoBits avatar Apr 03 '18 21:04 BetweenTwoBits

Seems like setting backgroundColor in SubtitlePainter.java to the cue's windowColor (when windowColorSet) gives the expected result, but I'm not sure thats the right fix. I'm assuming the better option would be to add a backgroundColor field to the Cue class would be a better solution.

BetweenTwoBits avatar Apr 03 '18 21:04 BetweenTwoBits

Looking at the issue, I think it's actually a duplicate of #2824 (just that here it's blue instead of transparent).

Besides that, it's certainly unfortunate to combine the embedded background style with the system window style. Your pull request looks like it solves the issue, but I'll wait for @ojw28 to take a look. He's currently unavailable, so this may take some weeks.

tonihei avatar May 14 '18 13:05 tonihei

Thanks for the reply. It does appear to be a duplicate of part 2 of that issue.

BetweenTwoBits avatar May 14 '18 19:05 BetweenTwoBits

The problem here is that we handle the text background color in different ways depending on where it came from:

  1. If it's specified in the CaptionStyleCompat then it gets drawn by a canvas.drawRoundRect call in SubtitlePainter.
  2. If it's embedded in the media then we use BackgroundColorSpan to specify the color. It gets drawn by a layout.draw(canvas) call in SubtitlePainter. Note that a background color may apply to only part of the Cue when it's specified in this way, and a single Cue may have multiple BackgroundColorSpans attached to it.

If background colors are specified by both CaptionStyleCompat and the media, we paint all of them. There are a few issues with this:

  1. The former draws a box that's a bit wider (and a slightly different shape) than the latter, which is why the issue arises in the example shown above.
  2. If the embedded style specifies a semi-transparent background color, the color specified by the CaptionStyleCompat will still be painted underneath, which is probably not correct. This would still be an issue even if the shapes painted by the two approaches were fixed to be identical.

The solution proposed in https://github.com/google/ExoPlayer/pull/4244 appears to allow a Cue to explicitly carry a text background color, which is then used in the first step above. Unfortunately I don't think this is a suitable solution for all cases. The cue captured in the screenshot above is specified in TTML as:

<span style="s2">Listen Proog! Do you hear that?<br/></span>
<span style="s1">AMUSEMENT PARK MUSIC</span>

Where s1 and s2 defined different background colors. Hence there is no single background color that can be sensibly set on the corresponding Cue. It also doesn't fix the second issue mentioned above.

I think the correct fix is to modify SubtitlePainter only, so that it (a) paints all backgrounds using a single approach, and (b) does not paint the CaptionStyleCompat specified background color for portions of the Cue that have a BackgroundColorSpan set on them from the media. Note that (b) fixes the transparency issue.

I think the easiest way to do this is likely to be by adding extra BackgroundColorSpans to the cue text, that don't overlap any already defined spans, and which specify the CaptionStyleCompat color.

ojw28 avatar Jun 05 '18 16:06 ojw28

Thank you for the detailed breakdown, that makes total sense. I'll put some work into this and edit my PR!

BetweenTwoBits avatar Jun 05 '18 16:06 BetweenTwoBits

No worries, and thanks! Note that I think you can fix the issue by modifying SubtitlePainter only. If you're still finding yourself touching other classes then it's probably worth discussing further, since I don't think it's necessary to do so.

ojw28 avatar Jun 05 '18 16:06 ojw28