mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-12 10:19:07 +00:00
Add controls to the VideoPlayer
This commit is contained in:
@@ -1,28 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.ComponentModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
using FontAwesome.WPF;
|
||||
using Unosquare.FFmpegMediaElement;
|
||||
|
||||
namespace QuickLook.Plugin.VideoViewer
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for UserControl1.xaml
|
||||
/// Interaction logic for UserControl1.xaml
|
||||
/// </summary>
|
||||
public partial class ViewerPanel : UserControl, IDisposable
|
||||
{
|
||||
public ViewerPanel()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
buttonPlayPause.MouseLeftButtonUp += TogglePlayPause;
|
||||
|
||||
mediaElement.PropertyChanged += ChangePlayPauseButton;
|
||||
mediaElement.MouseLeftButtonUp += TogglePlayPause;
|
||||
mediaElement.MediaErrored += ShowErrorOverlay;
|
||||
mediaElement.MediaFailed += ShowErrorOverlay;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
mediaElement?.Dispose();
|
||||
}
|
||||
|
||||
private void TogglePlayPause(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (mediaElement.IsPlaying)
|
||||
mediaElement.Pause();
|
||||
else
|
||||
mediaElement.Play();
|
||||
}
|
||||
|
||||
private void ChangePlayPauseButton(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName != "IsPlaying" && e.PropertyName != "HasMediaEnded")
|
||||
return;
|
||||
|
||||
buttonPlayPause.Icon = mediaElement.IsPlaying
|
||||
? FontAwesomeIcon.PauseCircleOutline
|
||||
: FontAwesomeIcon.PlayCircleOutline;
|
||||
}
|
||||
|
||||
private void ShowErrorOverlay(object sender, MediaErrorRoutedEventArgs e)
|
||||
{
|
||||
mediaElement.Stop();
|
||||
errorOverlay.Visibility = Visibility.Visible;
|
||||
}
|
||||
|
||||
public void LoadAndPlay(string path)
|
||||
@@ -36,10 +65,5 @@ namespace QuickLook.Plugin.VideoViewer
|
||||
GC.SuppressFinalize(this);
|
||||
Dispose();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
mediaElement?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user