Add controls to the VideoPlayer

This commit is contained in:
Paddy Xu
2017-05-08 22:00:25 +03:00
parent 66759992f1
commit 0995ebb7c2
10 changed files with 225 additions and 45 deletions

View File

@@ -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();
}
}
}
}