Merge pull request #8249 from karyogamy/caption-fix-2

Fix disabled caption to no longer automatically re-enable on new player instance
This commit is contained in:
litetex 2022-04-18 15:25:29 +02:00 committed by GitHub
commit 31df4e42d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 6 deletions

View File

@ -6,6 +6,7 @@ on:
branches:
- dev
- master
- release/**
paths-ignore:
- 'README.md'
- 'doc/**'

View File

@ -3557,15 +3557,27 @@ public final class Player implements
}
// apply caption language from previous user preference
final List<String> selectedPreferredLanguages =
trackSelector.getParameters().preferredTextLanguages;
final int textRendererIndex = getCaptionRendererIndex();
if (textRendererIndex == RENDERER_UNAVAILABLE) {
return;
}
// If user prefers to show no caption, then disable the renderer.
// Otherwise, DefaultTrackSelector may automatically find an available caption
// and display that.
final String userPreferredLanguage =
prefs.getString(context.getString(R.string.caption_user_set_key), null);
final int textRendererIndex = getCaptionRendererIndex();
if (userPreferredLanguage == null) {
trackSelector.setParameters(trackSelector.buildUponParameters()
.setRendererDisabled(textRendererIndex, true));
return;
}
if (userPreferredLanguage != null
&& !selectedPreferredLanguages.contains(userPreferredLanguage)
&& textRendererIndex != RENDERER_UNAVAILABLE) {
// Only set preferred language if it does not match the user preference,
// otherwise there might be an infinite cycle at onTextTracksChanged.
final List<String> selectedPreferredLanguages =
trackSelector.getParameters().preferredTextLanguages;
if (!selectedPreferredLanguages.contains(userPreferredLanguage)) {
trackSelector.setParameters(trackSelector.buildUponParameters()
.setPreferredTextLanguages(userPreferredLanguage,
PlayerHelper.captionLanguageStemOf(userPreferredLanguage))