| author | Matthieu Totet |
| Mon, 14 Dec 2009 17:02:03 +0100 | |
| changeset 23 | 10acb6a11a73 |
| parent 22 | 69a2910ec6f9 |
| child 24 | c031f1132dde |
| permissions | -rw-r--r-- |
| 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 |
{ |
|
|
23
10acb6a11a73
Update VideoViewer ( Allow Multi-VideoViewer)
Matthieu Totet
parents:
22
diff
changeset
|
53 |
if(e.Source == DataContext) |
|
10acb6a11a73
Update VideoViewer ( Allow Multi-VideoViewer)
Matthieu Totet
parents:
22
diff
changeset
|
54 |
{ |
|
10acb6a11a73
Update VideoViewer ( Allow Multi-VideoViewer)
Matthieu Totet
parents:
22
diff
changeset
|
55 |
VideoScreen.Position = ((TimeSpan)e.Parameter); |
|
10acb6a11a73
Update VideoViewer ( Allow Multi-VideoViewer)
Matthieu Totet
parents:
22
diff
changeset
|
56 |
} |
| 0 | 57 |
} |
58 |
||
59 |
void VideoPositionTimer_Tick(object sender, EventArgs e) |
|
60 |
{ |
|
| 22 | 61 |
if (_isPlayed) |
62 |
{ |
|
63 |
if(Tick!=null) |
|
64 |
{ |
|
65 |
Tick(this, new VideoViewerEventArgs(VideoScreen.Position)); |
|
66 |
} |
|
67 |
((VideoViewerVM)DataContext).LaunchTick(VideoScreen.Position); |
|
68 |
} |
|
69 |
//Commands.VideoViewer.SendPosition.Execute(VideoScreen.Position); |
|
| 0 | 70 |
} |
71 |
public void ChangePosition(TimeSpan TS) |
|
72 |
{ |
|
73 |
VideoScreen.Position = TS; |
|
74 |
|
|
75 |
} |
|
76 |
void Pause_Executed(object sender, SLExtensions.Input.ExecutedEventArgs e) |
|
77 |
{ |
|
78 |
VideoScreen.Pause(); |
|
| 15 | 79 |
_isPlayed = false; |
| 22 | 80 |
VideoPositionTimer.Stop(); |
81 |
if (VideoPositionTimer.IsEnabled) |
|
| 0 | 82 |
{ |
83 |
MessageBox.Show("Click Time IS NOT STOPPED"); |
|
84 |
} |
|
85 |
} |
|
86 |
||
87 |
void Play_Executed(object sender, SLExtensions.Input.ExecutedEventArgs e) |
|
88 |
{ |
|
89 |
if (e.Parameter == DataContext || e.Parameter == null) |
|
90 |
{ |
|
| 15 | 91 |
_isPlayed = true; |
| 0 | 92 |
VideoScreen.Play(); |
| 22 | 93 |
VideoPositionTimer.Start(); |
| 0 | 94 |
} |
95 |
} |
|
96 |
||
97 |
private void VideoScreen_MediaFailed(object sender, System.Windows.ExceptionRoutedEventArgs e) |
|
98 |
{ |
|
99 |
MessageBox.Show(e.ErrorException.ToString()); |
|
100 |
} |
|
101 |
||
102 |
private void VideoScreen_CurrentStateChanged(object sender, System.Windows.RoutedEventArgs e) |
|
103 |
{ |
|
104 |
|
|
105 |
} |
|
106 |
||
107 |
private void VideoScreen_MarkerReached(object sender, System.Windows.Media.TimelineMarkerRoutedEventArgs e) |
|
108 |
{ |
|
109 |
MessageBox.Show("toto"); |
|
110 |
} |
|
| 22 | 111 |
public event EventHandler<VideoViewerEventArgs> Tick; |
| 0 | 112 |
} |
| 22 | 113 |
public class VideoViewerEventArgs: EventArgs |
114 |
{ |
|
115 |
||
116 |
public TimeSpan Position { get; set; } |
|
117 |
public VideoViewerEventArgs(TimeSpan pos) |
|
118 |
{ |
|
119 |
Position = pos; |
|
120 |
} |
|
121 |
} |
|
| 0 | 122 |
} |