mirror of
https://github.com/zoriya/react-native-omni.git
synced 2026-08-16 02:44:51 +00:00
fix(cast-pref): propertly persist selected audip/sub on cast
This commit is contained in:
@@ -60,13 +60,18 @@ class OmniCastTrackSelector : CastTrackSelector() {
|
|||||||
val overrideMatch = indices.firstOrNull { i ->
|
val overrideMatch = indices.firstOrNull { i ->
|
||||||
overrides.keys.any { it.id == groups[i].id }
|
overrides.keys.any { it.id == groups[i].id }
|
||||||
}
|
}
|
||||||
val match = indices.firstOrNull { i ->
|
val matchesLabel = { i: Int ->
|
||||||
val name: String? = tracks[i].name
|
val name: String? = tracks[i].name
|
||||||
val language: String? = tracks[i].language
|
labels.isNotEmpty() && name != null && name in labels
|
||||||
(labels.isNotEmpty() && name != null && name in labels) ||
|
|
||||||
(languages.isNotEmpty() && language != null &&
|
|
||||||
Util.normalizeLanguageCode(language) in languages)
|
|
||||||
}
|
}
|
||||||
|
val matchesLanguage = { i: Int ->
|
||||||
|
val language: String? = tracks[i].language
|
||||||
|
languages.isNotEmpty() && language != null &&
|
||||||
|
Util.normalizeLanguageCode(language) in languages
|
||||||
|
}
|
||||||
|
val match = indices.firstOrNull { matchesLabel(it) && matchesLanguage(it) }
|
||||||
|
?: indices.firstOrNull { matchesLabel(it) }
|
||||||
|
?: indices.firstOrNull { matchesLanguage(it) }
|
||||||
val chosen = when {
|
val chosen = when {
|
||||||
overrideMatch != null -> overrideMatch
|
overrideMatch != null -> overrideMatch
|
||||||
match != null -> match
|
match != null -> match
|
||||||
|
|||||||
@@ -481,15 +481,15 @@ class OmniPlayer(
|
|||||||
}?.mediaTrackGroup
|
}?.mediaTrackGroup
|
||||||
if (group != null) {
|
if (group != null) {
|
||||||
params.setOverrideForType(TrackSelectionOverride(group, 0))
|
params.setOverrideForType(TrackSelectionOverride(group, 0))
|
||||||
|
}
|
||||||
|
// also set preferred flags for cast selection
|
||||||
|
val labels = track.label?.let { arrayOf(it) } ?: emptyArray()
|
||||||
|
if (type == C.TRACK_TYPE_AUDIO) {
|
||||||
|
params.setPreferredAudioLanguage(track.language)
|
||||||
|
.setPreferredAudioLabels(*labels)
|
||||||
} else {
|
} else {
|
||||||
val labels = track.label?.let { arrayOf(it) } ?: emptyArray()
|
params.setPreferredTextLanguage(track.language)
|
||||||
if (type == C.TRACK_TYPE_AUDIO) {
|
.setPreferredTextLabels(*labels)
|
||||||
params.setPreferredAudioLanguage(track.language)
|
|
||||||
.setPreferredAudioLabels(*labels)
|
|
||||||
} else {
|
|
||||||
params.setPreferredTextLanguage(track.language)
|
|
||||||
.setPreferredTextLabels(*labels)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
player.trackSelectionParameters = params.build()
|
player.trackSelectionParameters = params.build()
|
||||||
|
|||||||
Reference in New Issue
Block a user