-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOpenMediaWindow.xaml.cs
More file actions
87 lines (79 loc) · 2.71 KB
/
OpenMediaWindow.xaml.cs
File metadata and controls
87 lines (79 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System;
using System.Windows;
using System.Windows.Forms;
using VideoPlayerWPF.Controls;
namespace VideoPlayerWPF
{
/// <summary>
/// Interaction logic for OpenMediaWindow.xaml
/// </summary>
public partial class OpenMediaWindow : Window
{
#region Fields
Uri MediaUri { get; set; }
Player _player;
#endregion
#region Events
readonly EventHandler<RoutedEventArgs> _filesSelected;
internal delegate void FilesSelectedHandler();
internal static FilesSelectedHandler FilesSelectedEvent;
#endregion
#region Constructors
public OpenMediaWindow()
{
InitializeComponent();
}
internal OpenMediaWindow(Player player)
{
InitializeComponent();
_player = player;
_filesSelected += _player.OpenMedia;
}
#endregion
#region Buttons clicks
private void FileDialogButton_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog fileDialog = new OpenFileDialog
{
Title = "Select videos for playback",
Multiselect = true,
InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.CommonVideos),
CheckFileExists = true,
Filter = "Video Files|*.mp4;*.mpeg|All Files (*.*)|*.*",
AddExtension = true,
CheckPathExists = true,
DefaultExt = "mp4"
};
if(fileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
foreach(string path in fileDialog.FileNames)
{
_player.SourceController.Sources.Add(new Uri(path));
}
_player.Source = _player.SourceController.GetSource();
_filesSelected?.Invoke(this, null);
FilesSelectedEvent?.Invoke();
}
Close();
}
private void OkResultButton_Click(object sender, RoutedEventArgs e)
{
if (!string.IsNullOrEmpty(UrlBox.Text))
{
try
{
MediaUri = new Uri(UrlBox.Text);
Close();
_player.Source = MediaUri;
_filesSelected?.Invoke(this, null);
}
catch (UriFormatException)
{
System.Windows.MessageBox.Show("Enter a valid URL!", "Invalid URL", MessageBoxButton.OK, MessageBoxImage.Warning);
}
}
}
private void CancelResultButton_Click(object sender, RoutedEventArgs e) => Close();
#endregion
}
}