HTML::Object::DOM::VideoTrack - HTML Object DOM VideoTrack Class
use HTML::Object::DOM::VideoTrack; my $track = HTML::Object::DOM::VideoTrack->new || die( HTML::Object::DOM::VideoTrack->error, "\n" );
v0.2.0
The VideoTrack interface represents a single video track from a <video> element.
VideoTrack
To get a VideoTrack for a given media element, use the element's videoTracks property, which returns a VideoTrackList object from which you can get the individual tracks contained in the media:
my $el = $doc->querySelector('video'); my $tracks = $el->videoTracks; my $firstTrack = $tracks->[0];
Scan through all of the media's video tracks, activating the first video track that is in the user's preferred language (taken from a variable userLanguage).
for( my $i = 0; $i < $tracks->length; $i++ ) { if( $tracks->[$i]->language eq $userLanguage ) { $tracks->[$i]->selected = 1; # true last; } });
+-----------------------+ +---------------------------+ +-------------------------------+ | HTML::Object::Element | --> | HTML::Object::EventTarget | --> | HTML::Object::DOM::VideoTrack | +-----------------------+ +---------------------------+ +-------------------------------+
Inherits properties from its parent HTML::Object::EventTarget
Sets or gets a string which uniquely identifies the track within the media. This ID can be used to locate a specific track within a video track list by calling VideoTrackList.getTrackById(). The ID can also be used as the fragment part of the URL if the media supports seeking by media fragment per the Media Fragments URI specification.
VideoTrackList
Returns the ID as a scalar object
See also Mozilla documentation
A string specifying the category into which the track falls. For example, the main video track would have a kind of main.
main
A string providing a human-readable label for the track. For example, a track whose kind is sign might have a label of "A sign-language interpretation". This string is empty if no label is provided.
sign
Example:
use Module::Generic::Array; sub getTrackList { my $el = shift( @_ ); my $trackList = Module::Generic::Array->new; my $wantedKinds = [qw( main alternative commentary )]; $el->videoTracks->forEach(sub { my $track = shift( @_ ); if( $wantedKinds->includes( $track->kind ) ) { $trackList->push({ id => $track->id, kind => $track->kind, label => $track->label }); } }); return( $trackList ); }
A string specifying the video track's primary language, or an empty string if unknown. The language is specified as a BCP 47 (RFC 5646) language code, such as en-US or ja-JP.
en-US
ja-JP
Returns the language as a scalar object
A boolean value which controls whether or not the video track is active. Only a single video track can be active at any given time, so setting this property to true for one track while another track is active will make that other track inactive.
This always returns undef under perl.
undef
Normally, under JavaScript, this is the SourceBuffer that created the track. Returns undef if the track was not created by a SourceBuffer or the SourceBuffer has been removed from the MediaSource.sourceBuffers attribute of its parent media source.
SourceBuffer
MediaSource.sourceBuffers
Inherits methods from its parent HTML::Object::EventTarget
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.