NAME
HTML::Object::DOM::VideoTrackList - HTML Object DOM VideoTrackList Class
SYNOPSIS
use HTML::Object::DOM::VideoTrackList;
my $list = HTML::Object::DOM::VideoTrackList->new ||
die( HTML::Object::DOM::VideoTrackList->error, "\n" );
VERSION
v0.2.0
DESCRIPTION
The VideoTrackList
interface is used to represent a list of the video tracks contained within a <video> element, with each track represented by a separate VideoTrack
object in the list.
It inherits from HTML::Object::EventTarget.
INHERITANCE
+-----------------------+ +---------------------------+ +-------------------------+ +-----------------------------------+
| HTML::Object::Element | --> | HTML::Object::EventTarget | --> | HTML::Object::DOM::List | --> | HTML::Object::DOM::VideoTrackList |
+-----------------------+ +---------------------------+ +-------------------------+ +-----------------------------------+
PROPERTIES
Inherits properties from its parent HTML::Object::DOM::List
length
The number of tracks in the list.
Example:
my $videoElem = $doc->querySelector( 'video' );
my $numVideoTracks = 0;
if( $videoElem->videoTracks )
{
$numVideoTracks = $videoElem->videoTracks->length;
}
See also Mozilla documentation
selectedIndex
Sets or gets a number. Under perl, this is not set automatically. It is up to you to set this to whatever number you see fit.
Under JavaScript, this is the index of the currently selected track, if any, or −1 otherwise.
It returns the number as an object
See also Mozilla documentation
selectedindex
Alias for "selectedIndex"
METHODS
Inherits methods from its parent HTML::Object::DOM::List
addEventListener
Calls and returns the value from addEventListenerCalls in the ancestor class HTML::Object::DOM::List
children
Returns an array object of this element's children.
forEach
This is an alias for "foreach" in Module::Generic::Array
getTrackById
Returns the VideoTrack
found within the VideoTrackList
whose id matches the specified string. If no match is found, undef
is returned.
Example:
my $theTrack = $VideoTrackList->getTrackById( $id );
See also Mozilla documentation
EVENTS
Events fired are of class HTML::Object::DOM::TrackEvent
addtrack
Fired when a new video track has been added to the media element. Also available via the "onaddtrack" property.
Example:
my $videoElement = $doc->querySelector('video');
$videoElement->videoTracks->addEventListener( addtrack => sub
{
my $event = shift( @_ );
say( "Video track: ", $event->track->label, " added" );
});
my $videoElement = $doc->querySelector('video');
$videoElement->videoTracks->onaddtrack = sub
{
my $event = shift( @_ );
say( "Video track: ", $event->track->label, " added" );
};
See also Mozilla documentation
change
Fired when a video track has been made active or inactive. Also available via the "onchange" property.
Example:
my $videoElement = $doc->querySelector( 'video' );
$videoElement->videoTracks->addEventListener( change => sub
{
say( "'", $event->type, "' event fired" );
});
# changing the value of 'selected' will trigger the 'change' event
my $toggleTrackButton = $doc->querySelector( '.toggle-$track' );
$toggleTrackButton->addEventListener( click => sub
{
my $track = $videoElement->videoTracks->[0];
$track->selected = !$track->selected;
});
my $videoElement = $doc->querySelector( 'video' );
$videoElement->videoTracks->onchange = sub
{
my $event = shift( @_ );
say( "'", $event->type, "' event fired" );
};
# changing the value of 'selected' will trigger the 'change' event
my $toggleTrackButton = $doc->querySelector( '.toggle-$track' );
$toggleTrackButton->addEventListener( click => sub
{
my $track = $videoElement->videoTracks->[0];
$track->selected = !$track->selected;
});
See also Mozilla documentation
removetrack
Fired when a new video track has been removed from the media element. Also available via the "onremovetrack" property.
Example:
my $videoElement = $doc->querySelector( 'video' );
$videoElement->videoTracks->addEventListener( removetrack => sub
{
my $event = shift( @_ );
say( "Video track: ", $event->track->label, " removed" );
});
my $videoElement = $doc->querySelector( 'video' );
$videoElement->videoTracks->onremovetrack = sub
{
my $event = shift( @_ );
say( "Video 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 video track has been added to the media element.
Example:
$doc->querySelector('video')->videoTracks->onaddtrack = sub
{
my $event = shift( @_ );
addToTrackList( $event->track );
};
See also Mozilla documentation
onchange
An event handler to be called when the change event occurs — that is, when the value of the selected property for a track has changed, due to the track being made active or inactive.
Example:
my $trackList = $doc->querySelector( 'video' )->videoTracks;
$trackList->onchange = sub
{
my $event = shift( @_ );
$trackList->forEach(sub
{
my $track = shift( @_ );
updateTrackSelectedButton( $track->id, $track->selected );
});
};
See also Mozilla documentation
onremovetrack
An event handler to call when the removetrack event is sent, indicating that a video track has been removed from the media element.
Example:
$doc->querySelector( 'my-video' )->videoTracks->onremovetrack = sub
{
$myTrackCount = $doc->querySelector( 'my-video' )->videoTracks->length;
};
See also Mozilla documentation
AUTHOR
Jacques Deguest <jack@deguest.jp>
SEE ALSO
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.