author | sarias |
Sun, 11 Oct 2009 20:34:56 +0200 | |
changeset 138 | 61ba19954ed4 |
parent 136 | 8b513df1b446 |
child 146 | dd8ed4d3beb6 |
permissions | -rw-r--r-- |
3 | 1 |
using System; |
2 |
using System.IO; |
|
3 |
using System.Net; |
|
4 |
using System.Windows; |
|
5 |
using System.Windows.Controls; |
|
6 |
using System.Windows.Data; |
|
7 |
using System.Windows.Media; |
|
8 |
using System.Windows.Media.Imaging; |
|
9 |
using System.Windows.Media.Animation; |
|
10 |
using System.Windows.Navigation; |
|
11 |
using System.ComponentModel; |
|
49 | 12 |
using System.Reflection; |
135
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
13 |
using System.Collections.Generic; |
3 | 14 |
|
134
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
15 |
using Microsoft.Surface.Presentation; |
135
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
16 |
using Microsoft.Surface.Presentation.Controls; |
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
17 |
using FingersDance.ActionFactory; |
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
18 |
using FingersDance.Actions; |
136
8b513df1b446
First step of deleting annotations from timeline by drag and drop
cavaliet
parents:
135
diff
changeset
|
19 |
using FingersDance.Control.TimeLine; |
134
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
20 |
using FingersDance.Views; |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
21 |
using FingersDance.ViewModels; |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
22 |
|
3 | 23 |
namespace FingersDance.Control.Player |
24 |
{ |
|
25 |
public partial class UserControlPlayer |
|
26 |
{ |
|
34 | 27 |
#region Variables |
28 |
private bool isPlaying = false; |
|
29 |
#endregion |
|
3 | 30 |
|
34 | 31 |
public event EventHandler PlayerOpened; |
3 | 32 |
|
119 | 33 |
public UserControlPlayer() |
34 |
{ |
|
35 |
this.InitializeComponent(); |
|
121
32611257e99f
Link PLayer - SessionInput
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
119
diff
changeset
|
36 |
MediaElementVideo.LoadedBehavior = MediaState.Manual; |
32611257e99f
Link PLayer - SessionInput
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
119
diff
changeset
|
37 |
MediaElementVideo.UnloadedBehavior = MediaState.Manual; |
119 | 38 |
} |
39 |
||
34 | 40 |
#region Properties |
41 |
public double TotalMilliseconds |
|
42 |
{ |
|
43 |
get |
|
44 |
{ |
|
45 |
return MediaElementVideo.NaturalDuration.TimeSpan.TotalMilliseconds; |
|
46 |
} |
|
47 |
} |
|
48 |
public MediaElement Player |
|
49 |
{ |
|
50 |
get |
|
51 |
{ |
|
52 |
return MediaElementVideo; |
|
53 |
} |
|
54 |
set |
|
55 |
{ |
|
56 |
MediaElementVideo= value; |
|
57 |
} |
|
58 |
} |
|
59 |
||
60 |
#endregion |
|
61 |
||
62 |
||
63 |
#region Methodes |
|
3 | 64 |
|
119 | 65 |
public void initPlayer(string path) |
66 |
{ |
|
67 |
//init player |
|
68 |
isPlaying = false; |
|
121
32611257e99f
Link PLayer - SessionInput
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
119
diff
changeset
|
69 |
MediaElementVideo.Source = new Uri(path); |
119 | 70 |
MediaElementVideo.ScrubbingEnabled = true; |
71 |
} |
|
72 |
||
34 | 73 |
public void playerPause() |
74 |
{ |
|
75 |
MediaElementVideo.Pause(); |
|
76 |
} |
|
77 |
public void playerPlay() |
|
78 |
{ |
|
79 |
MediaElementVideo.Play(); |
|
80 |
} |
|
81 |
public void playerStop() |
|
82 |
{ |
|
83 |
MediaElementVideo.Stop(); |
|
84 |
} |
|
85 |
|
|
86 |
#endregion |
|
87 |
||
3 | 88 |
private void ButtonPlayPause_ContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e) |
89 |
{ |
|
34 | 90 |
if (!isPlaying)//Play |
3 | 91 |
{ |
34 | 92 |
isPlaying = true; |
3 | 93 |
try |
94 |
{ |
|
95 |
MediaElementVideo.Play(); |
|
96 |
} |
|
97 |
catch (Exception ex) { } |
|
98 |
} |
|
99 |
else//Pause |
|
100 |
{ |
|
34 | 101 |
isPlaying = false; |
3 | 102 |
try |
103 |
{ |
|
104 |
MediaElementVideo.Pause(); |
|
105 |
} |
|
34 | 106 |
catch (Exception exx) { } |
3 | 107 |
} |
108 |
||
109 |
} |
|
110 |
||
111 |
private void ButtonPlayPause_Click(object sender, RoutedEventArgs e) |
|
112 |
{ |
|
34 | 113 |
if (!isPlaying)//Play |
3 | 114 |
{ |
34 | 115 |
isPlaying = true; |
3 | 116 |
try |
117 |
{ |
|
118 |
MediaElementVideo.Play(); |
|
119 |
} |
|
34 | 120 |
catch (Exception ex) { } |
121 |
||
3 | 122 |
} |
123 |
else//Pause |
|
124 |
{ |
|
34 | 125 |
isPlaying = false; |
3 | 126 |
try |
127 |
{ |
|
128 |
MediaElementVideo.Pause(); |
|
129 |
} |
|
34 | 130 |
catch (Exception exx) { } |
131 |
//ButtonPlayPause.Background = FindResource("[Skin_1]_Play_button_xaml") as Brush; |
|
132 |
} |
|
133 |
} |
|
134 |
||
135 |
private void ButtonFastForward_Click(object sender, RoutedEventArgs e) |
|
136 |
{ |
|
137 |
if (MediaElementVideo.SpeedRatio <= 3) |
|
138 |
MediaElementVideo.SpeedRatio += 1; |
|
139 |
} |
|
140 |
||
141 |
private void ButtonFastForward_ContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e) |
|
142 |
{ |
|
143 |
if (MediaElementVideo.SpeedRatio <= 3) |
|
144 |
MediaElementVideo.SpeedRatio += 1; |
|
145 |
} |
|
146 |
||
147 |
private void ButtonRewind_Click(object sender, RoutedEventArgs e) |
|
148 |
{ |
|
149 |
//TimeSpan ts = new TimeSpan(0, 0, 0, 0); |
|
150 |
if (MediaElementVideo.SpeedRatio > 1) |
|
151 |
{ |
|
152 |
MediaElementVideo.SpeedRatio -= 1; |
|
3 | 153 |
} |
34 | 154 |
else |
155 |
{ |
|
156 |
MediaElementVideo.Position = MediaElementVideo.Position.Add(new TimeSpan(0, 0, 0, -5)); |
|
157 |
} |
|
158 |
} |
|
159 |
||
160 |
private void ButtonRewind_ContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e) |
|
161 |
{ |
|
162 |
||
163 |
//TimeSpan ts = new TimeSpan(0, 0, 0,0); |
|
164 |
if (MediaElementVideo.SpeedRatio > 1) |
|
165 |
{ |
|
166 |
MediaElementVideo.SpeedRatio -= 1; |
|
167 |
} |
|
168 |
else |
|
169 |
{ |
|
170 |
MediaElementVideo.Position = MediaElementVideo.Position.Add(new TimeSpan(0, 0, 0, -5)); |
|
171 |
} |
|
172 |
} |
|
173 |
||
174 |
private void MediaElementVideo_MediaOpened(object sender, RoutedEventArgs e) |
|
175 |
{ |
|
176 |
OnPlayerOpened(); |
|
177 |
} |
|
178 |
protected virtual void OnPlayerOpened() |
|
179 |
{ |
|
180 |
if(PlayerOpened!=null) |
|
181 |
PlayerOpened(this, new EventArgs()); |
|
3 | 182 |
} |
134
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
183 |
|
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
184 |
private void Play_Pause_area_DragEnter(object sender, SurfaceDragDropEventArgs e) |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
185 |
{ |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
186 |
//Console.WriteLine("Enter"); |
136
8b513df1b446
First step of deleting annotations from timeline by drag and drop
cavaliet
parents:
135
diff
changeset
|
187 |
|
8b513df1b446
First step of deleting annotations from timeline by drag and drop
cavaliet
parents:
135
diff
changeset
|
188 |
// If the TimelineAnnotationView comes from a user control different from the current one, |
8b513df1b446
First step of deleting annotations from timeline by drag and drop
cavaliet
parents:
135
diff
changeset
|
189 |
// it means that we want to add the annotation to the current list. |
8b513df1b446
First step of deleting annotations from timeline by drag and drop
cavaliet
parents:
135
diff
changeset
|
190 |
// So we check if the dragged annotation can be dragged or if it will recover any existant annotation (in this case it will not be accepted) |
8b513df1b446
First step of deleting annotations from timeline by drag and drop
cavaliet
parents:
135
diff
changeset
|
191 |
// e.Cursor.DragSource is the SurfaceListBox where the drag started from |
8b513df1b446
First step of deleting annotations from timeline by drag and drop
cavaliet
parents:
135
diff
changeset
|
192 |
SurfaceListBox slb = (SurfaceListBox)e.Cursor.DragSource; |
8b513df1b446
First step of deleting annotations from timeline by drag and drop
cavaliet
parents:
135
diff
changeset
|
193 |
// We get the instance of the UserControlSyncSource |
8b513df1b446
First step of deleting annotations from timeline by drag and drop
cavaliet
parents:
135
diff
changeset
|
194 |
UserControl syncSrc = (UserControl)((Grid)((Grid)this.Parent).Parent).Parent; |
8b513df1b446
First step of deleting annotations from timeline by drag and drop
cavaliet
parents:
135
diff
changeset
|
195 |
// and its UserControlTimeline |
8b513df1b446
First step of deleting annotations from timeline by drag and drop
cavaliet
parents:
135
diff
changeset
|
196 |
UserControlTimeLine tl = (UserControlTimeLine)((Grid)((Grid)syncSrc.Content).Children[0]).Children[0]; |
8b513df1b446
First step of deleting annotations from timeline by drag and drop
cavaliet
parents:
135
diff
changeset
|
197 |
if (((Grid)((UserControl)((Grid)slb.Parent).Parent).Parent).Parent != tl) |
8b513df1b446
First step of deleting annotations from timeline by drag and drop
cavaliet
parents:
135
diff
changeset
|
198 |
{ |
8b513df1b446
First step of deleting annotations from timeline by drag and drop
cavaliet
parents:
135
diff
changeset
|
199 |
// e.Cursor.Visual is the ContentControl, so its Content is the dragged TimelineAnnotationView |
8b513df1b446
First step of deleting annotations from timeline by drag and drop
cavaliet
parents:
135
diff
changeset
|
200 |
AnnotationViewModel annotationDataVM = (AnnotationViewModel)((TimelineAnnotationView)((ContentControl)e.Cursor.Visual).Content).DataContext; |
8b513df1b446
First step of deleting annotations from timeline by drag and drop
cavaliet
parents:
135
diff
changeset
|
201 |
Play_Pause_area.Background = tl.isAnnotationAccepted(annotationDataVM) ? new SolidColorBrush(Colors.Green) : new SolidColorBrush(Colors.Red); |
8b513df1b446
First step of deleting annotations from timeline by drag and drop
cavaliet
parents:
135
diff
changeset
|
202 |
} |
8b513df1b446
First step of deleting annotations from timeline by drag and drop
cavaliet
parents:
135
diff
changeset
|
203 |
else |
8b513df1b446
First step of deleting annotations from timeline by drag and drop
cavaliet
parents:
135
diff
changeset
|
204 |
{ |
8b513df1b446
First step of deleting annotations from timeline by drag and drop
cavaliet
parents:
135
diff
changeset
|
205 |
Play_Pause_area.Background = new SolidColorBrush(Colors.White); |
8b513df1b446
First step of deleting annotations from timeline by drag and drop
cavaliet
parents:
135
diff
changeset
|
206 |
} |
8b513df1b446
First step of deleting annotations from timeline by drag and drop
cavaliet
parents:
135
diff
changeset
|
207 |
Play_Pause_area.Opacity = 0.3; |
8b513df1b446
First step of deleting annotations from timeline by drag and drop
cavaliet
parents:
135
diff
changeset
|
208 |
|
134
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
209 |
} |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
210 |
|
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
211 |
private void Play_Pause_area_DragLeave(object sender, SurfaceDragDropEventArgs e) |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
212 |
{ |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
213 |
//Console.WriteLine("Leave"); |
135
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
214 |
Play_Pause_area.Opacity = 0; |
134
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
215 |
} |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
216 |
|
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
217 |
private void Play_Pause_area_DragOver(object sender, SurfaceDragDropEventArgs e) |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
218 |
{ |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
219 |
//Console.WriteLine("Over"); |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
220 |
} |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
221 |
|
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
222 |
private void Play_Pause_area_Drop(object sender, SurfaceDragDropEventArgs e) |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
223 |
{ |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
224 |
//Console.WriteLine("Drop"); |
135
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
225 |
Play_Pause_area.Opacity = 0; |
134
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
226 |
// e.Cursor.Visual is the ContentControl, so its Content is the dragged TimelineAnnotationView |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
227 |
AnnotationViewModel annotationDataVM = (AnnotationViewModel)((TimelineAnnotationView)((ContentControl)e.Cursor.Visual).Content).DataContext; |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
228 |
int nbSeconds = (int)annotationDataVM.TcBegin; |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
229 |
int nbMilliSec = (int)((annotationDataVM.TcBegin * 1000)%1000); |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
230 |
MediaElementVideo.Position = new TimeSpan(0, 0, 0, nbSeconds, nbMilliSec); |
135
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
231 |
|
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
232 |
|
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
233 |
// If the TimelineAnnotationView comes from a user control different from the current one, |
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
234 |
// it means that we want to add the annotation to the current list. |
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
235 |
// So we generate the ActionAddAnnotation |
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
236 |
// e.Cursor.DragSource is the SurfaceListBox where the drag started from |
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
237 |
SurfaceListBox slb = (SurfaceListBox)e.Cursor.DragSource; |
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
238 |
// We get the instance of the UserControlSyncSource |
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
239 |
UserControl syncSrc = (UserControl)((Grid)((Grid)this.Parent).Parent).Parent; |
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
240 |
// and its UserControlTimeline |
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
241 |
UserControl tl = (UserControl)((Grid)((Grid)syncSrc.Content).Children[0]).Children[0]; |
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
242 |
if (((Grid)((UserControl)((Grid)slb.Parent).Parent).Parent).Parent != tl) |
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
243 |
{ |
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
244 |
// Now we build the action arguments : a list holding the timeline and the annotation view models |
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
245 |
List<Object> actionsArgs = new List<Object>(); |
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
246 |
actionsArgs.Add(tl); |
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
247 |
actionsArgs.Add(annotationDataVM); |
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
248 |
|
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
249 |
ActionGenerator ag = new ActionGenerator(); |
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
250 |
ActionBase ab = ag.GetAction("ActionAddAnnotation", actionsArgs); |
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
251 |
if (ab != null) |
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
252 |
ab.Execute(); |
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
253 |
} |
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
254 |
|
134
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
255 |
} |
3 | 256 |
} |
257 |
} |