Customising the Captions - devrath/MediaAlchemySuite GitHub Wiki

There are some options

1. Font Size

Control the text size using setFixedTextSize or setFractionalTextSize:

subtitleView?.setFractionalTextSize(SubtitleView.DEFAULT_TEXT_SIZE_FRACTION) // default is 0.053f
// or
subtitleView?.setFixedTextSize(TypedValue.COMPLEX_UNIT_SP, 16f) // set absolute size

2. Text Alignment

Align captions (not always useful for all formats):

subtitleView?.setTextAlignment(Layout.Alignment.ALIGN_CENTER)

3. Bottom Padding

Adjust padding from the bottom of the screen:

subtitleView?.setBottomPaddingFraction(0.08f) // range: 0.0f to 1.0f

4. Visibility

Manually show/hide subtitles:

subtitleView?.visibility = View.VISIBLE // or View.GONE

5. Cue Line Spacing (Advanced – in custom view)

If you override SubtitleView, you can customize line spacing between cues using:

subtitleView?.setLineSpacing(spacingExtra: Float, spacingMultiplier: Float)

🧩 Code

import android.graphics.Color

private fun preparePlayerView(
    context: Context,
    controller: MediaController?
): PlayerView = PlayerView(context).apply {
    player = controller
    layoutParams = ViewGroup.LayoutParams(
        ViewGroup.LayoutParams.MATCH_PARENT,
        ViewGroup.LayoutParams.WRAP_CONTENT
    )
    useController = true
    subtitleView?.apply {
        setStyle(
            CaptionStyleCompat(
                Color.WHITE,
                Color.BLACK,
                Color.TRANSPARENT,
                CaptionStyleCompat.EDGE_TYPE_OUTLINE,
                Color.BLACK,
                Typeface.DEFAULT_BOLD
            )
        )
        setFractionalTextSize(0.06f)
        setFixedTextSize(TypedValue.COMPLEX_UNIT_SP, 12f)
        setBottomPaddingFraction(0.1f)
        subtitleView?.visibility = View.VISIBLE
        textAlignment = View.TEXT_ALIGNMENT_INHERIT
    }
}