Home > Article > Web Front-end > Methods to create and return new text tracks in html5
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
Value | Description |
kind |
Specifies the type of text track. Possible values:
|
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. |
Description | |
Represents a new text track. |
<!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!