I’m developing an IPTV application that streams live channels using HLS with the H.265 codec. Some of these channels support multiple audio tracks, and I’ve implemented an option for users to switch between the available audio tracks during playback.
To switch the audio track, I’m using the following code:
var audioTracks = video.audioTracks;
for (var i = 0; i < audioTracks.length; i++) {
audioTracks[i].enabled = (i === spanText);
console.log(Set track ${i} enabled=${audioTracks[i].enabled}
);
}
Here, spanText
represents the selected audio track index. However, this method does not seem to work as expected—the audio track does not change.
How can I properly switch audio tracks for a live HLS stream in this scenario?