API
Audio Tracks
In this section, we'll look at how audio tracks can be tracked and configured with Vidstack Player.
Audio tracks are currently only supported by the HLS Provider.
Tracks List
The read-only audioTracks
property on the player returns a AudioTrackList
object that contains AudioTrack
objects
Similar to text tracks, the returned list is live; that is, as tracks are added to and removed from the player, the list's contents change dynamically. Once you have a reference to the list, you can monitor it for changes to detect when new tracks are added or existing ones are removed by listening to list events.
The AudioTrack
interface contains the following shape:
Selecting
The selected
property can be used to set the current audio track like so:
Once set, the underlying provider will update the audio track.
List Events
The AudioTrackList
object is an EventTarget
which dispatches the following events:
add
: Fired when an audio track has been added to the list.remove
: Fired when an audio track has been removed from the list.change
: Fired when the selected audio track changes.
Media Store
The following audio track related properties are available on the media store:
audioTracks
: An array containing the current list ofAudioTrack
objects.audioTrack
: The currentAudioTrack
object ornull
if none is available.
Media Remote
The changeAudioTrack
method on the media remote can be used to dispatch requests to update the current audio track like so:
Media Events
The following audio track related events are available on the player:
audio-tracks-change
: Fired when the available list of audio tracks has changed.audio-track-change
: Fired when the selected audio track has changed.