-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVideoMPFWindow.xaml.cs
More file actions
181 lines (157 loc) · 5.61 KB
/
VideoMPFWindow.xaml.cs
File metadata and controls
181 lines (157 loc) · 5.61 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
using QuickLook.Common.Annotations;
using QuickLook.Common.Plugin;
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.Remoting.Contexts;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Media.Imaging;
using System.Windows.Threading;
namespace QuickLook.Plugin.VideoMPF
{
public partial class ViewerPanel : UserControl, IDisposable, INotifyPropertyChanged {
private readonly ContextObject _context;
DispatcherTimer timer;
bool IsSeeked;
bool IsPlay;
string pathFile;
private bool disposedValue;
public ViewerPanel(ContextObject context, String path)
{
InitializeComponent();
timer = new DispatcherTimer
{
Interval = TimeSpan.FromSeconds(1)
};
timer.Tick += Seek_Timer;
timer.Start();
LoadIcon();
IsSeeked = false;
IsPlay = false;
_context = context;
pathFile = path;
_context.IsBusy = false;
MyMediaElement.Source = new Uri(path);
}
public event System.Windows.RoutedEventHandler MediaOpened;
protected virtual void OnMediaOpened() {
//PlayOrPause.ToolTip = MyMediaElement.ActualWidth.ToString();
}
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) {
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
private void Seek_Timer(object sender, EventArgs e)
{
if (sender== null)
return;
if ((MyMediaElement.Source != null) && (MyMediaElement.NaturalDuration.HasTimeSpan) && (!IsSeeked))
{
Seeker.Minimum = 0;
Seeker.Maximum = MyMediaElement.NaturalDuration.TimeSpan.TotalSeconds;
Seeker.Value = MyMediaElement.Position.TotalSeconds;
}
}
private void Seek_Drag_Started(object sender, DragStartedEventArgs e)
{
IsSeeked = true;
}
private void Seek_Drag_Completed(object sender, DragCompletedEventArgs e)
{
IsSeeked = false;
MyMediaElement.Position = TimeSpan.FromSeconds(Seeker.Value);
}
private void Seek_Value_Changed(object sender, RoutedPropertyChangedEventArgs<double> e)
{
PlayTime.Text = TimeSpan.FromSeconds(Seeker.Value).ToString(@"hh\:mm\:ss");
}
private void Grid_MouseWheel(object sender, MouseWheelEventArgs e)
{
MyMediaElement.Volume += (e.Delta > 0) ? 0.1 : -0.1;
}
private void LoadIcon()
{
try
{
PlayOrPause.Content = new Image { Source = new BitmapImage(new Uri(FilePathInfo.Play)) };
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
private void ActionListener(object sender, RoutedEventArgs e)
{
Button btn = (Button)sender;
switch (btn.Uid)
{
case "Play":
if (IsPlay)
{
PauseSong();
}
else
{
PlaySong();
}
break;
}
}
public void PlaySong()
{
IsPlay = true;
PlayOrPause.Content = new Image { Source = new BitmapImage(new Uri(FilePathInfo.Pause)) };
PlayOrPause.ToolTip = "Pause";
MyMediaElement.Play();
}
public void PauseSong()
{
IsPlay = false;
PlayOrPause.Content = new Image { Source = new BitmapImage(new Uri(FilePathInfo.Play)) };
PlayOrPause.ToolTip = "Play";
MyMediaElement.Pause();
}
public void StopSong()
{
MyMediaElement.Stop();
_context.IsBusy = false;
}
public void Dispose(bool disposing) {
if (!disposedValue) {
if (disposing) {
}
try {
timer?.Stop();
MyMediaElement?.Close();
Task.Run(() =>
{
MyMediaElement = null;
});
} catch (Exception e) {
Debug.WriteLine(e);
}
// TODO: liberar los recursos no administrados (objetos no administrados) y reemplazar el finalizador
// TODO: establecer los campos grandes como NULL
disposedValue = true;
}
}
// // TODO: reemplazar el finalizador solo si "Dispose(bool disposing)" tiene código para liberar los recursos no administrados
// ~ViewerPanel()
// {
// // No cambie este código. Coloque el código de limpieza en el método "Dispose(bool disposing)".
// Dispose(disposing: false);
// }
void IDisposable.Dispose() {
// No cambie este código. Coloque el código de limpieza en el método "Dispose(bool disposing)".
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
}