Video Player
What makes a video accessible is widely misunderstood. Many web professionals know about closed captions. What many don't know is that they need audio descriptions in order to be WCAG AA compliant.
Requirement | A | AA | AAA |
---|---|---|---|
Closed Captions | |||
Audio Descriptions | Use either audio descriptions or transcripts to be single A compliant. | ||
Transcripts | Use either audio descriptions or transcripts to be single A compliant. | not required | |
Good contrast for overlay text | not required | ||
Can be paused | |||
No Seizure Inducing Sequences | |||
Sign Language | not required | not required | not required |
For a lot of companies and organizations, re-cutting an alternative cut of each video on their website is cost-prohibitive:
- It requires a voice actor to recite the audio descriptions.
- It requires a video editor to re-edit the video.
- Sometimes, other footage needs to be shot to accommodate the amount of time needed to insert the audio descriptions into the video.
Because of this, I have recommended using our custom build of Able Player and having the browser insert the audio descriptions. We have added some extra code to our build to ensure that Able Player plays the audio descriptions correctly on all devices (the official build has some issues in iOS — we will be submitting a PR to the official AblePlayer code so they can be incorporated in the official build). Able Player requires a separate caption file (in WebVTT format) so the player knows at what time the captions should be read out. In many instances, I also set the player to pause the video when the audio descriptions are recited, so the browser doesn't talk over the existing audio in the video.
One of the great side effects is that if you implement audio descriptions this way, the caption file + the audio descriptions file will produce a transcript for free, so your video player will meet a WCAG AAA guideline.
Video Player With Text-To-Speech Audio Descriptions
Code Walkthrough of the Above Example
Below is the HTML of the above example. Use the dropdown to highlight each of the individual steps that make the example accessible.
Installation Instructions
You can load this JavaScript library into your application in several ways:
- as an ES6 module using Webpack.
- as a CommonJS module using
require()
and Webpack. - as a native ES6 module within the browser.
- as an old-school ES4/JavaScript library.
If you haven't done so already, choosing which you should use is a major architectural decision. Here are a few articles that will help you decide:
- Jan Olaf Krems gives a great overview of the JavaScript file format differences.
- Joe Honton discusses that with ES modules and HTTP/2, you may not need Webpack anymore
- Stack Overflow has a really good thread about Webpack vs. ES6 modules as well.
Using NPM/Webpack to load ES6 Modules:
-
Install the
enable-a11y
NPM project. -
Edit your webpack.config.json file to resolve the
~
modifier by adding the following:module.exports = { ... resolve: { extensions: ['.js', '.jsx', '.scss', '.css', '*.html'], modules: [ path.resolve('./src/js'), path.resolve('./node_modules') ], alias: { '~enable-a11y': path.resolve(__dirname, 'node_modules/enable-a11y') }, ... }, ... }
-
You can use the module like this:
// import the JS module import ablePlayerCustomizations from '~enable-a11y/js/modules/ablePlayerCustomizations'; // AblePlayer uses this module, available via NPM
import Cookies from 'js-cookie'; // import the CSS for the module import '~enable-a11y/css/ablePlayerCustomizations'; // There is no .init() function to call. -
Alternatively, if you are using LESS you can include the styles in your project's CSS using:
@import '~enable-a11y/css/ablePlayerCustomizations';
.css
suffix)
Using NPM/Webpack to Load Modules Using CommonJS Syntax
-
Install the
enable-a11y
NPM project. -
You can import the module using
require
like this:var ablePlayerCustomizations = require('enable-a11y/ablePlayerCustomizations').default; ... ablePlayerCustomizations.init();
- You will have to include the CSS as well in your project's CSS using:
@import '~enable-a11y/css/ablePlayerCustomizations';
Using ES6 modules natively.
This is the method by which the page you are reading now loads the scripts.
- Grab the source by either using NPM, grabbing a ZIP file, or cloning the enable source code from GitHub.
-
If you want to load the module as a native ES6 module, copy
js/modules/ablePlayerCustomizations.js
, andcss/ablePlayerCustomizations.css
from the repo and put them in the appropriate directories in your project (all JS files must be in the same directory). -
Load the CSS in the head of your document:
<html> <head> ... <link rel="stylesheet" href="path-to/css/ablePlayerCustomizations.css" > ... </head> <body> ... </body> </html>
-
Load your scripts using the following code (NOTE: you must use
<script type="module">
):<script type="module"> import ablePlayerCustomizations from "path-to/ablePlayerCustomizations.js" ablePlayerCustomizations.init(); </script>
Using ES4
Just do the same as the ES6 method, except you should get the JavaScript files from thejs/modules/es4
directory instead of the js/modules/
:
<script src="path-to/es4/ablePlayerCustomizations.js"></script>