Update track selection in PlayerView to show one entry per track group only
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();
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.
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:
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
PlayerViewlists 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.
- 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:
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;
}
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.
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.