HTML and CSS Reference
In-Depth Information
Figure I.7. An error trying to access the currently active cue in the text track
The error in figure I.7 can have two main causes:
• There isn't a cue available for the current time.
• The text track hasn't loaded yet.
Determining whether there is a cue currently available follows the normal rules of
JavaScript; simply do a test like if (typeof
p.textTracks[2].activeCues[0] !== 'undefined') before attempting to
access the text property. In most real-life cases, you'll do this as a matter of course. But
it's clearly the second issue that's the problem here because our description cue file has no
gaps in its time coverage. One approach to solving the second issue would be to listen for
the load event of the text track, something we'll discuss further in the next section when
you learn about events. In the meantime, we'll look at two alternative approaches to solv-
ing the second issue:
• Loading all the text tracks in advance
• Checking to see if the text track has loaded
Loading the text tracks in advance
Unless the default attribute is applied to the track, it will be in the default mode of
DISABLED. For the browser to load the tracks, you need to set them to either HIDDEN or
VISIBLE. It's easy enough to do this in the ready event you already have in your code,
as shown in the following listing.
 
Search WWH ::




Custom Search