Skip to main content
Logo Appt Light

Success Criterion 1.4.2 - Level A

Audio Control

Ensure that audio which lasts longer than three seconds can be paused or stopped. This is important for people who have difficulty concentrating. In addition, the screen reader is difficult to use when other audio is playing.

Impact

  • For screen reader users, it is disruptive to auto-play audio.

  • Auto-playing audio can disrupt people who have difficulty concentrating to process information.

Check

“Can audio be controlled?“

This can be tested without the use of assistive technologies.

Solution

Always provide a pause or stop button when playing sound.

Add audio control

In Android apps, you should always be able to control audio. When using MediaPlayer, you should implement buttons to call the startpause and stop methods.

It is a best practice to play audio through the correct channel. Android has introduced AudioAttributes as a replacement of the STREAM types defined in AudioManager.

AudioAttributes defines the following content types:

AudioAttributes defines the following usages:

AudioManager defines the following legacy channels:

// Set audio attributes
val player = MediaPlayer()
player.setAudioAttributes(
    AudioAttributes.Builder()
        .setUsage(AudioAttributes.USAGE_ASSISTANCE_ACCESSIBILITY)
        .setContentType(AudioAttributes.CONTENT_TYPE_SPEECH)
        .setLegacyStreamType(AudioManager.STREAM_ACCESSIBILITY)
        .build()
)

// Provide media controls
button.setOnClickListener {
    if (player.isPlaying()) {
        player.pause()
    } else {
        player.start()
    }
}

Resources

Feedback?

Let us know!