feat: implement sub-visibility toggle

Closes #597
This commit is contained in:
edde746
2026-03-02 19:07:56 +01:00
parent c372920965
commit 94395feaba
4 changed files with 66 additions and 5 deletions
@@ -12,6 +12,9 @@ class PlayerAndroid extends PlayerBase {
int? _bufferSizeBytes;
bool _tunnelingEnabled = true;
/// Stored subtitle track ID when subtitles are hidden via sub-visibility.
String? _hiddenSubtitleTrackId;
@override
MethodChannel get methodChannel => _methodChannel;
@@ -193,6 +196,29 @@ class PlayerAndroid extends PlayerBase {
case 'tunneled-playback':
_tunnelingEnabled = value != 'no';
break;
case 'sub-visibility':
if (value == 'no') {
// Store current subtitle track and disable
final current = state.track.subtitle;
if (current != null && current.id != 'no') {
_hiddenSubtitleTrackId = current.id;
await selectSubtitleTrack(SubtitleTrack.off);
}
} else {
// Restore previously hidden subtitle track
final storedId = _hiddenSubtitleTrackId;
if (storedId != null) {
_hiddenSubtitleTrackId = null;
final track = state.tracks.subtitle.cast<SubtitleTrack?>().firstWhere(
(t) => t?.id == storedId,
orElse: () => null,
);
if (track != null) {
await selectSubtitleTrack(track);
}
}
}
break;
// Other properties are no-ops for ExoPlayer
}
}