androidexoplayersubtitle

How to show embedded subtitles in ExoPlayer?


I know that i can show external subtitles (i.e. which are stored in a separate file) in ExoPlayer in the following way:

val subsConf = SubtitleConfiguration
    .Builder(subsUri)
    .setMimeType(MimeTypes.APPLICATION_SUBRIP)
    .setSelectionFlags(C.SELECTION_FLAG_DEFAULT)
    .build()

val mediaItem = MediaItem.Builder()
    .setUri(videoUri)
    .setSubtitleConfigurations(ImmutableList.of(subsConf))
    .build()

exoPlayer.setMediaItems(listOf(mediaItem), 0, 0)
exoPlayer.prepare()

But what if my videoUri points to a file which already has embedded subtitles. How to turn them on ?


Solution

  • This is posible by using "track selection" parameters. Documentation is available here.

    In short there can be multiple tracks for video, audio and text (subtitles). You can selected preferred track using TrackSelectionParameters. You can also get list of tracks by using player.getCurrentTracks() and show them to user to be able to select any track.