Home  >  Article  >  Web Front-end  >  Methods to create and return new text tracks in html5

Methods to create and return new text tracks in html5

黄舟
黄舟Original
2017-11-07 11:15:292104browse

Example

Add a new text track to Video:

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

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)

Parameters

labellanguage
Value Description
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>


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!

Statement:
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