[AVFoundation] Error in selection audible mediagroup - HLS.

Hi everybody,

I think I have encountered a problem when selecting the new audible mediagroup in the hls. I will explain the casuistry below:

The hls manifest contains 2-3 audio tracks, which are parsed correctly by AVFoundation giving rise to the different audible mediagroups.

When we select a new audio track, we do it as the documentation says:

guard let item = currentPlayerItem,
        let mediaSelectionGroup = item.asset.mediaSelectionGroup(forMediaCharacteristic: .legible)
            else { return }

let selected = mediaSelectionGroup.options[index]
item.select(selected, in: mediaSelectionGroup)

So far everything works correctly, the problem is when switching audio tracks constantly and repeatedly. If we do this, the playback stays for a few seconds without any sound, it seems to be muted or laggy.

After investigating in Charles, we see that when repeating the process mentioned above, the audio track is requested correctly and the ts are returned correctly, but until the video is requested again and the next video ts is returned, the audio is not played. I attach a screenshot of charles so that it can be seen correctly:

In the selected part, you can see that the new audio track is requested and until avplayer does not ask again for the bitrate update, the audio does not play.

What could be happening? Is there anything in avfoundation that we can change so that it doesn't happen?

Thanks in advance,

Luis Martínez