大网数据广告活动
Web 标准与前端开发

DataCue: DataCue() constructor

· 52CE 我爱测

The **`DataCue()`** constructor creates and returns a new DataCue object that represents a timed metadata cue over a given time range. The resulting cue can be added to a metadata TextTrack using TextTrack.addCue(), allowing arbitrary data to be synchronized with audio or video p

WebVTT

The DataCue() constructor creates and returns a new DataCue object that represents a timed metadata cue over a given time range. The resulting cue can be added to a metadata TextTrack using TextTrack.addCue(), allowing arbitrary data to be synchronized with audio or video playback.

Syntax

new DataCue(startTime, endTime, value)
new DataCue(startTime, endTime, value, type)

Parameters

  • startTime
    • : A number representing the start time, in seconds, for the cue's time range. This corresponds to the point on the media timeline at which the cue becomes active and its TextTrackCue/enter_event event fires.
  • endTime
    • : A number representing the end time, in seconds, for the cue's time range. When the media playback reaches this time, the cue's TextTrackCue/exit_event event fires. Use Infinity for a cue that remains active until the end of the media.
  • value
    • : The data payload associated with the cue. This can be any type, such as a string, a JavaScript object, or an ArrayBuffer. The value is stored in the cue's DataCue.value property.
  • type
    • : A string identifying the type or schema of the data in value. This is typically a reverse-domain notation string (e.g., "org.id3", "org.mp4ra"). The value is stored in the cue's DataCue.type property and defaults to an empty string if not provided.

Return value

A new DataCue object.

Examples

Creating a DataCue with geolocation data

This example creates a DataCue that carries geolocation coordinates, using a reverse-domain string as the type to identify the data format.

<video controls src="video.mp4"></video>
const video = document.querySelector("video");
const track = video.addTextTrack("metadata", "Geo Track");
track.mode = "hidden";

// Create a cue from 5 seconds to the end of the media
const data = { latitude: 51.5043, longitude: -0.0762 };
const cue = new DataCue(5.0, Infinity, data, "org.example.geo");

cue.addEventListener("enter", (e) => {
  const { latitude, longitude } = e.target.value;
  console.log(`Pan map to: ${latitude}, ${longitude}`);
});

track.addCue(cue);

Specifications

Browser compatibility

See also

  • DataCue
  • TextTrack
  • TextTrack.addCue()
  • TextTrackCue/enter_event event
  • TextTrackCue/exit_event event

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。