Skip to content

Commit d581299

Browse files
committed
feat: only toggle subtile when there is one subtitle available, cycle through subtitle with Ctrl+C and Ctrl+Shift+C
1 parent 81f41ce commit d581299

File tree

2 files changed

+52
-18
lines changed

2 files changed

+52
-18
lines changed

Screenbox/Controls/PlayerControls.xaml

+8
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,14 @@
367367
<FontIcon Glyph="&#xED1F;" />
368368
<Button.KeyboardAccelerators>
369369
<KeyboardAccelerator Key="C" Invoked="{x:Bind ViewModel.ToggleSubtitle}" />
370+
<KeyboardAccelerator
371+
Key="C"
372+
Invoked="{x:Bind ViewModel.ToggleSubtitle}"
373+
Modifiers="Control" />
374+
<KeyboardAccelerator
375+
Key="C"
376+
Invoked="{x:Bind ViewModel.ToggleSubtitle}"
377+
Modifiers="Control,Shift" />
370378
</Button.KeyboardAccelerators>
371379
<Button.Flyout>
372380
<Flyout Opening="{x:Bind AudioTrackSubtitlePicker.ViewModel.OnAudioCaptionFlyoutOpening}" ShouldConstrainToRootBounds="False">

Screenbox/ViewModels/PlayerControlsViewModel.cs

+44-18
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ internal sealed partial class PlayerControlsViewModel : ObservableRecipient, IRe
4747
private readonly IWindowService _windowService;
4848
private readonly IFilesService _filesService;
4949
private IMediaPlayer? _mediaPlayer;
50-
private int _lastSubtitle = -1;
5150

5251
public PlayerControlsViewModel(
5352
PlaylistViewModel playlistViewModel,
@@ -76,26 +75,54 @@ public void Receive(MediaPlayerChangedMessage message)
7675

7776
public void ToggleSubtitle(KeyboardAccelerator sender, KeyboardAcceleratorInvokedEventArgs args)
7877
{
79-
args.Handled = true;
8078
if (_mediaPlayer?.PlaybackItem == null) return;
81-
var subtitleTracks = _mediaPlayer.PlaybackItem.SubtitleTracks;
79+
PlaybackSubtitleTrackList subtitleTracks = _mediaPlayer.PlaybackItem.SubtitleTracks;
8280
if (subtitleTracks.Count == 0) return;
83-
if (subtitleTracks.SelectedIndex >= 0)
84-
{
85-
_lastSubtitle = subtitleTracks.SelectedIndex;
86-
subtitleTracks.SelectedIndex = -1; Messenger.Send(
87-
new UpdateStatusMessage("Subtitle: None"));
88-
}
89-
else if (_lastSubtitle >= 0)
90-
{
91-
subtitleTracks.SelectedIndex = _lastSubtitle;
92-
Messenger.Send(
93-
new UpdateStatusMessage($"Subtitle: {subtitleTracks[subtitleTracks.SelectedIndex].Label}"));
94-
}
95-
else
81+
args.Handled = true;
82+
switch (args.KeyboardAccelerator.Modifiers)
9683
{
97-
args.Handled = false;
84+
case VirtualKeyModifiers.None when subtitleTracks.Count == 1:
85+
if (subtitleTracks.SelectedIndex >= 0)
86+
{
87+
subtitleTracks.SelectedIndex = -1;
88+
}
89+
else
90+
{
91+
subtitleTracks.SelectedIndex = 0;
92+
93+
}
94+
break;
95+
96+
case VirtualKeyModifiers.Control:
97+
if (subtitleTracks.SelectedIndex == subtitleTracks.Count - 1)
98+
{
99+
subtitleTracks.SelectedIndex = -1;
100+
}
101+
else
102+
{
103+
subtitleTracks.SelectedIndex++;
104+
}
105+
break;
106+
107+
case VirtualKeyModifiers.Control | VirtualKeyModifiers.Shift:
108+
if (subtitleTracks.SelectedIndex == -1)
109+
{
110+
subtitleTracks.SelectedIndex = subtitleTracks.Count - 1;
111+
}
112+
else
113+
{
114+
subtitleTracks.SelectedIndex--;
115+
}
116+
break;
117+
118+
default:
119+
args.Handled = false;
120+
return;
98121
}
122+
123+
Messenger.Send(subtitleTracks.SelectedIndex == -1
124+
? new UpdateStatusMessage("Subtitle: None")
125+
: new UpdateStatusMessage($"Subtitle: {subtitleTracks[subtitleTracks.SelectedIndex].Label}"));
99126
}
100127

101128
partial void OnZoomToFitChanged(bool value)
@@ -131,7 +158,6 @@ private void OnNaturalVideoSizeChanged(IMediaPlayer sender, object? args)
131158
{
132159
_dispatcherQueue.TryEnqueue(() => HasVideo = _mediaPlayer?.NaturalVideoHeight > 0);
133160
SaveSnapshotCommand.NotifyCanExecuteChanged();
134-
_lastSubtitle = -1;
135161
}
136162

137163
private void OnPlaybackStateChanged(IMediaPlayer sender, object? args)

0 commit comments

Comments
 (0)