Home > Web Front-end > H5 Tutorial > body text

Methods to create and return new text tracks in html5

黄舟
Release: 2017-11-07 11:15:29
Original
2099 people have browsed it

Example

Add a new text track to Video:

text1=myVid.addTextTrack("caption");
text1.addCue(new TextTrackCue("Test text", 01.000, 04.000,"","","",true));
Copy after login

Definition and usage

addTextTrack() method creates and returns a new Text track.

The new TextTrack object will be added to the text track list of the video/audio element.

Browser support

All major browsers do not support the addTextTrack() method.

Syntax

audio|video.addTextTrack(kind,label,language)
Copy after login

Parameters

labellanguage
ValueDescription
kind

Specifies the type of text track.

Possible values:

  • "subtitles"

  • ##"caption"

  • "descriptions"

  • "chapters"

  • "metadata"

String value specifies the label for the text track. Used to identify text tracks for users.
A two-letter language code that specifies the language of the text track.

To see all available language codes, see our Language Codes Reference Manual.

Return value

TypeDescriptionTextTrack objectRepresents a new text track.
Example:

<!DOCTYPE html> 
<html> 
<body> 
<button onclick="myFunction()" type="button">添加新字幕</button>
<br>
<video id="video1" width="480" height="270" controls="controls"> 
<source src="material/sample.mp4" type="video/mp4"/> 
<source src="material/sample.ogv" type="video/ogg"/>你的浏览器不支持HTML5 video.</video>
<script>var vid = document.getElementById("video1");
function myFunction() {   
var text1 = vid.addTextTrack("caption");
text1.addCue(new TextTrackCue("Test text", 01.000, 04.000, "", "", "", true));}
</script> 
</body> 
</html>
Copy after login


The above is the detailed content of Methods to create and return new text tracks in html5. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!