SubtitleView
@UnstableApi
public final class SubtitleView extends FrameLayout
| java.lang.Object | ||||
| ↳ | android.view.View | |||
| ↳ | android.view.ViewGroup | |||
| ↳ | android.widget.FrameLayout | |||
| ↳ | androidx.media3.ui.SubtitleView |
A view for displaying subtitle Cues.
Summary
Nested types |
|---|
@DocumentedThe type of |
Constants |
|
|---|---|
static final float |
DEFAULT_BOTTOM_PADDING_FRACTION = 0.08fThe default bottom padding to apply when |
static final float |
DEFAULT_TEXT_SIZE_FRACTION = 0.0533fThe default fractional text size. |
static final int |
VIEW_TYPE_CANVAS = 1Indicates subtitles should be displayed using a |
static final int |
VIEW_TYPE_WEB = 2Indicates subtitles should be displayed using a |
Public constructors |
|---|
SubtitleView(Context context) |
SubtitleView(Context context, @Nullable AttributeSet attrs) |
Public methods |
|
|---|---|
void |
setApplyEmbeddedFontSizes(boolean applyEmbeddedFontSizes)Sets whether font sizes embedded within the cues should be applied. |
void |
setApplyEmbeddedStyles(boolean applyEmbeddedStyles)Sets whether styling embedded within the cues should be applied. |
void |
setBottomPaddingFraction(float bottomPaddingFraction)Sets the bottom padding fraction to apply when |
void |
Sets the cues to be displayed by the view. |
void |
setFixedTextSize(@Dimension int unit, float size)Sets the text size to a given unit and value. |
void |
setFractionalTextSize(float fractionOfHeight)Sets the text size to be a fraction of the view's remaining height after its top and bottom padding have been subtracted. |
void |
setFractionalTextSize(float fractionOfHeight, boolean ignorePadding)Sets the text size to be a fraction of the height of this view. |
void |
setStyle(CaptionStyleCompat style)Sets the caption style. |
void |
Styles the captions using |
void |
Sets the text size based on |
void |
setViewType(@SubtitleView.ViewType int viewType)Sets the type of |
Inherited Constants |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Inherited methods |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Constants
DEFAULT_BOTTOM_PADDING_FRACTION
public static final float DEFAULT_BOTTOM_PADDING_FRACTION = 0.08f
The default bottom padding to apply when line is DIMEN_UNSET, as a fraction of the viewport height.
| See also | |
|---|---|
setBottomPaddingFraction |
DEFAULT_TEXT_SIZE_FRACTION
public static final float DEFAULT_TEXT_SIZE_FRACTION = 0.0533f
The default fractional text size.
| See also | |
|---|---|
setFractionalTextSize |
VIEW_TYPE_CANVAS
public static final int VIEW_TYPE_CANVAS = 1
Indicates subtitles should be displayed using a Canvas. This is the default.
VIEW_TYPE_WEB
public static final int VIEW_TYPE_WEB = 2
Indicates subtitles should be displayed using a WebView.
This will use CSS and HTML styling to render the subtitles. This supports some additional styling features beyond those supported by VIEW_TYPE_CANVAS such as vertical text.
Public constructors
Public methods
setApplyEmbeddedFontSizes
public void setApplyEmbeddedFontSizes(boolean applyEmbeddedFontSizes)
Sets whether font sizes embedded within the cues should be applied. Enabled by default. Only takes effect if setApplyEmbeddedStyles is set to true.
| Parameters | |
|---|---|
boolean applyEmbeddedFontSizes |
Whether font sizes embedded within the cues should be applied. |
setApplyEmbeddedStyles
public void setApplyEmbeddedStyles(boolean applyEmbeddedStyles)
Sets whether styling embedded within the cues should be applied. Enabled by default. Overrides any setting made with setApplyEmbeddedFontSizes.
| Parameters | |
|---|---|
boolean applyEmbeddedStyles |
Whether styling embedded within the cues should be applied. |
setBottomPaddingFraction
public void setBottomPaddingFraction(float bottomPaddingFraction)
Sets the bottom padding fraction to apply when line is DIMEN_UNSET, as a fraction of the view's remaining height after its top and bottom padding have been subtracted.
Note that this padding is applied in addition to any standard view padding.
| Parameters | |
|---|---|
float bottomPaddingFraction |
The bottom padding fraction. |
setFixedTextSize
public void setFixedTextSize(@Dimension int unit, float size)
Sets the text size to a given unit and value.
See TypedValue for the possible dimension units.
| Parameters | |
|---|---|
@Dimension int unit |
The desired dimension unit. |
float size |
The desired size in the given units. |
setFractionalTextSize
public void setFractionalTextSize(float fractionOfHeight)
Sets the text size to be a fraction of the view's remaining height after its top and bottom padding have been subtracted.
Equivalent to #setFractionalTextSize(fractionOfHeight, false).
| Parameters | |
|---|---|
float fractionOfHeight |
A fraction between 0 and 1. |
setFractionalTextSize
public void setFractionalTextSize(float fractionOfHeight, boolean ignorePadding)
Sets the text size to be a fraction of the height of this view.
| Parameters | |
|---|---|
float fractionOfHeight |
A fraction between 0 and 1. |
boolean ignorePadding |
Set to true if |
setStyle
public void setStyle(CaptionStyleCompat style)
Sets the caption style.
| Parameters | |
|---|---|
CaptionStyleCompat style |
A style for the view. |
setUserDefaultStyle
public void setUserDefaultStyle()
Styles the captions using getUserStyle if CaptioningManager is available and enabled.
Otherwise (and always before API level 19) uses a default style.
setUserDefaultTextSize
public void setUserDefaultTextSize()
Sets the text size based on getFontScale if CaptioningManager is available and enabled.
Otherwise (and always before API level 19) uses a default font scale of 1.0.
setViewType
public void setViewType(@SubtitleView.ViewType int viewType)
Sets the type of View used to display subtitles.
NOTE: VIEW_TYPE_WEB is currently very experimental, and doesn't support most styling and layout properties of Cue.
| Parameters | |
|---|---|
@SubtitleView.ViewType int viewType |
The |