Search code examples
androidkotlinexoplayerexoplayer2.xexoplayer-media-item

Exoplayer Subtitle


Hi I'm trying to add Subtitle for audio using data of https://grepp-programmers-challenges.s3.ap-northeast-2.amazonaws.com/2020-flo/song.json playing audio and setting the PlayerControlView was fine but dealing with SubtitleView got stuck lyric String

how can I sync and show this String through exoplayer.SubtitleView

I'm using Exoplayer ver 2.18.3


Solution

  • If you have a custom subtitle format, i think you should implement a custom SubtitleDecoder. For example you can check the implementation of SubripDecoder from exoplayer.

    After that, pass your subtitle decoder to the player using the custom implementation of `SubtitleDecoderFactory'.

    class CustomRenderersFactory(context: Context) : DefaultRenderersFactory(context) {
        override fun buildTextRenderers(
            context: Context,
            output: TextOutput,
            outputLooper: Looper,
            extensionRendererMode: Int,
            out: ArrayList<Renderer>
        ) {
            out.add(TextRenderer(output, outputLooper, CustomSubtitleDecoderFactory()))
        }
    }
    

    Now just add a subtitle track to your MediaItem/MediaSource