HTML::O...dioTrack(3)

πŸ“¦ version 0.6.0, in alpine 3.24

πŸ’– NAME πŸ’–

okay so this is the HTML::Object::DOM::AudioTrack(3) page from User Contributed Perl Documentation β€” the HTML Object DOM AudioTrack Class. It’s giving β€œone single audio track from an HTML media element” main character energy, and honestly? obsessed. πŸ’…

✨ SYNOPSIS ✨

Yep, load it up like this:

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

πŸŽ€ VERSION πŸŽ€

Version: v0.2.0. Small number, big track energy. 🫢

πŸ¦‹ DESCRIPTION πŸ¦‹

The AudioTrack interface represents a single audio track from one of the HTML media elements, <audio> or <video>. That’s literally the whole vibe β€” one track, doing its thing. 🎧

🌸 INHERITANCE 🌸

This class inherits through this whole lil chain, no cap:

        +-----------------------+     +---------------------------+     +-------------------------------+     +-------------------------------+
        | HTML::Object::Element | --> | HTML::Object::EventTarget | --> | HTML::Object::DOM::MediaTrack | --> | HTML::Object::DOM::AudioTrack |
        +-----------------------+     +---------------------------+     +-------------------------------+     +-------------------------------+

πŸ’… PROPERTIES πŸ’…

Inherits properties from its parent HTML::Object::DOM::MediaTrack. Here’s the lineup, bestie:

πŸ‘‘ enabled πŸ‘‘

A boolean value which controls whether or not the audio track’s sound is enabled. Setting this value to false mutes the track’s audio. Periodt β€” that’s the mute button energy. πŸ”‡

Example:

        sub swapCommentaryMain
        {
            my $videoElem = $doc->getElementById( 'main-video' );
            my $audioTrackMain;
            my $audioTrackCommentary;

            $videoElem->audioTracks->forEach(sub
            {
                my $track = shift( @_ );
                if( $track->kind == 'main' )
                {
                    $audioTrackMain = $track;
                }
                elsif( $track->kind == 'commentary' )
                {
                    $audioTrackCommentary = $track;
                }
            });

            if( $audioTrackMain && $audioTrackCommentary )
            {
                my $commentaryEnabled = $audioTrackCommentary->enabled;
                $audioTrackCommentary->enabled = $audioTrackMain->enabled;
                $audioTrackMain->enabled = $commentaryEnabled;
            }
        }

See also Mozilla documentation: https://developer.mozilla.org/en-US/docs/Web/API/AudioTrack/enabled

πŸ¦‹ id πŸ¦‹

A string which uniquely identifies the track within the media. This ID can be used to locate a specific track within an audio track list by calling "AudioTrackList".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. iykyk β€” it’s the track’s little name tag. 🏷️

See also Mozilla documentation: https://developer.mozilla.org/en-US/docs/Web/API/AudioTrack/id

🌈 kind 🌈

A string specifying the category into which the track falls. For example, the main audio track would have a kind of "main". Categorize it, slay it, label it. πŸ’«

See also Mozilla documentation: https://developer.mozilla.org/en-US/docs/Web/API/AudioTrack/kind

πŸŽ€ label πŸŽ€

A string providing a human-readable label for the track. For example, an audio commentary track for a movie might have a label of "Commentary with director John Q. Public and actors John Doe and Jane Eod." This string is empty if no label is provided. Very β€œtell me what you are” of it. πŸ’–

Example:

        use Module::Generic::Array;
        sub getTrackList
        {
            my $el = shift( @_ );
            my $trackList = Module::Generic::Array->new;
            my $wantedKinds = [
                "main", "alternative", "main-desc", "translation", "commentary"
            ];

            $el->audioTracks->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: https://developer.mozilla.org/en-US/docs/Web/API/AudioTrack/label

🌍 language 🌍

A string specifying the audio 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 "pt-BR". It’s giving global citizen, fr fr. πŸ—£οΈ

Example:

        use Module::Generic::Array;
        sub getAvailableLanguages
        {
            my $el = shift( @_ );
            my $trackList = Module::Generic::Array->new;
            my $wantedKinds = [
                "main", "translation"
            ];

            $el->audioTracks->forEach(sub
            {
                my $track = shift( @_ );
                if( $wantedKinds->includes( $track->kind ) )
                {
                    $trackList->push({
                        id => $track->id,
                        kind => $track->kind,
                        language => $track->language
                    });
                }
            });
            return( $trackList );
        }

See also Mozilla documentation: https://developer.mozilla.org/en-US/docs/Web/API/AudioTrack/language

🧚 sourceBuffer 🧚

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. So if it’s not from a SourceBuffer, it’s lowkey a mystery origin story. 🫧

See also Mozilla documentation: https://developer.mozilla.org/en-US/docs/Web/API/AudioTrack/sourceBuffer

πŸ”₯ METHODS πŸ”₯

Inherits methods from its parent HTML::Object::DOM::MediaTrack. That’s the tea, bestie. 🍡

⭐ EXAMPLE ⭐

Okay this example is a whole lil sound-effects moment, and it ate:

        use feature 'signatures';
        my $sfx = HTML::Object::DOM::Element::Audio->new( 'sfx.wav' );
        my $sounds = $sfx->addTextTrack( 'metadata' );

        # add sounds we care about
        sub addFX( $start, $end, $name )
        {
            my $cue = HTML::Object::DOM::VTTCue->new( $start, $end, '' );
            $cue->id = $name;
            $cue->pauseOnExit = 1; # true
            $sounds->addCue( $cue );
        }
        addFX( 12.783, 13.612, 'dog bark' );
        addFX( 13.612, 15.091, 'kitten mew' );

        sub playSound( $id )
        {
            $sfx->currentTime = $sounds->getCueById( $id )->startTime;
            $sfx->play();
        }

        # play a bark as soon as we can
        $sfx->oncanplaythrough = sub
        {
            playSound( 'dog bark' );
        }
        # meow when the user tries to leave,
        # and have the browser ask them to stay
        $doc->onbeforeunload = sub
        {
            my $e = shift( @_ );
            playSound( 'kitten mew' );
            $e->preventDefault();
        }

πŸ‘‘ AUTHOR πŸ‘‘

Jacques Deguest <jack@deguest.jp> β€” author icon, no cap. πŸ’Œ

🌟 SEE ALSO 🌟

Mozilla documentation: https://developer.mozilla.org/en-US/docs/Web/API/AudioTrack

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.


That’s the whole page, bestie. Source/version/date vibes: perl v5.42.2, 2026-02-15. Mwah πŸ’‹

πŸ“¦ where this page comes from