NAME

HTML::Object::DOM::Element::Track - HTML Object DOM Track Class

SYNOPSIS

use HTML::Object::DOM::Element::Track;
my $track = HTML::Object::DOM::Element::Track->new || 
    die( HTML::Object::DOM::Element::Track->error, "\n" );

my $video = $doc->getElementsByTagName('video')->[0];
# or
my $video = $doc->createElement('video');
$video->controls = 1; # true
# Source 1
my $source1 = $doc->createElement('source');
$source1->src = 'https://example.org/some/where/videos/video.webm';
# Source 2
my $source2 = $doc->createElement('source');
$source2->src = 'https://example.org/some/where/videos/video.mp4';
# Track 1
my $track1 = $doc->createElement('track');
$track1->kind = 'subtitles';
$track1->src = 'subtitles-en.vtt';
$track1->label = 'English captions';
$track1->srclang = 'en';
$track1->type = 'text/vtt';
$track1->default = 1; # true
# Track 2
my $track2 = $doc->createElement('track');
$track2->kind = 'subtitles';
$track2->src = 'subtitles-fr.vtt';
$track2->label = 'Sous-titres Français';
$track2->srclang = 'fr';
$track2->type = 'text/vtt';
# Track 3
my $track3 = $doc->createElement('track');
$track3->kind = 'subtitles';
$track3->src = 'subtitles-ja.vtt';
$track3->label = '日本語字幕';
$track3->srclang = 'ja'";
$track3->type = 'text/vtt';
# Append everything
$video->appendChild( $source1 );
$video->appendChild( $source2 );
$video->appendChild( $track1 );
$video->appendChild( $track2 );
$video->appendChild( $track3 );
my $p = $doc->createElement('p');
$p->textContent = q{This browser does not support the video element.};
$video->appendChild( $p );

<video controls="">
    <source src="https://example.org/some/where/videos/video.webm" type="video/webm" />
    <source src="https://example.org/some/where/videos/video.mp4" type="video/mp4" />
    <track src="subtitles-en.vtt" label="English captions" kind="subtitles" srclang="en" default />
    <track src="subtitles-fr.vtt" label="Sous-titres Français" kind="subtitles" srclang="fr" />
    <track src="subtitles-ja.vtt" label="日本語字幕" kind="subtitles" srclang="ja" />
    <p>This browser does not support the video element.</p>
</video>

VERSION

v0.2.0

DESCRIPTION

This interface represents an HTML <track> element within the DOM. This element can be used as a child of either <audio> or <video> to specify a text track containing information such as closed captions or subtitles.

INHERITANCE

+-----------------------+     +---------------------------+     +-------------------------+     +----------------------------+     +-----------------------------------+
| HTML::Object::Element | --> | HTML::Object::EventTarget | --> | HTML::Object::DOM::Node | --> | HTML::Object::DOM::Element | --> | HTML::Object::DOM::Element::Track |
+-----------------------+     +---------------------------+     +-------------------------+     +----------------------------+     +-----------------------------------+

PROPERTIES

Inherits properties from its parent HTML::Object::DOM::Element

default

A boolean value reflecting the default attribute, indicating that the track is to be enabled if the user's preferences do not indicate that another track would be more appropriate.

See also Mozilla documentation

kind

Is a string that reflects the kind HTML attribute, indicating how the text track is meant to be used. Possible values are: subtitles, captions, descriptions, chapters, or metadata.

See also Mozilla documentation

label

Is a string that reflects the label HTML attribute, indicating a user-readable title for the track.

See also Mozilla documentation

readyState

Returns an unsigned short that show the readiness state of the track. Below are the possible constant values. You can export and use those constants by calling either of the following:

use HTML::Object::DOM::Element::Track qw( :all );
# or
use HTML::Object::DOM qw( :track );

See "CONSTANTS" for the constants that can be exported and used.

See also Mozilla documentation

src

Is a string that reflects the src HTML attribute, indicating the address of the text track data.

See also Mozilla documentation

srclang

Is a string that reflects the srclang HTML attribute, indicating the language of the text track data.

See also Mozilla documentation

track

Returns TextTrack is the track element's text track data.

See also Mozilla documentation

METHODS

Inherits methods from its parent HTML::Object::DOM::Element

EVENTS

Event listeners for those events can also be found by prepending on before the event type:

For example, cuechange event listeners can be set also with oncuechange method:

$e->oncuechange(sub{ # do something });
# or as an lvalue method
$e->oncuechange = sub{ # do something };

cuechange

Under perl, this event is not triggered obviously, but you can trigger it yourself.

Under JavaScript, this is sent when the underlying TextTrack has changed the currently-presented cues. This event is always sent to the TextTrack but is also sent to the HTML::Object::DOM::Element::Track if one is associated with the track. You may also use the oncuechange event handler to establish a handler for this event.

Example:

$track->addEventListener( cuechange => sub
{
    my $cues = $track->activeCues; # array of current $cues
});

$track->oncuechange = sub
{
    my $cues = $track->activeCues; # array of current $cues
}

Another example:

my $textTrackElem = $doc->getElementById( 'texttrack' );

$textTrackElem->addEventListener( cuechange => sub
{
    my $cues = $event->target->track->activeCues;
});

or

$textTrackElem->oncuechange = sub
{
    my $cues = $_->target->track->activeCues;
});

See also Mozilla documentation

CONSTANTS

The following constants can be exported and used, such as:

use HTML::Object::DOM::Element::Track qw( :all );
# or directly from HTML::Object::DOM
use HTML::Object::DOM qw( :track );
NONE (0)

Indicates that the text track's cues have not been obtained.

LOADING (1)

Indicates that the text track is loading and there have been no fatal errors encountered so far. Further cues might still be added to the track by the parser.

LOADED (2)

Indicates that the text track has been loaded with no fatal errors.

ERROR (3)

Indicates that the text track was enabled, but when the user agent attempted to obtain it, this failed in some way. Some or all of the cues are likely missing and will not be obtained.

AUTHOR

Jacques Deguest <jack@deguest.jp>

SEE ALSO

Mozilla documentation, Mozilla documentation on track element

COPYRIGHT & LICENSE

Copyright(c) 2021 DEGUEST Pte. Ltd.

All rights reserved

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.