このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

TextTrackCueList: getCueById() メソッド

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2015年7月⁩.

getCueById()TextTrackCueList インターフェイスのメソッドで、TextTrackCueList オブジェクトが表すリストの中で、識別子が id の値と一致する最初の VTTCue を返します。

構文

js
getCueById(id)

引数

id

キューの識別子の文字列です。

返値

VTTCue オブジェクトです。

TextTrack.cues プロパティは、その具体的なトラックの現在のキューを格納した TextTrackCueList を返します。cues.getCueById("second") を呼び出すと、VTTCue のうち ID が "second" のものを返します。

WEBVTT

first
00:00:00.000 --> 00:00:00.999 line:80%
Hildy!

second
00:00:01.000 --> 00:00:01.499 line:80%
How are you?
js
const video = document.getElementById("video");
video.onplay = () => {
  console.log(video.textTracks[0].cues.getCueById("second")); // a VTTCue object;
};

仕様書

Specification
HTML
# dom-texttrackcuelist-getcuebyid

ブラウザーの互換性