I modified my audio track switching code based on your suggestions, but I am still facing the same issue. I am trying to change the audio track for live channels. The log shows that after changing the audio track, the selected audio’s enabled
property is set to true
. However, the video continues playing with the default audio, and after a few seconds, the video gets stuck.
I am using the following code to change the audio track:
var newIndex = document.getElementById(foc${rightfocus}_${mainfocus}
);
var spanIndex = parseInt(newIndex.querySelector(“span”).innerHTML);
var audioTracks = document.getElementById(‘myVideo’).audioTracks;
for (var i = 0; i < audioTracks.length; i++) {
if (i === spanIndex) {
audioTracks[i].enabled = true;
} else {
audioTracks[i].enabled = false;
}
console.log(audioTracks);
}
Here, spanIndex
represents the selected audio track ID, and I am trying to switch the audio track based on it.
Is this code work for live channels