Skip to content

Commit

Permalink
feat(ui): Allow showing track labels in UI
Browse files Browse the repository at this point in the history
Instead of language, role, or both, it is sometimes useful for an
application to show the "label" field of the corresponding "Track"
object.

Closes shaka-project#2927

Change-Id: Ifc2fa8137bc73ec704443c6071f102805f70dc3d
  • Loading branch information
joeyparrish committed Oct 20, 2020
1 parent 3eca747 commit c7d0ce9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ui/externs/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ shaka.extern.UIVolumeBarColors;
* audio variant selection.
* LANGUAGE means that only the language of the item is shown.
* ROLE means that only the role of the item is shown.
* LANGUAGE_ROLE means both are shown, or just language if there is no role.
* LANGUAGE_ROLE means both language and role are shown, or just language if
* there is no role.
* LABEL means the non-standard DASH "label" attribute or the HLS "NAME"
* attribute are shown.
* Defaults to LANGUAGE.
* @property {number} fadeDelay
* The delay (in seconds) before fading out the controls once the user stops
Expand Down
10 changes: 10 additions & 0 deletions ui/language_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ shaka.ui.LanguageUtils = class {
span.textContent += ': ' + rolesString;
}
break;
case shaka.ui.TrackLabelFormat.LABEL:
if (track.label) {
span.textContent = track.label;
} else {
// Fallback behavior. This probably shouldn't happen.
shaka.log.alwaysWarn('Track #' + track.id + ' does not have a ' +
'label, but the UI is configured to only show labels.');
span.textContent = '?';
}
break;
}

if (updateChosen && (combinationName == selectedCombination)) {
Expand Down
1 change: 1 addition & 0 deletions ui/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ shaka.ui.TrackLabelFormat = {
'LANGUAGE': 0,
'ROLE': 1,
'LANGUAGE_ROLE': 2,
'LABEL': 3,
};

/**
Expand Down

0 comments on commit c7d0ce9

Please sign in to comment.