Skip to main content
Logo Appt Light

Success Criterion 1.2.2 - Level A

Captions (Prerecorded)

Ensure captions are provided for all videos with sound. People who are hard of hearing, deaf or deafblind depend on captions to understand what is being said. Captions are also useful for anyone who is temporarily unable to perceive sound, for example inside a quiet zone.

Impact

  • Captions are useful for anyone who is temporarily unable to perceive sound, for example in a quiet zone.

  • People who are deaf or hard of hearing depend on captions to understand what is being said.

Check

Are captions provided for all videos?”

This can be visually tested, no assistive technologies are needed.

Solution

Add captions

On Android, captions can be added by using TimedText inside a MediaPlayer. The code example below shows a basic example.

val player = MediaPlayer.create(this, R.raw.video)
try {
    player.addTimedTextSource("/assets/appt.srt", MediaPlayer.MEDIA_MIMETYPE_TEXT_SUBRIP)
    player.trackInfo.forEachIndexed { index, trackInfo ->
        if (trackInfo.trackType == TrackInfo.MEDIA_TRACK_TYPE_TIMEDTEXT) {
            player.selectTrack(index)
            return@forEachIndexed
        }
    }
    player.setOnTimedTextListener(this)
    player.start()
} catch (e: Exception) {
    e.printStackTrace()
}

Resources

Feedback?

Let us know!