HTML::Object::DOM::VideoTrackList - HTML Object DOM VideoTrackList Class
use HTML::Object::DOM::VideoTrackList; my $list = HTML::Object::DOM::VideoTrackList->new || die( HTML::Object::DOM::VideoTrackList->error, "\n" );
v0.2.0
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.
VideoTrackList
VideoTrack
It inherits from HTML::Object::EventTarget.
+-----------------------+ +---------------------------+ +-------------------------+ +-----------------------------------+ | HTML::Object::Element | --> | HTML::Object::EventTarget | --> | HTML::Object::DOM::List | --> | HTML::Object::DOM::VideoTrackList | +-----------------------+ +---------------------------+ +-------------------------+ +-----------------------------------+
Inherits properties from its parent HTML::Object::DOM::List
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
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
Alias for "selectedIndex"
Inherits methods from its parent HTML::Object::DOM::List
Calls and returns the value from addEventListenerCalls in the ancestor class HTML::Object::DOM::List
Returns an array object of this element's children.
This is an alias for "foreach" in Module::Generic::Array
Returns the VideoTrack found within the VideoTrackList whose id matches the specified string. If no match is found, undef is returned.
undef
my $theTrack = $VideoTrackList->getTrackById( $id );
Events fired are of class HTML::Object::DOM::TrackEvent
Fired when a new video track has been added to the media element. Also available via the "onaddtrack" property.
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" ); };
Fired when a video track has been made active or inactive. Also available via the "onchange" property.
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; });
Fired when a new video track has been removed from the media element. Also available via the "onremovetrack" property.
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" ); };
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.
$doc->querySelector('video')->videoTracks->onaddtrack = sub { my $event = shift( @_ ); addToTrackList( $event->track ); };
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.
my $trackList = $doc->querySelector( 'video' )->videoTracks; $trackList->onchange = sub { my $event = shift( @_ ); $trackList->forEach(sub { my $track = shift( @_ ); updateTrackSelectedButton( $track->id, $track->selected ); }); };
An event handler to call when the removetrack event is sent, indicating that a video track has been removed from the media element.
$doc->querySelector( 'my-video' )->videoTracks->onremovetrack = sub { $myTrackCount = $doc->querySelector( 'my-video' )->videoTracks->length; };
Jacques Deguest <jack@deguest.jp>
Mozilla documentation
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.
To install HTML::Object, copy and paste the appropriate command in to your terminal.
cpanm
cpanm HTML::Object
CPAN shell
perl -MCPAN -e shell install HTML::Object
For more information on module installation, please visit the detailed CPAN module installation guide.