static updateAudioTracks(tracks, langMenu, onTrackSelected, updateChosen,
      currentSelectionElement, localization, trackLabelFormat,
      showAudioChannelCountVariants, showAudioCodec) {
    const LocIds = shaka.ui.Locales.Ids;

    // TODO: Do the benefits of having this common code in a method still
    // outweigh the complexity of the parameter list?
    const selectedTrack = tracks.find((track) => {
      return track.active == true;
    });

    /** @type {!Map<string, !Set<string>>} */
    const codecsByLanguage = new Map();
    for (const track of tracks) {
      if (!track.codecs) {
        continue;
      }
      if (!codecsByLanguage.has(track.language)) {
        codecsByLanguage.set(track.language, new Set());
      }
      codecsByLanguage.get(track.language).add(
          shaka.util.MimeUtils.getNormalizedCodec(track.codecs));
    }
    const hasDifferentAudioCodecs = (language) =>
      codecsByLanguage.has(language) && codecsByLanguage.get(language).size > 1;

    // Remove old tracks
    // 1. Save the back to menu button
    const backButton = shaka.ui.Utils.getFirstDescendantWithClassName(
        langMenu, 'shaka-back-to-overflow-button');

    // 2. Remove everything
    shaka.util.Dom.removeAllChildren(langMenu);

    // 3. Add the backTo Menu button back
    langMenu.appendChild(backButton);

    // 4. Figure out which languages have multiple roles.
    const getRolesString = (track) => {
      return track.roles.join(', ');
    };

    const getCombination = (language, rolesString, label, channelsCount,
        audioCodec, spatialAudio) => {
      const keys = [
        language,
        rolesString,
        spatialAudio,
      ];
      if (showAudioChannelCountVariants && channelsCount != null) {
        keys.push(channelsCount);
      }
      if (showAudioCodec && hasDifferentAudioCodecs(language) && audioCodec) {
        keys.push(audioCodec);
      }
      if (label &&
          trackLabelFormat == shaka.ui.Overlay.TrackLabelFormat.LABEL) {
        keys.push(label);
      }
      return keys.join(': ');
    };

    const getChannelsCountName = (channelsCount) => {
      let name = '';
      if (channelsCount >= 5) {
        name = ' ' + localization.resolve(LocIds.SURROUND);
      }
      return name;
    };

    const getAudioCodecName = (audioCodec) => {
      let name = '';
      if (audioCodec == 'aac') {
        name = 'AAC';
      } else if (audioCodec === 'ac-3') {
        name = 'Dolby';
      } else if (audioCodec === 'ec-3') {
        name = 'DD+';
      } else if (audioCodec === 'ac-4') {
        name = 'Dolby AC-4';
      } else if (audioCodec === 'opus') {
        name = 'Opus';
      } else if (audioCodec === 'flac') {
        name = 'fLaC';
      }
      return name ? ' ' + name : name;
    };

    // 5. Add new buttons
    /** @type {!Set<string>} */
    const combinationsMade = new Set();
    const selectedCombination = selectedTrack ? getCombination(
        selectedTrack.language, getRolesString(selectedTrack),
        selectedTrack.label, selectedTrack.channelsCount,
        selectedTrack.codecs &&
        shaka.util.MimeUtils.getNormalizedCodec(selectedTrack.codecs),
        selectedTrack.spatialAudio) : '';

    for (const track of tracks) {
      const language = track.language;
      const rolesString = getRolesString(track);
      const label = track.label;
      const channelsCount = track.channelsCount;
      const audioCodec = track.codecs &&
          shaka.util.MimeUtils.getNormalizedCodec(track.codecs);
      const spatialAudio = track.spatialAudio;
      const combinationName =
          getCombination(language, rolesString, label, channelsCount,
              audioCodec, spatialAudio);
      if (combinationsMade.has(combinationName)) {
        continue;
      }
      combinationsMade.add(combinationName);

      const button = shaka.util.Dom.createButton();
      button.addEventListener('click', () => {
        onTrackSelected(track);
      });

      const span = shaka.util.Dom.createHTMLElement('span');
      button.appendChild(span);

      span.textContent =
          shaka.ui.LanguageUtils.getLanguageName(language, localization);
      let basicInfo = '';
      if (showAudioCodec && showAudioChannelCountVariants &&
          spatialAudio && (audioCodec == 'ec-3' || audioCodec == 'ac-4')) {
        basicInfo += ' Dolby Atmos';
      } else {
        if (showAudioCodec && hasDifferentAudioCodecs(language)) {
          basicInfo += getAudioCodecName(audioCodec);
        }
        if (showAudioChannelCountVariants) {
          basicInfo += getChannelsCountName(channelsCount);
        }
      }
      switch (trackLabelFormat) {
        case shaka.ui.Overlay.TrackLabelFormat.LANGUAGE:
          span.textContent += basicInfo;
          break;
        case shaka.ui.Overlay.TrackLabelFormat.ROLE:
          span.textContent += basicInfo;
          if (!rolesString) {
            // Fallback behavior. This probably shouldn't happen.
            shaka.log.alwaysWarn('Track #' + JSON.stringify(track) +
                ' does not have a role, but the UI is configured to ' +
                'only show role.');
            span.textContent = '?';
          } else {
            span.textContent = rolesString;
          }
          break;
        case shaka.ui.Overlay.TrackLabelFormat.LANGUAGE_ROLE:
          span.textContent += basicInfo;
          if (rolesString) {
            span.textContent += ': ' + rolesString;
          }
          break;
        case shaka.ui.Overlay.TrackLabelFormat.LABEL:
          if (label) {
            span.textContent = label;
          } else {
            // Fallback behavior. This probably shouldn't happen.
            shaka.log.alwaysWarn('Track #' + JSON.stringify(track) +
                ' does not have a label, but the UI is configured to ' +
                'only show labels.');
            span.textContent = '?';
          }
          break;
      }

      if (updateChosen && (combinationName == selectedCombination)) {
        button.appendChild(shaka.ui.Utils.checkmarkIcon());
        span.classList.add('shaka-chosen-item');
        button.ariaSelected = 'true';
        currentSelectionElement.textContent = span.textContent;
      }
      langMenu.appendChild(button);
    }
  }
@param {!Array<shaka.extern.AudioTrack>} tracks
@param {!HTMLElement} langMenu
@param {function(!shaka.extern.AudioTrack)} onTrackSelected
@param {boolean} updateChosen
@param {!HTMLElement} currentSelectionElement
@param {shaka.ui.Localization} localization
@param {shaka.ui.Overlay.TrackLabelFormat} trackLabelFormat
@param {boolean} showAudioChannelCountVariants
@param {boolean} showAudioCodec