NAME

HTML::Object::DOM::TextTrackList - HTML Object DOM Track List Class

SYNOPSIS

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

Getting a video element's text track list:

my $textTracks = $doc->querySelector( 'video' )->textTracks;

Monitoring track count changes:

$textTracks->onaddtrack = \&updateTrackCount;
$textTracks->onremovetrack = \&updateTrackCount;

sub updateTrackCount
{
    my $event = shift( @_ );
    my $trackCount = $textTracks->length;
    drawTrackCountIndicator( $trackCount );
}

VERSION

v0.2.0

DESCRIPTION

The TextTrackList interface is used to represent a list of the text tracks defined by the <track> element, with each track represented by a separate textTrack object in the list. It inherits from HTML::Object::EventTarget

INHERITANCE

+-----------------------+     +---------------------------+     +-------------------------+     +----------------------------------+
| HTML::Object::Element | --> | HTML::Object::EventTarget | --> | HTML::Object::DOM::List | --> | HTML::Object::DOM::TextTrackList |
+-----------------------+     +---------------------------+     +-------------------------+     +----------------------------------+

PROPERTIES

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

length

The number of tracks in the list.

Example:

my $media = $doc->querySelector( 'video, audio' );
my $numTextTracks = 0;

if( $media->textTracks )
{
    $numTextTracks = $media->textTracks->length;
}

See also Mozilla documentation

METHODS

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

addEventListener

Set a new event listener for the provided event type. See HTML::Object::EventTarget

children

Set or get an array object of elements.

forEach

Provided with a callback code reference and this will call it for each child element.

See "foreach" in Module::Generic::Array

getTrackById

Returns the TextTrack found within the TextTrackList whose id matches the specified string. If no match is found, undef is returned.

Example:

my $theTrack = $TextTrackList->getTrackById( $id );

See also Mozilla documentation

EVENTS

addtrack

Fired when a new text track has been added to the media element. Also available via the onaddtrack property.

Example:

my $mediaElement = $doc->querySelector( 'video, audio' );

$mediaElement->textTracks->addEventListener( addtrack => sub
{
    my $event = shift( @_ );
    say( "Text track: ", $event->track->label, " added" );
});

my $mediaElement = $doc->querySelector( 'video, audio' );

$mediaElement->textTracks->onaddtrack = sub
{
    my $event = shift( @_ );
    say( "Text track: ", $event->track->label, " added" );
};

See also Mozilla documentation

change

Fired when a text track has been made active or inactive. Also available via the onchange property.

Example:

my $mediaElement = $doc->querySelectorAll( 'video, audio' )->[0];
$mediaElement->textTracks->addEventListener( change => sub
{
    my $event = shift( @_ );
    say( "'", $event->type, "' event fired" );
});

my $mediaElement = $doc->querySelector( 'video, audio' );
$mediaElement->textTracks->onchange = sub
{
    say( "'", $event->type, "' event fired" );
};

See also Mozilla documentation

removetrack

Fired when a new text track has been removed from the media element. Also available via the onremovetrack property.

Example:

my $mediaElement = $doc->querySelector( 'video, audio' );

$mediaElement->textTracks->addEventListener( removetrack => sub
{
    my $event = shift( @_ );
    say( "Text track: ", $event->track->label, " removed" );
});

my $mediaElement = $doc->querySelector( 'video, audio' );

$mediaElement->textTracks->onremovetrack = sub
{
    my $event = shift( @_ );
    say( "Text track: ", $event->track->label, " removed" );
};

See also Mozilla documentation

EVENT HANDLERS

onaddtrack

An event handler to be called when the addtrack event is fired, indicating that a new text track has been added to the media element.

Example:

$doc->querySelector( 'video' )->textTracks->onaddtrack = sub
{
    my $event = shift( @_ );
    addToTrackList( $event->track );
};

See also Mozilla documentation

onchange

An event handler to be called when the change event occurs.

Example:

my $trackList = $doc->querySelector( 'video, audio' )->textTracks;

$trackList->onchange = sub
{
    my $event = shift( @_ );
     #.... do something
};

See also Mozilla documentation

onremovetrack

An event handler to call when the removetrack event is sent, indicating that a text track has been removed from the media element.

Example:

$doc->querySelectorAll( 'video, audio' )->[0].textTracks->onremovetrack = sub
{
    my $event = shift( @_ );
    myTrackCount = $doc->querySelectorAll( 'video, audio' )->[0]->textTracks->length;
};

See also Mozilla documentation

AUTHOR

Jacques Deguest <jack@deguest.jp>

SEE ALSO

Mozilla documentation

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.