ExoPlayer
ExoPlayer copied to clipboard
SubtitleView more options for CaptionStyleCompat
Missing outlineWidth option
Currently I am trying to add subtitle options into my app, however I am missing the option to set the outline width as CaptionStyleCompat does not include it. It looks like SubtitlePainter sets these to Math.round((2f * displayMetrics.densityDpi) / DisplayMetrics.DENSITY_DEFAULT);
and has no options to change it in runtime.
Proposed solution
Simply add outlineWidth/shadowRadius/shadowOffset as an option in CaptionStyleCompat and use those in SubtitlePainter.
Alternatives considered
Remove final from SubtitleView and SubtitlePainter so users can override specific parts.
Possible duplicate of #9391
CaptionStyleCompat
contains the same properties as android.view.accessibility.CaptioningManager.CaptionStyle
. These are also the same properties that an end-user can customise.
I'm afraid we won't be adding additional properties to this class.
Remove final from SubtitleView and SubtitlePainter so users can override specific parts.
These classes are not designed for to be inherited from, so it's deliberately forbidden. See Item 19 of Effective Java 3rd Edition: "Design and document for inheritance or else prohibit it".
I think the 'right' way to support customising this property of subtitles is to add it to Cue
(either as a cue-level property, or a (possibly custom) styling span inside Cue.text
) and update SubtitlePainter
to respect this property (in the same way it considers e.g. the foreground color from both Cue
and CaptionStyleCompat
). This would be done as part of #9391 (in addition to parsing it from the TTML source file).
If this was done, you could then either use TTML subtitles to get support for this property, or mutate Cue
objects before they're displayed on the screen to set this property, as described in https://github.com/google/ExoPlayer/issues/7243#issuecomment-614651130.
Given this is a subset of the work required for #9391, I'm going to mark it as a duplicate.