[Peek]Use space to play/resume video (#29487)

This commit is contained in:
Davide Giacometti
2023-11-03 12:11:57 +01:00
committed by GitHub
parent 47aa28977c
commit 4875564a59
2 changed files with 25 additions and 0 deletions

View File

@@ -40,6 +40,9 @@
Source="{x:Bind VideoPreviewer.Preview, Mode=OneWay}"
ToolTipService.ToolTip="{x:Bind ImageInfoTooltip, Mode=OneWay}"
Visibility="{x:Bind IsPreviewVisible(VideoPreviewer, Previewer.State), Mode=OneWay}">
<MediaPlayerElement.KeyboardAccelerators>
<KeyboardAccelerator Key="Space" Invoked="KeyboardAccelerator_Space_Invoked" />
</MediaPlayerElement.KeyboardAccelerators>
<MediaPlayerElement.TransportControls>
<MediaTransportControls
x:Name="mediaTransport"

View File

@@ -299,6 +299,28 @@ namespace Peek.FilePreviewer
}
}
private void KeyboardAccelerator_Space_Invoked(KeyboardAccelerator sender, KeyboardAcceleratorInvokedEventArgs args)
{
var mediaPlayer = VideoPreview.MediaPlayer;
if (mediaPlayer.Source == null || !mediaPlayer.CanPause)
{
return;
}
if (mediaPlayer.CurrentState == Windows.Media.Playback.MediaPlayerState.Playing)
{
mediaPlayer.Pause();
}
else
{
mediaPlayer.Play();
}
// Prevent the keyboard accelerator to be called twice
args.Handled = true;
}
private async Task UpdateImageTooltipAsync(CancellationToken cancellationToken)
{
if (Item == null)