Skip to content

Update track selection in PlayerView to show one entry per track group only #1666

Closed

Description

@JaroslavHerber

By default, if a m3u channel has subtitles, the exoplayer selects and displays automatically the first subtitle. Why not "off" by default?
There should be a method to turn off this default behavior, without hacking the DefaultTrackSelector.

Btw. I tried this, but the player still displays the first subtitle track by default. What am I missing?

DefaultTrackSelector oTrackSelector = new DefaultTrackSelector(this);

DefaultTrackSelector.Parameters parameters = oTrackSelector
	.buildUponParameters()
	.setPreferredTextLanguage(null) // This ensures no text track is selected by default
	.setSelectUndeterminedTextLanguage(false) // Do not select any text track if the language is undetermined
	.build();

oTrackSelector.setParameters(parameters);

oPlayer = new ExoPlayer.Builder(this, oRenderersFactory)
	.setTrackSelector(oTrackSelector)
	.setMediaSourceFactory(oMediaSourceFactory)
	.build();

Activity

  1. changed the title [-]We need a setting for default subtitle behaviour[/-] [+]We need a setting for default subtitle behavior[/+] on Aug 29, 2024
  2. tonihei commented on Aug 29, 2024

    @tonihei
    Collaborator

    It's likely that the subtitle you see is 'on' by default because it's marked as 'forced' or similar by the media itself and turning it on is following the spec. If you share the stream you are trying to play, we can have a look and see if there is a setting to turn off the behavior. It's likely https://developer.android.com/reference/androidx/media3/common/TrackSelectionParameters.Builder#setIgnoredTextSelectionFlags(int) can help with ignoring the forced flags.

  3. self-assigned this
    on Aug 29, 2024
  4. JaroslavHerber commented on Aug 29, 2024

    @JaroslavHerber
    ContributorAuthor

    Thank you very much :)

    Here is the public stream:

    #EXTINF:-1 tvg-id="HR.de" tvg-name="HRFernsehen.de" status="timeout" group-title="HR",hr-fernsehen (1080p)
    https://hrhls.akamaized.net/hls/live/2024525/hrhls/index.m3u8
    

    (The video might show geo-blocking hint, but the subtitles are still working in this channel)

    I also noticed, that every track (subtitles or audio) are displayed twice or more in the selector. The audio tracks are confusing:
    image

  5. tonihei commented on Aug 29, 2024

    @tonihei
    Collaborator

    Thanks for sharing the stream.

    The HLS playlist has DEFAULT=YES for both subtitle tracks and according to the HLS spec:
    "If the value is YES, then the client SHOULD play this Rendition of the content in the absence of information from the user indicating a different choice."

    So selecting this track by default without user interaction is technically correct. If you don't want this and control the content creation, I'd suggest to fix the playlist file itself. Using TrackSelectionParameters.Builder.setIgnoredTextSelectionFlags(C.SELECTION_FLAG_DEFAULT) also works as expected by ignoring this flag in the media.

    I also noticed, that every track (subtitles or audio) are displayed twice or more in the selector. The audio tracks are confusing

    There seem to be a few things going on here:

    • I think the two text tracks should be put into one adaptive group in ExoPlayer, but are currently treated separately.
    • The audio selection dialog in PlayerView lists adaptive formats separately instead of as a group.
    • The audio track name provider is not using the NAME tag provided by the playlist that help to distinguish them (e.g. "Klare Sprache")

    I'll mark this issue as a bug for these issues, the main question around showing the subtitles by default is working as intended for this playlist as explained above.

  6. changed the title [-]We need a setting for default subtitle behavior[/-] [+]Track display issues in PlayerView with adaptive audio and text tracks from HLS[/+] on Aug 29, 2024
  7. JaroslavHerber commented on Nov 4, 2024

    @JaroslavHerber
    ContributorAuthor
    • The audio track name provider is not using the NAME tag provided by the playlist that help to distinguish them (e.g. "Klare Sprache")

    I think the issue here is the priority of languageAndRole over Label in DefaultTrackNameProvider.buildLanguageOrLabelString(Format format)

    private String buildLanguageOrLabelString(Format format) {
        String languageAndRole =
            joinWithSeparator(buildLanguageString(format), buildRoleString(format));
        return TextUtils.isEmpty(languageAndRole) ? buildLabelString(format) : languageAndRole;
      }
    

    So the label is only used if languageAndRole is empty. Maybe we can mix languageAndRole and Label?
    The current logic with languageAndRole is sure the best choice if the channel offers different language-AudioTracks. But in the upper case we have just one language (German) with some variation-AudioTracks.

    If me mix them, we can get this:
    image

    Here is the code:

    private String buildLanguageOrLabelString(Format format) {
        String Label = buildLabelString(format);
        String Language = buildLanguageString(format);
        String Role = buildRoleString(format);
    
        String languageAndRole = Role;
        if( !Label.equals(Language) ) {
          languageAndRole = joinWithSeparator(Language, Role);
        }
    
        String returnString = Label;
        if( !TextUtils.isEmpty(languageAndRole) ) {
          returnString += " (" + languageAndRole + ")";
        }
    
        return returnString;
      }
    
  8. tonihei commented on Jun 10, 2025

    @tonihei
    Collaborator

    I think the two text tracks should be put into one adaptive group in ExoPlayer, but are currently treated separately.

    This part if fixed now.

    The audio selection dialog in PlayerView lists adaptive formats separately instead of as a group.
    The audio track name provider is not using the NAME tag provided by the playlist that help to distinguish them (e.g. "Klare Sprache")

    These ones are actually not as straight-forward because the track selection parameters don't currently offer a really good way to select an entire group and then let the player choose the best matching individual track based on format support etc. Will mark it as an enhancement to track this part of the issue.

  9. changed the title [-]Track display issues in PlayerView with adaptive audio and text tracks from HLS[/-] [+]Update track selection in PlayerView to show one entry per track group only[/+] on Jun 10, 2025
  10. tonihei commented on Jul 15, 2025

    @tonihei
    Collaborator

    The second part is also done now. We added TrackSelectionParameters.preferredVideoLabels, preferredTextLabels and preferredAudioLabels to let you specify preferences for a label. This should allow you to select all of the tracks in the respective group and leave the rest of the decision on more technical parameters to the player.

  11. locked and limited conversation to collaborators on Sep 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions