View on GitHub

Able Player

Fully accessible cross-browser HTML5 media player.

Download this project as a .zip file Download this project as a tar.gz file

Able Player

Able Player is a fully accessible cross-browser HTML5 media player.

To see the player in action check out the Able Player Examples page.

Features

Supported Languages

Able Player has been translated into the following languages. To add another language, see instructions below under Contributing.

Contributing

There are many ways to contribute to Able Player, and we welcome and appreciate your help! Here are some options:

Compatibility

Able Player has been tested with the following browsers and assistive technologies.

Note that mobile browsers have limitations (e.g., volume control and autostart are not supported)

Dependencies

Able Player has the following third party dependencies:

To install Able Player, copy the following files from the Able Player repo into a folder on your web server:

The build folder includes minified production code (ableplayer.min.js and ableplayer.min.css). For debugging and/or style customization purposes, human-readable source files are also available:

Fallback

All modern browsers have supported HTML5 media elements for many years. However, there are still older browsers in use that don’t have this support (e.g., Internet Explorer 9 and earlier). For these, you need to provide fallback content.

Prior to version 4.0, Able Player used JW Player as a fallback Flash player for older browsers. However, this solution was built specifically on JW Player 6 which is now many versions old and difficult to find.

Also, prior to version 4.0, Able Player used Modernizr to enable styling of HTML5 elements in Internet Explorer 6 through 8. This too is no longer supported, and Modernizr is no longer needed.

Instead, we recommend providing alternative content as a child of the <video> or <audio> element. For example, this could be a link to the media file so users can download it and play it on their player of choice. Or it could be a link to a transcript.

If the browser is unable to play the media file, Able Player will show this alternative content. If no alternative content is provided, Able Player will display a standard message that lists the minimum versions of common web browsers required for playing HTML5 media.

Setup Step 1: Use HTML5 Doctype

Able Player is built on the HTML5 media elements, so at the top of your web page be sure you have the HTML5 doctype:

<!DOCTYPE html>

Setup Step 2: Add JavaScript and CSS

Copy and paste the following code into your web page. This code applies to all use cases, both audio and video.

<!-- Dependencies -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="thirdparty/js.cookie.js"></script>

<!-- CSS -->
<link rel="stylesheet" href="build/ableplayer.min.css" type="text/css"/>

<!-- JavaScript -->
<script src="build/ableplayer.min.js"></script>

Setup Step 3: Add HTML

Add an HTML5 <audio> or <video> element to your web page, as follows.

Audio

Copy and paste the following code into your web page, replacing the source files with the path to your own media files. Use both OGG and MP3 to ensure cross-browser compatibility, since some browsers don’t support MP3.

<audio id="audio1" data-able-player preload="auto">
  <source type="audio/ogg" src="path_to_audio_file.ogg"/>
  <source type="audio/mpeg" src="path_to_audio_file.mp3"/>
</audio>

Video

Copy and paste the following code into your web page, replacing the source files with the path to your own media files. Use both WebM and MP4 to ensure cross-browser compatibility, since some browsers don’t support MP4.

<video id="video1" data-able-player preload="auto" width="480" height="360" poster="path_to_image.jpg">
  <source type="video/webm" src="path_to_video.webm" data-desc-src="path_to_described_video.webm"/>
  <source type="video/mp4" src="path_to_video.mp4" data-desc-src="path_to_described_video.mp4"/>
  <track kind="captions" src="path_to_captions.vtt"/>
  <track kind="descriptions" src="path_to_descriptions.vtt"/>
</video>

Supported Attributes

The following attributes are supported on both the <audio> and <video> elements:

Required Attributes

Optional; General-Purpose

Language

Captions

Transcript

Able Player can automatically generate an accessible interactive transcript from the chapters, captions, and descriptions tracks. There are three types of interactive transcripts supported:

The following attributes control which of the above types, if any, are generated:

If none of the above attributes are present, the transcript will be displayed in a draggable, resizable popup that can be toggled on/off using a button on the controller. Note that a toggle button is added to the controller only if the transcript is a “popup” type; there is no toggle button for either the “external” or “manual” transcript types.

Additional transcript-related attributes include:

