The text tracks of a media element as data: captions and subtitles to choose and show, and chapters to follow in every browser.
A track is a map of the members of TextTrack in kebab-case, with the values of its enums as keywords, e.g.
{:kind :chapters
:label "Chapters"
:language "en"
:mode :hidden
:active-cues [{:start-time 95 :end-time 1830 :text "News"}]}
Only Chromium accepts chapters in the Media Session's metadata, but a hidden chapters track fires cuechange in every engine. So a chapters track from add! and chapter-cues, followed with watch!, says which chapter plays.
The text tracks of a media element as data: captions and subtitles to
choose and show, and chapters to follow in every browser.
A track is a map of the members of TextTrack in kebab-case, with the
values of its enums as keywords, e.g.
{:kind :chapters
:label "Chapters"
:language "en"
:mode :hidden
:active-cues [{:start-time 95 :end-time 1830 :text "News"}]}
Only Chromium accepts chapters in the Media Session's metadata, but a
hidden chapters track fires cuechange in every engine. So a chapters
track from add! and chapter-cues, followed with watch!, says which
chapter plays.(add! element
{:keys [kind label language mode cues]
:or {kind :subtitles mode :hidden}
:as track})Add a text track to the media element from track, a map of its
:kind, :label, :language, :mode and :cues, and return a function that
removes it, e.g.
(def remove!
(add! audio {:kind :chapters
:cues (chapter-cues chapter-info 1830)}))
The :kind is :subtitles and the :mode is :hidden by default, which follows the cues without showing them. The cues are maps of their :start-time, :end-time and :text, and the call leaves out those that the browser refuses, e.g. for a start time that isn't finite. A cue that ends at ##Inf lasts to the end of the media, however long it turns out.
The track comes from a track element, since a track from addTextTrack can never be removed. The cues follow once the element has loaded, since Chrome and WebKit drop the cues added before.
Add a text track to the media `element` from `track`, a map of its
:kind, :label, :language, :mode and :cues, and return a function that
removes it, e.g.
(def remove!
(add! audio {:kind :chapters
:cues (chapter-cues chapter-info 1830)}))
The :kind is :subtitles and the :mode is :hidden by default, which
follows the cues without showing them. The cues are maps of their
:start-time, :end-time and :text, and the call leaves out those that the
browser refuses, e.g. for a start time that isn't finite. A cue that
ends at ##Inf lasts to the end of the media, however long it turns out.
The track comes from a track element, since a track from addTextTrack
can never be removed. The cues follow once the element has loaded, since
Chrome and WebKit drop the cues added before.(chapter-cues chapters duration)The cues of a chapters track for the chapters of a media of duration
seconds, e.g. the :chapter-info of the session's metadata. Each chapter
lasts until the next one starts, and the last until the end, at the
duration, or at ##Inf while the duration is nil or unknown, e.g. before
the metadata has loaded:
(chapter-cues [{:title "Intro" :start-time 0}
{:title "News" :start-time 95}]
nil)
;; => [{:start-time 0 :end-time 95 :text "Intro"}
;; {:start-time 95 :end-time ##Inf :text "News"}]
The cues of a chapters track for the `chapters` of a media of `duration`
seconds, e.g. the :chapter-info of the session's metadata. Each chapter
lasts until the next one starts, and the last until the end, at the
duration, or at ##Inf while the duration is nil or unknown, e.g. before
the metadata has loaded:
(chapter-cues [{:title "Intro" :start-time 0}
{:title "News" :start-time 95}]
nil)
;; => [{:start-time 0 :end-time 95 :text "Intro"}
;; {:start-time 95 :end-time ##Inf :text "News"}](cues cue-list)The cue-list, a TextTrackCueList, as a vector of maps of each cue's
:start-time, :end-time and :text, and its :id where it has one. A cue
that lasts to the end of the media, as add! writes one, ends at ##Inf.
The `cue-list`, a TextTrackCueList, as a vector of maps of each cue's :start-time, :end-time and :text, and its :id where it has one. A cue that lasts to the end of the media, as add! writes one, ends at ##Inf.
(show! element {:keys [kinds languages label] :as prefs})Show the first text track of the media element that prefs choose,
and turn off its other tracks of those kinds. Return the track as shown,
or nil where none matches, which turns them all off.
The prefs are a map of the :kinds and the :languages that you accept,
each in the order that you prefer, e.g.
(show! video {:kinds [:captions :subtitles]
:languages ["da" "en"]})
The language counts first, so Danish subtitles beat English captions, and a language includes its regional variants, e.g. "en" includes "en-GB". Without :languages, no track matches, which turns the kinds off.
With a :label, only a track of that label matches, in any language unless :languages narrow it, e.g. a track that you added yourself:
(show! video {:kinds [:captions] :label "Transcript"})
Show the first text track of the media `element` that `prefs` choose,
and turn off its other tracks of those kinds. Return the track as shown,
or nil where none matches, which turns them all off.
The `prefs` are a map of the :kinds and the :languages that you accept,
each in the order that you prefer, e.g.
(show! video {:kinds [:captions :subtitles]
:languages ["da" "en"]})
The language counts first, so Danish subtitles beat English captions,
and a language includes its regional variants, e.g. "en" includes
"en-GB". Without :languages, no track matches, which turns the kinds
off.
With a :label, only a track of that label matches, in any language
unless :languages narrow it, e.g. a track that you added yourself:
(show! video {:kinds [:captions] :label "Transcript"})(text-track track)The track, a TextTrack, as a map of its :kind, :label, :language,
:mode and :active-cues. A disabled track has no active cues.
The `track`, a TextTrack, as a map of its :kind, :label, :language, :mode and :active-cues. A disabled track has no active cues.
(text-tracks element)The text tracks of the media element as a vector of maps from
text-track.
The text tracks of the media `element` as a vector of maps from text-track.
(watch! element f)Call f with the text tracks of the media element now and whenever
they change, and return a function that stops it.
They change when a track is added or removed, when its mode changes, and
when its active cues change, e.g. at the start of a chapter. The call
passes the vector from text-tracks to f only when it differs from the
last, e.g.
(def stop!
(watch! video #(swap! app assoc :tracks %)))
Where the element's tracks fire no events, e.g. in jsdom, the call does nothing.
Call `f` with the text tracks of the media `element` now and whenever
they change, and return a function that stops it.
They change when a track is added or removed, when its mode changes, and
when its active cues change, e.g. at the start of a chapter. The call
passes the vector from text-tracks to `f` only when it differs from the
last, e.g.
(def stop!
(watch! video #(swap! app assoc :tracks %)))
Where the element's tracks fire no events, e.g. in jsdom, the call does
nothing.cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |