Audio description on Android
Videos should include audio description when important visual details are shown which you cannot hear. Audio description is an additional sound track which describes these important visual details. This allows people who are blind or have difficulty processing visual information to understand the content.
As of Android 4.1, the MediaPlayer
has support for multiple audio tracks. Use the selectTrack
method to select the correct audio track.
The code example belows shows a basic implementation of selecting an audio description track embedded inside a video.
val player = MediaPlayer.create(this, R.raw.video)
try {
player.trackInfo.forEachIndexed { index, trackInfo ->
if (trackInfo.trackType == TrackInfo.MEDIA_TRACK_TYPE_AUDIO) {
player.selectTrack(index)
return@forEachIndexed
}
}
player.start()
} catch (e: Exception) {
e.printStackTrace()
}