HTML::O...dioTrack(3)
π 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 & 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.
Thatβs the whole page, bestie. Source/version/date vibes: perl v5.42.2, 2026-02-15. Mwah π
π¦ where this page comes from
- alpine 3.24: perl-html-object-doc 0.6.0-r1 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms