Success Criterion 1.4.2 - Level A
Audio Control
Ensure that audio which lasts longer than three seconds can be paused or stopped. It is disturbing if audio cannot be paused, especially for people who use a screen reader. As a result, they can no longer hear the screen reader's voice properly. For people who have difficulty concentrating, it is also nice if audio can be paused. This allows them to focus better on the other information.
Impact
For screen reader users, it is disruptive to autoplay audio.
Autoplaying 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 start
, pause
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:
CONTENT_TYPE_MOVIE
: used for soundtracks, typically in moviesCONTENT_TYPE_MUSIC
: used for musicCONTENT_TYPE_SONIFICATION
: used for accompanying sounds, such as beepsCONTENT_TYPE_SPEECH
: used for speechCONTENT_TYPE_UNKNOWN
: used when the content type is unknown, or other than the available options
AudioAttributes
defines the following usages:
USAGE_ALARM
: used for alarmsUSAGE_ASSISTANCE_ACCESSIBILITY
: used for accessibility, e.g. for screen reader usersUSAGE_ASSISTANCE_NAVIGATION_GUIDANCE
: used for navigation directions, e.g. while drivingUSAGE_ASSISTANCE_SONIFICATION
: used for user interface soundsUSAGE_ASSISTANT
: used for user queries, audio instructions or help utterances.USAGE_GAME
: used for audio inside gamesUSAGE_MEDIA
: used for audio in media, such as moviesUSAGE_NOTIFICATION
: used for notification soundsUSAGE_NOTIFICATION_EVENT
: used to attract the user's attention, such as a reminder or low battery warning.USAGE_NOTIFICATION_RINGTONE
: used for telephony ringtonesUSAGE_UNKNOWN
: used when the usage is unknown, or not definedUSAGE_VOICE_COMMUNICATION
: used for voice communication, such as telephony or VoIPUSAGE_VOICE_COMMUNICATION_SIGNALLING
: used for in-call signalling, such as with a "busy" beep, orDTMF
tones.
AudioManager
defines the following legacy channels:
STREAM_ACCESSIBILITY
: channel for accessibility, such as assistive technologiesSTREAM_ALARM
: channel for alarmsSTREAM_DMTF
: channel for dual-tone multi-frequency signaling, such as phone dialing tonesSTREAM_MUSIC
: channel for musicSTREAM_NOTIFICATION
: channel for notificationsSTREAM_RING
: channel for incoming phone callsSTREAM_SYSTEM
: channel for system soundsSTREAM_VOICE_CALL
: channel for voice calls
// 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()
}
}