The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

HTML::Object::DOM::TrackEvent - HTML Object DOM Track Event

SYNOPSIS

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

VERSION

    v0.2.0

DESCRIPTION

The TrackEvent interface, which is part of the HTML DOM specification, is used for events which represent changes to a set of available tracks on an HTML media element; these events are addtrack and removetrack.

Events based on TrackEvent are always sent to one of the media track list types:

INHERITANCE

    +---------------------+     +-------------------------------+
    | HTML::Object::Event | --> | HTML::Object::DOM::TrackEvent |
    +---------------------+     +-------------------------------+

PROPERTIES

TrackEvent is based on Event, so properties of Event are also available on TrackEvent objects.

track

Read-only.

This is a DOM track object this event is in reference to. If not undef, this is always an object of one of the media track types: AudioTrack, VideoTrack, or TextTrack).

See also Mozilla documentation

METHODS

TrackEvent has no methods of its own; however, it is based on Event, so it provides the methods available on Event objects.

EXAMPLE

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

    $videoElem->videoTracks->addEventListener( 'addtrack', \&handleTrackEvent, { capture => 0 });
    $videoElem->videoTracks->addEventListener( 'removetrack', \&handleTrackEvent, { capture => 0 });
    $videoElem->audioTracks->addEventListener( 'addtrack', \&handleTrackEvent, { capture => 0 });
    $videoElem->audioTracks->addEventListener( 'removetrack', \&handleTrackEvent, { capture => 0 });
    $videoElem->textTracks->addEventListener( 'addtrack', \&handleTrackEvent, { capture => 0 });
    $videoElem->textTracks->addEventListener( 'removetrack', \&handleTrackEvent, { capture => 0 });

    sub handleTrackEvent
    {
        my $event = shift( @_ );
        my $trackKind;

        if( $event->target->isa( 'HTML::Object::DOM::VideoTrackList' ) )
        {
            $trackKind = 'video';
        }
        elsif( $event->target->isa( 'HTML::Object::DOM::AudioTrackList' ) )
        {
            $trackKind = 'audio';
        }
        elsif( $event->target->isa( 'HTML::Object::DOM::TextTrackList' ) )
        {
            $trackKind = 'text';
        }
        else
        {
            $trackKind = 'unknown';
        }

        my $type = $event->type;
        if( $type eq 'addtrack' )
        {
            say( "Added a $trackKind track" );
        }
        elsif( $type eq 'removetrack' )
        {
            say( "Removed a $trackKind track" );
        }
    }

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.