Multimedia Accessibility – C# Examples

Accessible Multimedia

Multimedia web accessibility refers to ensuring that multimedia content, such as videos, audio files, and interactive presentations, is accessible to all individuals, including those with disabilities. Multimedia content is prevalent on the internet, and everyone must access and understand the information conveyed. Accessible media must meet all the needs of people with disabilities and must include:

The accessible multimedia is customized for assistive technologies. This means that blind people no longer have to rely on others to read to them. They simply open the browser and interact with the content on their own, as screen reader software is designed to read online content out loud.

Without a caption for an audio file, deaf people cannot recognize the meaningful information that the audio conveys. But captions, if they are well-written and synchronized with the audio content, provide descriptions of critical visual details and actions in multimedia.

We already covered how to check alt text for images, buttons, and more in the Screen Reader Accessibility article. Here, we will look at the importance of using a <track> element for multimedia accessibility.

<track> Element to Provide Audio & Video Descriptions

Video content cannot be seen by visually impaired people, and audio content cannot be heard by hearing-impaired people. The primary purpose of the <track> element is to provide captions and subtitles for video and audio content. While it’s not intended for providing audio descriptions directly, it can be used in conjunction with other methods to make audio descriptions available for individuals with visual impairments.

Captions for Video

The use of the video alt text is not a standard or recommended practice in HTML. The alt attribute is primarily used for providing alternative text for images and is not intended for <video> elements. However, there are alternative approaches to making video content accessible.

Captions in the video include a textual description of all essential background noises and other sounds and the text of all dialogue and narration. The <video> element must include a <track> element with kind="captions" property. Captions must convey all relevant auditory information in the video, including dialogue, musical cues, sound effects, and other vital data for deaf users.

Here’s how you can use the <track> element for multimedis accessibility:

1<video poster="myvideo.png" controls>
2    <source src="myvideo.mp4" srclang="en" type="video/mp4">
3    <source src="myvideo.webm" srclang="fr" type="video/webm">
4    <source src="myvideo.webm" srclang="ua" type="video/webm"> 
5    <track src="myvideo_en.vtt" kind="captions" srclang="en" label="English">
6    <track src="myvideo_fr.ttml" kind="captions" srclang="fr" label="French">
7    <track src="mvideo_ua.vtt" kind="captions" srclang="ua" label="Ukrainian">

Let’s look at line 5 of the HTML code. The src attribute of the <track> element specifies the track file name and points to the WebVTT file (“myvideo_en.vtt”) containing the captions or subtitles. The kind attribute describes the contents of the file. The srclang attribute specifies the language of the track file. The label attribute specifies the track name. None of these attributes, except src, are required. However, they are highly recommended as they improve clarity.

Captions for Audio

Ensure all elements with audio content on the website have a caption using the <track> element with kind="captions" property. Captions are text—synchronized with the audio file—of the dialog, narration, and any important auditory information, for the benefit of deaf users. The following code shows how to add two different tracks – one in English and one in Spanish:

2   <source src="mySpeech.mp3" type="audio/mp3">
3   <track src="captions_en.vtt" kind="captions" srclang="en" label="english_captions">
4   <track src="captions_es.vtt" kind="captions" srclang="es" label="spanish_captions">

Audio Description for <video> elements

Adding audio descriptions to <video> elements is a crucial accessibility practice, ensuring that individuals with visual impairments can fully understand and enjoy video content. While blind people can hear the audio content of videos with no issue, they miss the visual aspects of films, such as facial expressions and scenes. Many things happen in movies that are completely visual, with no auditory component. For example, a person can make a facial expression but not speak. Audio descriptions provide narrated information about the visual elements of a video, such as scenes, actions, and gestures.

The following code shows how to add two different audio descriptions – one in English and one in Spanish:

1<video width="300" height="200">
2    <source src="myVideo.mp4" type="video/mp4">
3    <track src="audio_desc_en.vtt" kind="descriptions" srclang="en" label="english_description">
4    <track src="audio_desc_es.vtt" kind="descriptions" srclang="es" label="spanish_description">

Check Multimedia Accessibility with Aspose.HTML

To check your website for the multimedia accessibility criteria, you need to follow these steps:

  1. Use the WebAccessibility() constructor to create an instance of the WebAccessibility class responsible for web accessibility validation.
  2. Use the Rules property of the webAccessibility object that provides access to a collection of web accessibility rules.
    • Call the GetPrinciple() method of the AccessibilityRules class and GetGuideline() method of the Principle class to get required principle by code from WCAG.
  3. Call the CreateValidator() method to create a validator object. You are essentially setting up a validator that will check web content against the specific accessibility guidelines and success criteria associated with the guideline you’ve specified.
  4. Load an HTML document using one of the HTMLDocument() constructors.
  5. Use the Validate(document) method to check the HTML document for accessibility. The result is stored in the validationResult variable.
  6. Check whether the validation was successful. Print the detailed information about errors, including the associated HTML element.

In this example, you can check an HTML document for compliance with all the criteria in the “1.2 Time-based Media” guideline.

 1using Aspose.Html;
 2using Aspose.Html.Accessibility;
 3using System.IO;
 5    // Initialize a webAccessibility container
 6    var webAccessibility = new Aspose.Html.Accessibility.WebAccessibility();
 8    // Get from the rules list Principle "1.Perceivable" by code "1" and get guideline "1.2 Time-based Media"
 9    var guideline = webAccessibility.Rules.GetPrinciple("1").GetGuideline("1.2");
11    // Create an accessibility validator, pass the found guideline as parameters, and specify the full validation settings
12    var validator = webAccessibility.CreateValidator(guideline, ValidationBuilder.All);
14    // Initialize an object of the HTMLDocument class
15    using (var document = new HTMLDocument(""))
16    {
17        // Check the document
18        var validationResult = validator.Validate(document);
20        // Checking for success
21        if (!validationResult.Success)
22        {
23            // Get all result details
24            foreach (var ruleResult in validationResult.Details)
25            {
26                // If the result of the rule is unsuccessful
27                if (!ruleResult.Success)
28                {
29                    // Get errors list
30                    foreach (var result in ruleResult.Errors)
31                    {
32                        // Check the type of the erroneous element
33                        if (result.Error.Target.TargetType == TargetTypes.HTMLElement)
34                        {
35                            var rule = (HTMLElement)result.Error.Target.Item;
36                            Output.WriteLine("Error in rule {0} : {1}", result.Rule.Code, result.Error.ErrorMessage);
37                            Output.WriteLine("HTML Element: {0}", rule.OuterHTML);
38                        }
39                    }
40                }
41            }
42        }
43    }

To check, for example, the presence of audio description, you must select the desired criterion and make a check on it.

 1    // Get from the rules list Principle "1.Perceivable" by code "1" and get guideline "1.2 Time-based Media"
 2    var guideline = webAccessibility.Rules.GetPrinciple("1").GetGuideline("1.2");
 4    // Get criterion – 1.2.3 Audio Description or Media Alternative (Prerecorded)
 5    var criterion = guideline.GetCriterion("1.2.3");
 7    // Create an accessibility validator – and pass the found guideline as parameters and specify the full validation settings
 8    var validator = webAccessibility.CreateValidator(criterion, ValidationBuilder.All);
10    ...

Remember that the key is to ensure that users with disabilities can access the multimedia content and understand its context effectively. Combining multiple accessibility techniques, such as captions, transcripts, and audio descriptions, can provide all users with a comprehensive and inclusive experience.

See Also

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.