The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

HTML::Object::DOM::VideoTrack - HTML Object DOM VideoTrack Class

SYNOPSIS

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

VERSION

    v0.2.0

DESCRIPTION

The VideoTrack interface represents a single video track from a <video> element.

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;
        }
    });

INHERITANCE

    +-----------------------+     +---------------------------+     +-------------------------------+
    | HTML::Object::Element | --> | HTML::Object::EventTarget | --> | HTML::Object::DOM::VideoTrack |
    +-----------------------+     +---------------------------+     +-------------------------------+

PROPERTIES

Inherits properties from its parent HTML::Object::EventTarget

id

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.

Returns the ID as a scalar object

See also Mozilla documentation

kind

A string specifying the category into which the track falls. For example, the main video track would have a kind of main.

See also Mozilla documentation

label

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.

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 );
    }

See also Mozilla documentation

language

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.

Returns the language as a scalar object

See also Mozilla documentation

selected

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.

See also Mozilla documentation

sourceBuffer

This always returns undef under perl.

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.

See also Mozilla documentation

METHODS

Inherits methods from its parent HTML::Object::EventTarget

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.