Embedding subtitles using HTML5 only
The section ‘Embedding Subtitles using HTML5 only’ will describe how subtitles will be provided to HTML5 based websites in the future.
Before starting
- Move the subs.srt, subs.vtt and the subs.xml file to the ‘website’ folder that was created earlier
The website folder should contain these files:
- videoplayer.fla
- videoplayer.swf
- SkinUnderPlayStopSeekCaptionVol.swf
- html5videoex.mp4
- html5videoex.webm
- html5video.htm
- subs.srt
- subs.vtt
- subs.xml
Embed subtitles using HTML5 only
These instructions will provide the HTML5 code for embedding subtitles. Before starting, open the html5video.htm webpage that was created earlier. That web page contained 3 links to 2 videos:- html5videoex.mp4
- html5videoex.webm
Current code
<body>
<video width="640" height="360" controls="controls"></body>
<source src="html5videoex.mp4" type="video/mp4" /></video>
<source src="html5videoex.webm" type="video/webm" />
<object id="flashContent" type="application/x-shockwave-flash" data="videoplayer.swf" width="640" height="400">
<param name="movie" value="videoplayer.swf" /></object>
<p>Download the Flash plugin from <a href="http://www.adobe.com" title="Download Flash plugin">www.adobe.com</a></p>
Updated code
Add the line of code below after the <source> tags and before the <object> tag to create the link to the subtitle:
<track src="subs.vtt" kind="subtitles" srclang="en" label="English subtitles" default />
The <track> tag is all that is required to meet the proposed HTML5 specification of providing subtitles.
Currently there are no browsers that render the subtitles from the <track> tag only and therefore a JavaScript solution must be provided. This is discussed in the ‘Making Subtitles Work Now’ post (The link to this can be found at the end of this page).
src – this is the location and name of the subtitle file
kind – specifies whether captions, subtitles, chapters, descriptions or metadata are being provided.
srclang – the language of the track
label – the title of the track
default – specifies that the track is enabled by default. Many track elements can be used for the same video.
The webpage code now with the <track> tag included appears as below:
<body>
<video width="640" height="360" controls="controls">
<source src="html5videoex.mp4" type="video/mp4" />
<source src="html5videoex.webm" type="video/webm" />
</body><track src="subs.vtt" kind="subtitles" srclang="en" label="English subtitles" default />
<object id="flashContent" type="application/x-shockwave-flash" data="videoplayer.swf" width="640" height="400">
<param name="movie" value="videoplayer.swf" />
<p>Download the Flash plugin from <a href="http://www.adobe.com" title="Download Flash plugin">www.adobe.com</a></p></object></video>
- Save the changes to the web page and test the result in a browser. In future versions of web browsers this is all that will be needed to get subtitles to work. As of April 2012* there are no browsers that support the <track> tag.
Related posts:
Accessible HTML5 video for allHow to create a basic HTML5 webpage
Fall back to Flash
Current HTML5 subtitle support
Subtitle creation process
Link subtitles to video
Making subtitles work now
A Flash solution
Making it work now, on an Android device
Making it work now, on an Apple device
Thoughts on HTML5 video and subtitles - conclusion
No comments:
Post a Comment