Skip to main content
Logo Appt Light

Live captions on Android

Captions should be provided in real-time to enable users to understand what is being said in live videos. The challenge with live captions is both organizational and technical. A captioner must be present who can provide live captions for the video by using suitable software.

On Android, we recommend using a library such as ExoPlayer to support live captions. ExoPlayer is developed by Google and is an open-source alternative to Android's MediaPlayer for audio and video playback. Many code examples can be found in the ExoPlayer documentation. You can use DefaultTrackSelector in combination with DefaultHttpDataSourceFactory to show subtitles.

val trackSelector = DefaultTrackSelector(baseContext)
trackSelector.setParameters(
    trackSelector.buildUponParameters().setPreferredTextLanguage("nl")
)
val exoPlayer = SimpleExoPlayer.Builder(baseContext)
                    .setTrackSelector(trackSelector)
                    .build()
val dataSourceFactory: DataSource.Factory = DefaultHttpDataSourceFactory(
    Util.getUserAgent(baseContext, "Appt"),
    null,
    DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS,
    1800000,
    true
)
val mediaUri = Uri.parse("https://appt.org/live-video")
val mediaSource = HlsMediaSource.Factory(dataSourceFactory).createMediaSource(mediaUri)
exoPlayer.prepare(mediaSource)

Feedback?

Let us know!