|
0
|
1 |
using System; |
|
|
2 |
using System.Windows; |
|
|
3 |
using System.Windows.Controls; |
|
|
4 |
using System.Windows.Documents; |
|
|
5 |
using System.Windows.Ink; |
|
|
6 |
using System.Windows.Input; |
|
|
7 |
using System.Windows.Media; |
|
|
8 |
using System.Windows.Media.Animation; |
|
|
9 |
using System.Windows.Shapes; |
|
|
10 |
using Iri.Modernisation.BaseMVVM.Commands; |
|
|
11 |
using Iri.Modernisation.Controls.ViewModel; |
|
|
12 |
namespace Iri.Modernisation.Controls.View |
|
|
13 |
{ |
|
|
14 |
public partial class VideoViewer : UserControl |
|
|
15 |
{ |
|
|
16 |
|
|
|
17 |
|
|
22
|
18 |
|
|
|
19 |
public System.Windows.Threading.DispatcherTimer VideoPositionTimer = new System.Windows.Threading.DispatcherTimer(); |
|
|
20 |
|
|
0
|
21 |
public String MediaSource |
|
|
22 |
{ |
|
|
23 |
get |
|
|
24 |
{ |
|
|
25 |
return (String)GetValue(SourceProperty); |
|
|
26 |
} |
|
|
27 |
set |
|
|
28 |
{ |
|
|
29 |
SetValue(SourceProperty, value); |
|
|
30 |
if(DataContext != null) |
|
|
31 |
((VideoViewerVM)DataContext).Source = value; |
|
|
32 |
} |
|
|
33 |
} |
|
|
34 |
|
|
|
35 |
// Using a DependencyProperty as the backing store for Source. This enables animation, styling, binding, etc... |
|
|
36 |
public static readonly DependencyProperty SourceProperty = |
|
|
37 |
DependencyProperty.Register("MediaSource", typeof(String), typeof(VideoViewer), new PropertyMetadata("")); |
|
|
38 |
|
|
15
|
39 |
private bool _isPlayed = false; |
|
0
|
40 |
public VideoViewer() |
|
|
41 |
{ |
|
|
42 |
// Required to initialize variables |
|
22
|
43 |
InitializeComponent(); /// <summary> |
|
|
44 |
VideoPositionTimer.Interval = new System.TimeSpan(0, 0, 0, 0, 1000); |
|
|
45 |
VideoPositionTimer.Tick += new EventHandler(VideoPositionTimer_Tick); |
|
0
|
46 |
Commands.GoToTime.Executed += new EventHandler<SLExtensions.Input.ExecutedEventArgs>(GoToTime_Executed); |
|
|
47 |
Commands.VideoViewer.Pause.Executed += new EventHandler<SLExtensions.Input.ExecutedEventArgs>(Pause_Executed); |
|
|
48 |
Commands.VideoViewer.Play.Executed +=new EventHandler<SLExtensions.Input.ExecutedEventArgs>(Play_Executed); |
|
|
49 |
} |
|
|
50 |
|
|
|
51 |
void GoToTime_Executed(object sender, SLExtensions.Input.ExecutedEventArgs e) |
|
|
52 |
{ |
|
|
53 |
VideoScreen.Position = TimeSpan.FromMilliseconds((double)e.Parameter); |
|
|
54 |
} |
|
|
55 |
|
|
|
56 |
void VideoPositionTimer_Tick(object sender, EventArgs e) |
|
|
57 |
{ |
|
22
|
58 |
if (_isPlayed) |
|
|
59 |
{ |
|
|
60 |
if(Tick!=null) |
|
|
61 |
{ |
|
|
62 |
Tick(this, new VideoViewerEventArgs(VideoScreen.Position)); |
|
|
63 |
} |
|
|
64 |
((VideoViewerVM)DataContext).LaunchTick(VideoScreen.Position); |
|
|
65 |
} |
|
|
66 |
//Commands.VideoViewer.SendPosition.Execute(VideoScreen.Position); |
|
0
|
67 |
} |
|
|
68 |
public void ChangePosition(TimeSpan TS) |
|
|
69 |
{ |
|
|
70 |
VideoScreen.Position = TS; |
|
|
71 |
|
|
|
72 |
} |
|
|
73 |
void Pause_Executed(object sender, SLExtensions.Input.ExecutedEventArgs e) |
|
|
74 |
{ |
|
|
75 |
VideoScreen.Pause(); |
|
15
|
76 |
_isPlayed = false; |
|
22
|
77 |
VideoPositionTimer.Stop(); |
|
|
78 |
if (VideoPositionTimer.IsEnabled) |
|
0
|
79 |
{ |
|
|
80 |
MessageBox.Show("Click Time IS NOT STOPPED"); |
|
|
81 |
} |
|
|
82 |
} |
|
|
83 |
|
|
|
84 |
void Play_Executed(object sender, SLExtensions.Input.ExecutedEventArgs e) |
|
|
85 |
{ |
|
|
86 |
if (e.Parameter == DataContext || e.Parameter == null) |
|
|
87 |
{ |
|
15
|
88 |
_isPlayed = true; |
|
0
|
89 |
VideoScreen.Play(); |
|
22
|
90 |
VideoPositionTimer.Start(); |
|
0
|
91 |
} |
|
|
92 |
} |
|
|
93 |
|
|
|
94 |
private void VideoScreen_MediaFailed(object sender, System.Windows.ExceptionRoutedEventArgs e) |
|
|
95 |
{ |
|
|
96 |
MessageBox.Show(e.ErrorException.ToString()); |
|
|
97 |
} |
|
|
98 |
|
|
|
99 |
private void VideoScreen_CurrentStateChanged(object sender, System.Windows.RoutedEventArgs e) |
|
|
100 |
{ |
|
|
101 |
|
|
|
102 |
} |
|
|
103 |
|
|
|
104 |
private void VideoScreen_MarkerReached(object sender, System.Windows.Media.TimelineMarkerRoutedEventArgs e) |
|
|
105 |
{ |
|
|
106 |
MessageBox.Show("toto"); |
|
|
107 |
} |
|
22
|
108 |
public event EventHandler<VideoViewerEventArgs> Tick; |
|
0
|
109 |
} |
|
22
|
110 |
public class VideoViewerEventArgs: EventArgs |
|
|
111 |
{ |
|
|
112 |
|
|
|
113 |
public TimeSpan Position { get; set; } |
|
|
114 |
public VideoViewerEventArgs(TimeSpan pos) |
|
|
115 |
{ |
|
|
116 |
Position = pos; |
|
|
117 |
} |
|
|
118 |
} |
|
0
|
119 |
} |