2018-06-22 22:10:37 -04:00
|
|
|
|
using Microsoft.Win32;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
namespace butterflow_ui
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Interaction logic for MainWindow.xaml
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public partial class MainWindow : Window
|
|
|
|
|
|
{
|
2018-07-01 17:02:50 -05:00
|
|
|
|
#region Members
|
|
|
|
|
|
|
2018-07-01 18:38:51 -05:00
|
|
|
|
//
|
2018-07-01 17:02:50 -05:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2018-06-23 12:58:22 -05:00
|
|
|
|
#region Properties
|
|
|
|
|
|
|
2018-06-24 03:29:34 -05:00
|
|
|
|
/// <summary> Gets or sets the butyterflow options configuration. </summary>
|
|
|
|
|
|
/// <value> The options configuration. </value>
|
2018-06-24 02:56:03 -05:00
|
|
|
|
public OptionsConfiguration OptionsConfiguration { get; set; } = new OptionsConfiguration();
|
2018-06-23 12:58:22 -05:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2018-06-24 02:56:03 -05:00
|
|
|
|
/// <summary> Default constructor. </summary>
|
2018-06-22 22:10:37 -04:00
|
|
|
|
public MainWindow()
|
|
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-06-24 02:56:03 -05:00
|
|
|
|
/// <summary> Event handler. Called by btnFilePicker for click events. </summary>
|
|
|
|
|
|
/// <param name="sender"> Source of the event. </param>
|
|
|
|
|
|
/// <param name="e"> Routed event information. </param>
|
2018-06-22 22:10:37 -04:00
|
|
|
|
private void btnFilePicker_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
var ofd = new OpenFileDialog();
|
|
|
|
|
|
ofd.Filter = "Supported Video Files|*.mp4;*.mkv";
|
2018-06-24 02:56:03 -05:00
|
|
|
|
|
2018-06-22 22:10:37 -04:00
|
|
|
|
|
|
|
|
|
|
var result = ofd.ShowDialog(this);
|
|
|
|
|
|
if (result.HasValue && result.Value)
|
|
|
|
|
|
{
|
2018-07-01 17:02:50 -05:00
|
|
|
|
this.OptionsConfiguration.VideoInput = ofd.FileName;
|
2018-06-25 03:44:45 -05:00
|
|
|
|
|
2018-07-01 17:02:50 -05:00
|
|
|
|
//Hack to get the first frame to display in the media preview element.
|
|
|
|
|
|
//This also triggers the MediaOpened event so we can get the metadata from the element.
|
|
|
|
|
|
mediaPreview.Play();
|
2018-07-01 18:38:51 -05:00
|
|
|
|
mediaPreview.PausePlayback();
|
2018-06-22 22:10:37 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-06-24 03:29:34 -05:00
|
|
|
|
|
|
|
|
|
|
/// <summary> Event handler. Called by PlaybackRate radio buttons for checked events. </summary>
|
|
|
|
|
|
/// <param name="sender"> Source of the event. </param>
|
|
|
|
|
|
/// <param name="e"> Routed event information. </param>
|
|
|
|
|
|
private void PlaybackRateRadioButton_Checked(object sender, RoutedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
var typedSender = (RadioButton)sender;
|
|
|
|
|
|
|
|
|
|
|
|
if(typedSender != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var tag = typedSender.Tag.ToString();
|
|
|
|
|
|
this.OptionsConfiguration.PlaybackRate = tag;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-07-01 17:02:50 -05:00
|
|
|
|
|
|
|
|
|
|
/// <summary> Event handler. Called by bntVideoPlay for click events. </summary>
|
|
|
|
|
|
/// <param name="sender"> Source of the event. </param>
|
|
|
|
|
|
/// <param name="e"> Routed event information. </param>
|
|
|
|
|
|
private void bntVideoPlay_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
|
{
|
2018-07-01 18:38:51 -05:00
|
|
|
|
if (this.mediaPreview.CanPlay() || this.mediaPreview.CanPause.GetValueOrDefault(false))
|
2018-07-01 17:02:50 -05:00
|
|
|
|
{
|
2018-07-01 18:38:51 -05:00
|
|
|
|
this.mediaPreview.TogglePlayPause();
|
|
|
|
|
|
}
|
2018-07-01 17:02:50 -05:00
|
|
|
|
|
2018-07-01 18:38:51 -05:00
|
|
|
|
if(this.mediaPreview.IsPlaying)
|
|
|
|
|
|
{
|
2018-07-01 17:02:50 -05:00
|
|
|
|
this.PlayPauseButtonIcon.Template = Application.Current.Resources["PauseIcon"] as ControlTemplate;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
this.PlayPauseButtonIcon.Template = Application.Current.Resources["PlayIcon"] as ControlTemplate;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> Event handler. Called by bntVideoStop for click events. </summary>
|
|
|
|
|
|
/// <param name="sender"> Source of the event. </param>
|
|
|
|
|
|
/// <param name="e"> Routed event information. </param>
|
|
|
|
|
|
private void bntVideoStop_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.PlayPauseButtonIcon.Template = Application.Current.Resources["PlayIcon"] as ControlTemplate;
|
|
|
|
|
|
this.mediaPreview.Stop();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> Event handler. Called by bntVideoForward for click events. </summary>
|
|
|
|
|
|
/// <param name="sender"> Source of the event. </param>
|
|
|
|
|
|
/// <param name="e"> Routed event information. </param>
|
|
|
|
|
|
private void bntVideoForward_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
|
{
|
2018-07-01 18:38:51 -05:00
|
|
|
|
if (this.mediaPreview.CanSkipForward(null))
|
|
|
|
|
|
{
|
|
|
|
|
|
this.mediaPreview.SkipForward(null);
|
|
|
|
|
|
}
|
2018-07-01 17:02:50 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> Event handler. Called by bntVideoBackward for click events. </summary>
|
|
|
|
|
|
/// <param name="sender"> Source of the event. </param>
|
|
|
|
|
|
/// <param name="e"> Routed event information. </param>
|
|
|
|
|
|
private void bntVideoBackward_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
|
{
|
2018-07-01 18:38:51 -05:00
|
|
|
|
if (this.mediaPreview.CanSkipBack(null))
|
|
|
|
|
|
{
|
|
|
|
|
|
this.mediaPreview.SkipBack(null);
|
|
|
|
|
|
}
|
2018-07-01 17:02:50 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> Event handler. Called by mediaPreview for media opened events. </summary>
|
|
|
|
|
|
/// <param name="sender"> Source of the event. </param>
|
|
|
|
|
|
/// <param name="e"> Routed event information. </param>
|
|
|
|
|
|
private void mediaPreview_MediaOpened(object sender, RoutedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.OptionsConfiguration.Width = this.mediaPreview.NaturalVideoWidth.ToString();
|
|
|
|
|
|
this.OptionsConfiguration.Height = this.mediaPreview.NaturalVideoHeight.ToString();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> Event handler. Called by mediaPreview for media ended events. </summary>
|
|
|
|
|
|
/// <param name="sender"> Source of the event. </param>
|
|
|
|
|
|
/// <param name="e"> Routed event information. </param>
|
|
|
|
|
|
private void mediaPreview_MediaEnded(object sender, RoutedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.PlayPauseButtonIcon.Template = Application.Current.Resources["PlayIcon"] as ControlTemplate;
|
|
|
|
|
|
}
|
2018-06-22 22:10:37 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|