To manually code the transcript, one simple strategy is to first allow Able Player to automatically generate a transcript. Then copy and paste its content as a starting point. To manually code a transcript from scratch, use the following markup (see Video Demo #7 for an example):

Chapters

Metadata

Metadata is added using the <track> element with kind=”metadata”. It must be in Web Video Text Tracks format (WebVTT). Able Player supports two types of metadata:

  1. “text” - The WebVTT file contains text, intended to be written to an external container at the designated times. You must provide the external container; Able Player does not generate that automatically.

  2. “selector” - The WebVTT file contains jQuery selectors which target hidden content that is already present on the web page. At the designated times, the hidden content referenced by the jQuery selectors is made visible. In addition to selectors, the WebVTT file can contain either of the following keywords, each on a line by itself:

This combination of exposing new content, pausing the video, and placing keyboard focus on a newly exposed element, can be used to provide supplemental content including clickable “hot spots” overlaid on the video.

The following attributes make all this possible:

NOTE: If you’re using metadata to expose content in sync with videos hosted on YouTube, please review YouTube’s Terms of Service related to Overlays and Frames. As of August 11, 2016: “You must not display overlays, frames, or other visual elements in front of any part of a YouTube embedded player, including player controls. Similarly, you must not use overlays, frames or other visual elements to obscure any part of an embedded player, including player controls.”

Fallback Player

The following attributes are supported on the <video> element only:

If width and height are omitted, the player will be sized to fit its container.

The following additional features are supported by Able Player:

Multiple source files

As with audio, we recommend including two versions of each video, one in H.264 (MP4) and another in WebM or OGG for browsers that don’t support MP4. Browsers will play the first media source that they support.

Closed Captions

Captions are added using the <track> element with kind=”captions”. Captions must be in Web Video Text Tracks format (WebVTT). WebVTT tags within captions are currently ignored.

NOTE: Able Player only supports valid WebVTT files. Be sure to validate your WebVTT using a WebVTT Validator.

If captions are provided, a CC button will be added to the Able Player controller.

Audio Description

Supplemental description of key visual content for blind users can be added using one of two methods.

The first method is the same as closed captions, a <track> element, with kind=”descriptions”. This points to a WebVTT file, which is essentially the same as a closed caption file, but its contents are description text rather than captions. With this method, description text is read aloud by browsers that support the Web Speech API; otherwise it’s written to an
ARIA live region, so supporting screen readers will automatically announce the new text as soon as it is written to the page.

The second method is to produce a separate video with description mixed in. If multiple video sources are already provided (e.g., an MP4 and WebM file), then the described version must be available in both of these formats. For each video source that has a described version available, add a data-desc-src attribute to the <source> element for that video. The value of this attribute is a path pointing to the described version of the video. With this method, the described version of the video can be played instead of the non-described version, and the two versions can be swapped with clicking the “D” button on the controller.

If descriptions are available using either of the above methods, a Description toggle button appears on the controller (represented by the universal Description symbol, the letter “D”). How descriptions are ultimately delivered depends on which of the above methods is used.

If both methods are used, description will be delivered using the separate
described version of the video. However, the WebVTT file will be used to (a) display the description text visibly (if users have selected this option in their preferences), and (b) incorporate the description text into the auto-generated interactive transcript. Therefore, it is important for the WebVTT description file to be accurately synchronized with the separate described version of the video.

In some applications, text-based descriptions might be a required part of the interface (e.g., if video pauses so users can interact with HTML overlays; text-based description could be used in this context to provide additional instructions for screen reader users). In such cases the Descriptions button can be eliminated from the controller with data-use-descriptions-button=”false”.

In other applications, a WebVTT descriptions file might be used solely for the purposes of displaying visible description text or incorporating description text into the auto-generated transcript, and the WebVTT description text is not intended to be read aloud by screen readers or browsers (for example, if the sole video source is a described video). In such cases, use data-descriptions-audible=”false” to prevent browsers and screen readers from announcing changes to the description text.

Sign language

Sign language translation is supported in a separate video player, synchronized with the main player. Tips for filming a sign language interpreter are available from Signing Books for the Deaf:

If multiple video sources are already provided (e.g., an MP4 and WebM file), then the sign language video must be available in both of these formats. For each video source that has a sign language version available, add a data-sign-src attribute to the <source> element for that video. The value of this attribute is a path pointing to the sign language version of the video. If a sign language version is available, a sign language button will be added to the media controller. This button will toggle the display of a pop-up window in which the sign language video will appear. Users can move or resize the pop-up window with either mouse or keyboard.

Unfortunately this feature is not currently supported on iOS.

Setup Step 4: Review User-Defined Variables in ableplayer.js

The JavaScript file initialize.js includes a block of user-defined variables that can be modified from their default settings, such as volume, color of controller buttons, seek interval for rewind and forward buttons, and others. Explanations of each variable are provided in the comments.

If you make changes to this or any other JavaScript script files, the player will need to be recompiled before your changes will take effect. To do so, run the shell script compile.sh.

Playlists

An Able Player playlist is an HTML list of tracks. A playlist can accompany either a video or audio player, but both audio and video cannot be combined within a single playlist. The list can be either ordered (<ol>) or unordered (<ul>).

The following attributes are supported on the list element:

Within the playlist, each list item can include the following HTML attributes:

If width and height are omitted, the player will be sized to fit its container.

The following HTML elements must be nested inside each list item:

A <span> element with class=”able-source” for each <source> element that is to accompany the media. When the user selects an item from the playlist, its able-source <span> elements will be copied to <source> elements and loaded for playback. For each attribute that will ultimately be on the media’s <source> elements, add the same attributes to each <span>, prefaced with data-.

Within the playlist, each list item must include the following HTML elements:

The following example shows a playlist with two videos. The first video has one source (an MP4 file), and two tracks (captions and descriptions). The second video is hosted on YouTube, and has both a non-described and described version. It also has a locally-hosted chapters track.
Able Player supports mixed playlists, with videos hosted locally or on YouTube. Vimeo videos are not yet supported within playlists.

<ul class="able-playlist" data-player="my_video_player">
  <li data-poster="video1.jpg" data-width="480" data-height="360">
    <span class="able-source" 
      data-type="video/mp4" 
      data-src="video1.mp4">
    </span>
    <span class="able-track" 
      data-kind="captions" 
      data-src="video1_captions_en.vtt" 
      data-srclang="en"
      data-label="English">
    </span>
    <span class="able-track"
      data-kind="descriptions"
      data-src="video1_description_en.vtt"
      data-srclang="en"
      data-label="English">
    </span>
    <button type="button">
      <img src="video1_thumbnail.jpg" alt="">
      Title of Video 1
    </button>
  </li>
  <li data-youtube-id="xxxxxxxxxxx" data-youtube-desc-id="yyyyyyyyyyy">
    <span class="able-track"
      data-kind="chapters"
      data-src="video2_chapters.vtt"
      data-srclang="en"
      data-label="Chapters">
    </span>
    <button type="button">
      <!-- thumbnail will be retrieved from YouTube -->
      Title of Video 2
    </button>
  </li>
</ul>

For additional examples of both audio and video playlists, see the Able Player Examples page.

Supported data-* audio types:

Supported data-* video types:

When a playlist is included on a page, the <source> elements within the <audio> or <video> tags are optional. If they are provided, they should match the first item in the playlist.

Interactive Transcript

Able Player interactive transcripts are generated automatically from WebVTT chapters, descriptions, and captions/subtitles files. If a transcript is available, a Transcript button will be added to the Able Player controller.

Features of the interactive transcript include the following:

If the transcript is assembled from multiple sources, any timing imperfections between sources come sometimes lead to problems in the read order within the transcript. For example, a new chapter should start before any captions or descriptions within that chapter. If the chapter starts a millisecond later than its first caption, the chapter name will appear in the transcript as a heading after its first caption. To help authors/developers attain perfect synchronization between all timed text files, Able Player (in version 3.1.6) introduced a Video Transcript Sorter (VTS). The VTS displays all timed text content from all sources in a table, and provides several features that enable users to rearrange content and modify start and end times. Users can also insert new content into the table, which can be useful for authoring low frequency content such as chapters and description. Too use VTS, add the following HTML to the desired location within any web page that includes an Able Player instance:

<div id="able-vts"></div>

YouTube Support

To play a YouTube video in Able Player, simply include a data-youtube-id attribute on the <video> element. The value of this attribute must be the video’s 11-character YouTube ID.

If a described version of the video is available on YouTube, include a data-youtube-desc-id attribute on the <video> element. The value of this attribute must be the 11-character YouTube ID of the described version. If users turn on the Description button on their player controller, the described version of the video will be loaded instead of the non-described version.

Versions 2.3.1 through 3.2.12 required a YouTube Data API key for retrieving caption data from YouTube. Get a YouTube Data API key by registering your application at the Google Developer Console. For complete instructions, see Google’s Getting Started page. Note: All that’s needed for playing YouTube videos in Able Player is a simple API key, not OAuth 2.0.

After obtaining your YouTube Data API Key, insert the following code into your HTML page:

<script>
  var youTubeDataAPIKey = "paste your API key here";
  var googleApiReady = false;
  function initGoogleClientApi() {
    googleApiReady = true;
  }
</script>
<script src="http://apis.google.com/js/client.js?onload=initGoogleClientApi"></script>

Starting with version 3.2.13, Able Player no longer requires a YouTube Data API key in order to access caption tracks from YouTube. However, an API key is still encouraged, as it relies on well-documented methods from Google, whereas operating without an API key relies on methods that are not well documented, and therefore may not be reliable.

Also new in 3.2.13, Able Player now handles YouTube captions in the same way it handles HTML <track kind="captions"> elements. The display of the caption text can be customized via the Preferences menu, and the caption text is used to automatically create an interactive transcript.

YouTube does not currently support chapters, descriptions, and metadata tracks. With Able Player, these features can be added to the video using HTML <track> elements, even if the video’s captions and subtitles are stored on YouTube. The advantage of managing captions entirely on YouTube is that you only have to manage them in one place, and they’re available everywhere your YouTube video is played.

If your video has HTML <track> elements for captions and subtitles, these will be used instead of the captions on YouTube.

Adjustable playback rate is available for some videos.

Vimeo Support

To play a Vimeo video in Able Player, simply include a data-vimeo-id attribute on the <video> element. The value of this attribute must be the video’s Vimeo ID (a string of numbers).

If a described version of the video is available on Vimeo, include a data-vimeo-desc-id attribute on the <video> element. The value of this attribute must be the Vimeo ID of the described version. If users turn on the Description button on their player controller, the described version of the video will be loaded instead of the non-described version.

Note that Vimeo currently has some limitations:

MIME Types

If your media doesn’t play, one possibility is that your web server is attempting to serve up the media with the incorrect MIME type. On Apache, this can be correct by adding the following commands to the .htaccess file:

# Audio MIME Types
AddType audio/mpeg mp3
AddType audio/mp4 mp4
AddType audio/mp4 mpa
AddType audio/ogg ogg
AddType audio/ogg oga
AddType audio/wav wav

# Video MIME Types
AddType video/mp4 mp4
AddType video/ogg ogv
AddType video/webm webm

If you don’t have access to your server’s .htaccess file, you should be able to view and add MIME types somewhere within your server’s control panel.

If your site is running on a Windows server, consult the documentation from Microsoft. For example:

Keyboard Shortcuts

Able Player includes several keyboard shortcuts that enable users to control the player from anywhere on the web page, as follows:

Note that modifier keys (Alt, Control, and Shift) can be assigned by clicking the Preferences button on the player. If users find that shortcut keys aren’t working as advertised, they might have better success by selecting different combinations of modifier keys to accompany the default shortcut keys.

By default, keyboard shortcuts must be accompanied by Alt + Control.

User Preferences

One of Able Player’s accessibility features is that the player is highly customizable by users. The controller includes a Preferences button that allows users to change default preferences and settings. Their changes are stored in a browser cookie and in most cases should therefore be preserved the next time they visit the site. Specifically, users can control the following:

Building the Able Player source

The source JavaScript files for Able Player are in the /scripts directory, and the source CSS files are in the /styles directory. These source files are ultimately combined into several different files (in the /build directory) using npm and Grunt:

npm install
grunt

The npm and Grunt build process is defined by the Gruntfile.js and package.json files. (Note that the version number is specified in package.json, and must be updated when a new version is released).

Files created by the build process are put into the /build directory:

Acknowledgments