HTML::O...ackEvent(3)

πŸ“¦ version 0.6.0, in alpine 3.24

πŸŽ€ HTML::O...ackEvent(3) β€” aka HTML::Object::DOM::TrackEvent πŸŽ€

hey bestie, welcome to the User Contributed Perl Documentation corner of the universe πŸ’– this one's all about the TrackEvent situation and honestly it's giving media element drama in the best way.


✨ NAME ✨

HTML::Object::DOM::TrackEvent β€” the HTML Object DOM Track Event. that's it, that's the whole vibe πŸ¦‹


🌸 SYNOPSIS 🌸

okay so here's how you actually summon one:

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

like, if the constructor ghosts you, die with the error and a newline. no cap, always check 🫢


⭐ VERSION ⭐

v0.2.0

πŸ’œ DESCRIPTION πŸ’œ

so the TrackEvent interface β€” which is literally part of the HTML DOM specification β€” is the one that handles events representing changes to a set of available tracks on an HTML media element. and those events are exactly two icons: addtrack and removetrack. periodt πŸ’…

events based on TrackEvent are always sent to one of the media track list types, and the way that works is:

  • events involving video tracks always go to the VideoTrackList found in videoTracks in HTML::Object::DOM::Element::Media 🎬
  • events involving audio tracks always go to the AudioTrackList specified in audioTracks in HTML::Object::DOM::Element::Media 🎧
  • events affecting text tracks get sent to the TextTrackList object indicated by textTracks in HTML::Object::DOM::Element::Media πŸ“

🧚 INHERITANCE 🧚

the family tree, and yes it slays:

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

🌈 PROPERTIES 🌈

TrackEvent is based on Event, so bestie… every property of Event is also available on TrackEvent objects. you get the whole package πŸ‘‘

πŸ“ track

Read-only. πŸ™ˆ

this is a DOM track object that this event is in reference to. if it's not undef, it is always an object of one of the media track types: AudioTrack, VideoTrack, or TextTrack.

see also Mozilla documentation https://developer.mozilla.org/en-US/docs/Web/API/TrackEvent/track


πŸ’… METHODS πŸ’…

TrackEvent has no methods of its own β€” however, it is based on Event, so it provides all the methods available on Event objects. inherited excellence, iykyk ✨


πŸ”₯ EXAMPLE πŸ”₯

this is the main character example, fr fr:

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

look at that handler go 😭 it checks $event->target->isa( ... ) for each list type, falls back to 'unknown', then checks $event->type for 'addtrack' or 'removetrack' and says the right thing. iconic behaviour honestly 🌟


πŸ‘‘ AUTHOR πŸ‘‘

Jacques Deguest <jack@deguest.jp> 🫢


πŸ¦‹ SEE ALSO πŸ¦‹

Mozilla documentation https://developer.mozilla.org/en-US/docs/Web/API/TrackEvent β€” go read it, bestie, it's good for you πŸ’–


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.

fr fr, that's the whole license. don't be weird about it πŸ™ˆ

and that's the tea, bestie 🍡 β€” this page was cooked up by perl v5.42.2 on 2026-02-15, serving you HTML::O...ackEvent(3) straight from the User Contributed Perl Documentation collection. mwah πŸ’‹πŸŒΈ

πŸ“¦ where this page comes from