author | cavaliet |
Wed, 04 Nov 2009 16:28:01 +0100 | |
changeset 186 | 83615722dbab |
parent 174 | 45c9e55fcf23 |
child 188 | e642ad0c366b |
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; |
143 | 13 |
using System.Collections.Generic; |
14 |
||
15 |
using Microsoft.Surface.Presentation; |
|
16 |
using Microsoft.Surface.Presentation.Controls; |
|
156
e16c8c913c65
Color Factory et application des couleurs au pivot
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
146
diff
changeset
|
17 |
using FingersDance.Factory; |
143 | 18 |
using FingersDance.Actions; |
19 |
using FingersDance.Control.TimeLine; |
|
20 |
using FingersDance.Views; |
|
21 |
using FingersDance.ViewModels; |
|
174 | 22 |
using GestureControl; |
3 | 23 |
|
24 |
namespace FingersDance.Control.Player |
|
25 |
{ |
|
26 |
public partial class UserControlPlayer |
|
27 |
{ |
|
34 | 28 |
#region Variables |
29 |
private bool isPlaying = false; |
|
30 |
#endregion |
|
3 | 31 |
|
34 | 32 |
public event EventHandler PlayerOpened; |
165 | 33 |
public event EventHandler PlayerStopOrPause; |
168
d70ee2002f75
Thumb Timeline Rotation and Debug Closing Panels
ARIAS Santiago
parents:
165
diff
changeset
|
34 |
|
170 | 35 |
#region constructors |
119 | 36 |
public UserControlPlayer() |
37 |
{ |
|
38 |
this.InitializeComponent(); |
|
121
32611257e99f
Link PLayer - SessionInput
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
119
diff
changeset
|
39 |
MediaElementVideo.LoadedBehavior = MediaState.Manual; |
32611257e99f
Link PLayer - SessionInput
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
119
diff
changeset
|
40 |
MediaElementVideo.UnloadedBehavior = MediaState.Manual; |
173
e99fe78cd168
Gesture Control Integration in the Control Player
ARIAS Santiago
parents:
170
diff
changeset
|
41 |
//SAR |
e99fe78cd168
Gesture Control Integration in the Control Player
ARIAS Santiago
parents:
170
diff
changeset
|
42 |
//Control User Info |
170 | 43 |
usercontrolInfoUser.LabelSession.Content = "Seance Test"; |
44 |
usercontrolInfoUser.LabelUser.Content = "User Test"; |
|
119 | 45 |
} |
174 | 46 |
|
170 | 47 |
#endregion |
48 |
||
34 | 49 |
#region Properties |
50 |
public double TotalMilliseconds |
|
51 |
{ |
|
52 |
get |
|
53 |
{ |
|
54 |
return MediaElementVideo.NaturalDuration.TimeSpan.TotalMilliseconds; |
|
55 |
} |
|
56 |
} |
|
57 |
public MediaElement Player |
|
58 |
{ |
|
59 |
get |
|
60 |
{ |
|
61 |
return MediaElementVideo; |
|
62 |
} |
|
63 |
set |
|
64 |
{ |
|
65 |
MediaElementVideo= value; |
|
66 |
} |
|
67 |
} |
|
68 |
||
69 |
#endregion |
|
70 |
||
71 |
||
72 |
#region Methodes |
|
3 | 73 |
|
119 | 74 |
public void initPlayer(string path) |
75 |
{ |
|
76 |
//init player |
|
77 |
isPlaying = false; |
|
121
32611257e99f
Link PLayer - SessionInput
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
119
diff
changeset
|
78 |
MediaElementVideo.Source = new Uri(path); |
119 | 79 |
MediaElementVideo.ScrubbingEnabled = true; |
80 |
} |
|
81 |
||
34 | 82 |
public void playerPause() |
83 |
{ |
|
84 |
MediaElementVideo.Pause(); |
|
165 | 85 |
if (PlayerStopOrPause != null) |
168
d70ee2002f75
Thumb Timeline Rotation and Debug Closing Panels
ARIAS Santiago
parents:
165
diff
changeset
|
86 |
PlayerStopOrPause(false, new EventArgs()); |
34 | 87 |
} |
88 |
public void playerPlay() |
|
89 |
{ |
|
90 |
MediaElementVideo.Play(); |
|
168
d70ee2002f75
Thumb Timeline Rotation and Debug Closing Panels
ARIAS Santiago
parents:
165
diff
changeset
|
91 |
if (PlayerStopOrPause != null) |
d70ee2002f75
Thumb Timeline Rotation and Debug Closing Panels
ARIAS Santiago
parents:
165
diff
changeset
|
92 |
PlayerStopOrPause(true, new EventArgs()); |
34 | 93 |
} |
94 |
public void playerStop() |
|
95 |
{ |
|
96 |
MediaElementVideo.Stop(); |
|
165 | 97 |
if (PlayerStopOrPause != null) |
168
d70ee2002f75
Thumb Timeline Rotation and Debug Closing Panels
ARIAS Santiago
parents:
165
diff
changeset
|
98 |
PlayerStopOrPause(false, new EventArgs()); |
34 | 99 |
} |
100 |
|
|
101 |
#endregion |
|
102 |
||
173
e99fe78cd168
Gesture Control Integration in the Control Player
ARIAS Santiago
parents:
170
diff
changeset
|
103 |
#region GestureEvents |
e99fe78cd168
Gesture Control Integration in the Control Player
ARIAS Santiago
parents:
170
diff
changeset
|
104 |
|
e99fe78cd168
Gesture Control Integration in the Control Player
ARIAS Santiago
parents:
170
diff
changeset
|
105 |
public void GestureDetected(object sender, GestureControl.GestureRoutedEventArgs e) |
e99fe78cd168
Gesture Control Integration in the Control Player
ARIAS Santiago
parents:
170
diff
changeset
|
106 |
{ |
e99fe78cd168
Gesture Control Integration in the Control Player
ARIAS Santiago
parents:
170
diff
changeset
|
107 |
Console.WriteLine("gesture detected: " + e.Gesture); |
e99fe78cd168
Gesture Control Integration in the Control Player
ARIAS Santiago
parents:
170
diff
changeset
|
108 |
switch (e.Gesture) |
e99fe78cd168
Gesture Control Integration in the Control Player
ARIAS Santiago
parents:
170
diff
changeset
|
109 |
{ |
e99fe78cd168
Gesture Control Integration in the Control Player
ARIAS Santiago
parents:
170
diff
changeset
|
110 |
case "UP": |
e99fe78cd168
Gesture Control Integration in the Control Player
ARIAS Santiago
parents:
170
diff
changeset
|
111 |
// |
e99fe78cd168
Gesture Control Integration in the Control Player
ARIAS Santiago
parents:
170
diff
changeset
|
112 |
usercontrolInfoUser.LabelSession.Content = "UP!"; |
e99fe78cd168
Gesture Control Integration in the Control Player
ARIAS Santiago
parents:
170
diff
changeset
|
113 |
break; |
e99fe78cd168
Gesture Control Integration in the Control Player
ARIAS Santiago
parents:
170
diff
changeset
|
114 |
case "LEFT": |
e99fe78cd168
Gesture Control Integration in the Control Player
ARIAS Santiago
parents:
170
diff
changeset
|
115 |
usercontrolInfoUser.LabelSession.Content = "LEFT!"; |
e99fe78cd168
Gesture Control Integration in the Control Player
ARIAS Santiago
parents:
170
diff
changeset
|
116 |
break; |
e99fe78cd168
Gesture Control Integration in the Control Player
ARIAS Santiago
parents:
170
diff
changeset
|
117 |
case "RIGHT": |
e99fe78cd168
Gesture Control Integration in the Control Player
ARIAS Santiago
parents:
170
diff
changeset
|
118 |
usercontrolInfoUser.LabelSession.Content = "RIGHT!"; |
e99fe78cd168
Gesture Control Integration in the Control Player
ARIAS Santiago
parents:
170
diff
changeset
|
119 |
break; |
e99fe78cd168
Gesture Control Integration in the Control Player
ARIAS Santiago
parents:
170
diff
changeset
|
120 |
case "DOWN": |
e99fe78cd168
Gesture Control Integration in the Control Player
ARIAS Santiago
parents:
170
diff
changeset
|
121 |
usercontrolInfoUser.LabelSession.Content = "DOWN!"; |
e99fe78cd168
Gesture Control Integration in the Control Player
ARIAS Santiago
parents:
170
diff
changeset
|
122 |
break; |
e99fe78cd168
Gesture Control Integration in the Control Player
ARIAS Santiago
parents:
170
diff
changeset
|
123 |
default: |
e99fe78cd168
Gesture Control Integration in the Control Player
ARIAS Santiago
parents:
170
diff
changeset
|
124 |
//this.TxtGesture.Text = e.Gesture; |
e99fe78cd168
Gesture Control Integration in the Control Player
ARIAS Santiago
parents:
170
diff
changeset
|
125 |
break; |
e99fe78cd168
Gesture Control Integration in the Control Player
ARIAS Santiago
parents:
170
diff
changeset
|
126 |
} |
e99fe78cd168
Gesture Control Integration in the Control Player
ARIAS Santiago
parents:
170
diff
changeset
|
127 |
} |
e99fe78cd168
Gesture Control Integration in the Control Player
ARIAS Santiago
parents:
170
diff
changeset
|
128 |
#endregion |
e99fe78cd168
Gesture Control Integration in the Control Player
ARIAS Santiago
parents:
170
diff
changeset
|
129 |
|
162
0b9f989bcb37
Display annotations in all opened UserPanels with the user's color
sarias
parents:
156
diff
changeset
|
130 |
#region Button Simple Player Actions |
3 | 131 |
private void ButtonPlayPause_ContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e) |
132 |
{ |
|
34 | 133 |
if (!isPlaying)//Play |
3 | 134 |
{ |
34 | 135 |
isPlaying = true; |
3 | 136 |
try |
137 |
{ |
|
138 |
MediaElementVideo.Play(); |
|
168
d70ee2002f75
Thumb Timeline Rotation and Debug Closing Panels
ARIAS Santiago
parents:
165
diff
changeset
|
139 |
if (PlayerStopOrPause != null) |
d70ee2002f75
Thumb Timeline Rotation and Debug Closing Panels
ARIAS Santiago
parents:
165
diff
changeset
|
140 |
PlayerStopOrPause(true, new EventArgs()); |
3 | 141 |
} |
142 |
catch (Exception ex) { } |
|
143 |
} |
|
144 |
else//Pause |
|
145 |
{ |
|
34 | 146 |
isPlaying = false; |
3 | 147 |
try |
148 |
{ |
|
149 |
MediaElementVideo.Pause(); |
|
168
d70ee2002f75
Thumb Timeline Rotation and Debug Closing Panels
ARIAS Santiago
parents:
165
diff
changeset
|
150 |
if (PlayerStopOrPause != null) |
d70ee2002f75
Thumb Timeline Rotation and Debug Closing Panels
ARIAS Santiago
parents:
165
diff
changeset
|
151 |
PlayerStopOrPause(false, new EventArgs()); |
3 | 152 |
} |
34 | 153 |
catch (Exception exx) { } |
3 | 154 |
} |
155 |
||
156 |
} |
|
157 |
||
158 |
private void ButtonPlayPause_Click(object sender, RoutedEventArgs e) |
|
159 |
{ |
|
34 | 160 |
if (!isPlaying)//Play |
3 | 161 |
{ |
34 | 162 |
isPlaying = true; |
3 | 163 |
try |
164 |
{ |
|
165 |
MediaElementVideo.Play(); |
|
168
d70ee2002f75
Thumb Timeline Rotation and Debug Closing Panels
ARIAS Santiago
parents:
165
diff
changeset
|
166 |
if (PlayerStopOrPause != null) |
d70ee2002f75
Thumb Timeline Rotation and Debug Closing Panels
ARIAS Santiago
parents:
165
diff
changeset
|
167 |
PlayerStopOrPause(true, new EventArgs()); |
3 | 168 |
} |
34 | 169 |
catch (Exception ex) { } |
170 |
||
3 | 171 |
} |
172 |
else//Pause |
|
173 |
{ |
|
34 | 174 |
isPlaying = false; |
3 | 175 |
try |
176 |
{ |
|
177 |
MediaElementVideo.Pause(); |
|
168
d70ee2002f75
Thumb Timeline Rotation and Debug Closing Panels
ARIAS Santiago
parents:
165
diff
changeset
|
178 |
if (PlayerStopOrPause != null) |
d70ee2002f75
Thumb Timeline Rotation and Debug Closing Panels
ARIAS Santiago
parents:
165
diff
changeset
|
179 |
PlayerStopOrPause(false, new EventArgs()); |
3 | 180 |
} |
34 | 181 |
catch (Exception exx) { } |
182 |
//ButtonPlayPause.Background = FindResource("[Skin_1]_Play_button_xaml") as Brush; |
|
183 |
} |
|
184 |
} |
|
185 |
||
186 |
private void ButtonFastForward_Click(object sender, RoutedEventArgs e) |
|
187 |
{ |
|
188 |
if (MediaElementVideo.SpeedRatio <= 3) |
|
189 |
MediaElementVideo.SpeedRatio += 1; |
|
190 |
} |
|
191 |
||
192 |
private void ButtonFastForward_ContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e) |
|
193 |
{ |
|
194 |
if (MediaElementVideo.SpeedRatio <= 3) |
|
195 |
MediaElementVideo.SpeedRatio += 1; |
|
196 |
} |
|
197 |
||
198 |
private void ButtonRewind_Click(object sender, RoutedEventArgs e) |
|
199 |
{ |
|
200 |
//TimeSpan ts = new TimeSpan(0, 0, 0, 0); |
|
201 |
if (MediaElementVideo.SpeedRatio > 1) |
|
202 |
{ |
|
203 |
MediaElementVideo.SpeedRatio -= 1; |
|
3 | 204 |
} |
34 | 205 |
else |
206 |
{ |
|
207 |
MediaElementVideo.Position = MediaElementVideo.Position.Add(new TimeSpan(0, 0, 0, -5)); |
|
208 |
} |
|
209 |
} |
|
210 |
||
211 |
private void ButtonRewind_ContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e) |
|
212 |
{ |
|
213 |
||
214 |
//TimeSpan ts = new TimeSpan(0, 0, 0,0); |
|
215 |
if (MediaElementVideo.SpeedRatio > 1) |
|
216 |
{ |
|
217 |
MediaElementVideo.SpeedRatio -= 1; |
|
218 |
} |
|
219 |
else |
|
220 |
{ |
|
221 |
MediaElementVideo.Position = MediaElementVideo.Position.Add(new TimeSpan(0, 0, 0, -5)); |
|
222 |
} |
|
223 |
} |
|
224 |
||
162
0b9f989bcb37
Display annotations in all opened UserPanels with the user's color
sarias
parents:
156
diff
changeset
|
225 |
#endregion |
0b9f989bcb37
Display annotations in all opened UserPanels with the user's color
sarias
parents:
156
diff
changeset
|
226 |
|
34 | 227 |
private void MediaElementVideo_MediaOpened(object sender, RoutedEventArgs e) |
228 |
{ |
|
229 |
OnPlayerOpened(); |
|
230 |
} |
|
231 |
protected virtual void OnPlayerOpened() |
|
232 |
{ |
|
233 |
if(PlayerOpened!=null) |
|
234 |
PlayerOpened(this, new EventArgs()); |
|
3 | 235 |
} |
143 | 236 |
|
237 |
private void Play_Pause_area_DragEnter(object sender, SurfaceDragDropEventArgs e) |
|
238 |
{ |
|
239 |
//Console.WriteLine("Enter"); |
|
240 |
||
241 |
// If the TimelineAnnotationView comes from a user control different from the current one, |
|
242 |
// it means that we want to add the annotation to the current list. |
|
243 |
// 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) |
|
244 |
// e.Cursor.DragSource is the SurfaceListBox where the drag started from |
|
245 |
SurfaceListBox slb = (SurfaceListBox)e.Cursor.DragSource; |
|
246 |
// We get the instance of the UserControlSyncSource |
|
247 |
UserControl syncSrc = (UserControl)((Grid)((Grid)this.Parent).Parent).Parent; |
|
248 |
// and its UserControlTimeline |
|
249 |
UserControlTimeLine tl = (UserControlTimeLine)((Grid)((Grid)syncSrc.Content).Children[0]).Children[0]; |
|
250 |
if (((Grid)((UserControl)((Grid)slb.Parent).Parent).Parent).Parent != tl) |
|
251 |
{ |
|
252 |
// e.Cursor.Visual is the ContentControl, so its Content is the dragged TimelineAnnotationView |
|
253 |
AnnotationViewModel annotationDataVM = (AnnotationViewModel)((TimelineAnnotationView)((ContentControl)e.Cursor.Visual).Content).DataContext; |
|
254 |
Play_Pause_area.Background = tl.isAnnotationAccepted(annotationDataVM) ? new SolidColorBrush(Colors.Green) : new SolidColorBrush(Colors.Red); |
|
255 |
} |
|
256 |
else |
|
257 |
{ |
|
258 |
Play_Pause_area.Background = new SolidColorBrush(Colors.White); |
|
259 |
} |
|
260 |
Play_Pause_area.Opacity = 0.3; |
|
261 |
||
262 |
} |
|
263 |
||
264 |
private void Play_Pause_area_DragLeave(object sender, SurfaceDragDropEventArgs e) |
|
265 |
{ |
|
266 |
//Console.WriteLine("Leave"); |
|
267 |
Play_Pause_area.Opacity = 0; |
|
268 |
} |
|
269 |
||
270 |
private void Play_Pause_area_DragOver(object sender, SurfaceDragDropEventArgs e) |
|
271 |
{ |
|
272 |
//Console.WriteLine("Over"); |
|
273 |
} |
|
274 |
||
275 |
private void Play_Pause_area_Drop(object sender, SurfaceDragDropEventArgs e) |
|
276 |
{ |
|
277 |
//Console.WriteLine("Drop"); |
|
278 |
Play_Pause_area.Opacity = 0; |
|
279 |
// e.Cursor.Visual is the ContentControl, so its Content is the dragged TimelineAnnotationView |
|
280 |
AnnotationViewModel annotationDataVM = (AnnotationViewModel)((TimelineAnnotationView)((ContentControl)e.Cursor.Visual).Content).DataContext; |
|
281 |
int nbSeconds = (int)annotationDataVM.TcBegin; |
|
282 |
int nbMilliSec = (int)((annotationDataVM.TcBegin * 1000)%1000); |
|
283 |
MediaElementVideo.Position = new TimeSpan(0, 0, 0, nbSeconds, nbMilliSec); |
|
284 |
||
285 |
||
286 |
// If the TimelineAnnotationView comes from a user control different from the current one, |
|
287 |
// it means that we want to add the annotation to the current list. |
|
288 |
// So we generate the ActionAddAnnotation |
|
289 |
// e.Cursor.DragSource is the SurfaceListBox where the drag started from |
|
290 |
SurfaceListBox slb = (SurfaceListBox)e.Cursor.DragSource; |
|
291 |
// We get the instance of the UserControlSyncSource |
|
292 |
UserControl syncSrc = (UserControl)((Grid)((Grid)this.Parent).Parent).Parent; |
|
293 |
// and its UserControlTimeline |
|
294 |
UserControl tl = (UserControl)((Grid)((Grid)syncSrc.Content).Children[0]).Children[0]; |
|
295 |
if (((Grid)((UserControl)((Grid)slb.Parent).Parent).Parent).Parent != tl) |
|
296 |
{ |
|
297 |
// Now we build the action arguments : a list holding the timeline and the annotation view models |
|
298 |
List<Object> actionsArgs = new List<Object>(); |
|
299 |
actionsArgs.Add(tl); |
|
300 |
actionsArgs.Add(annotationDataVM); |
|
301 |
||
302 |
ActionGenerator ag = new ActionGenerator(); |
|
303 |
ActionBase ab = ag.GetAction("ActionAddAnnotation", actionsArgs); |
|
304 |
if (ab != null) |
|
305 |
ab.Execute(); |
|
306 |
} |
|
307 |
||
308 |
} |
|
162
0b9f989bcb37
Display annotations in all opened UserPanels with the user's color
sarias
parents:
156
diff
changeset
|
309 |
|
0b9f989bcb37
Display annotations in all opened UserPanels with the user's color
sarias
parents:
156
diff
changeset
|
310 |
//This function Sets a brush in a specific rectangle of the StackPanelAnnotation |
0b9f989bcb37
Display annotations in all opened UserPanels with the user's color
sarias
parents:
156
diff
changeset
|
311 |
public void displayStackPanelAnnotations(int id, Brush brushAnnotation) |
0b9f989bcb37
Display annotations in all opened UserPanels with the user's color
sarias
parents:
156
diff
changeset
|
312 |
{ |
163 | 313 |
Object o = null; |
162
0b9f989bcb37
Display annotations in all opened UserPanels with the user's color
sarias
parents:
156
diff
changeset
|
314 |
switch (id) |
0b9f989bcb37
Display annotations in all opened UserPanels with the user's color
sarias
parents:
156
diff
changeset
|
315 |
{ |
163 | 316 |
case 1: |
317 |
rect1.Fill = brushAnnotation; |
|
318 |
o = rect1.FindResource("Rect1Annotation"); |
|
319 |
rect1.BeginStoryboard((Storyboard)o); |
|
320 |
break; |
|
321 |
case 2: rect2.Fill = brushAnnotation; |
|
322 |
o = rect2.FindResource("Rect2Annotation"); |
|
323 |
rect2.BeginStoryboard((Storyboard)o); |
|
324 |
break; |
|
325 |
case 3: rect3.Fill = brushAnnotation; |
|
326 |
o = rect3.FindResource("Rect3Annotation"); |
|
327 |
rect3.BeginStoryboard((Storyboard)o); |
|
328 |
break; |
|
329 |
case 4: rect4.Fill = brushAnnotation; |
|
330 |
o = rect4.FindResource("Rect4Annotation"); |
|
331 |
rect4.BeginStoryboard((Storyboard)o); |
|
332 |
break; |
|
162
0b9f989bcb37
Display annotations in all opened UserPanels with the user's color
sarias
parents:
156
diff
changeset
|
333 |
default: break; |
0b9f989bcb37
Display annotations in all opened UserPanels with the user's color
sarias
parents:
156
diff
changeset
|
334 |
} |
0b9f989bcb37
Display annotations in all opened UserPanels with the user's color
sarias
parents:
156
diff
changeset
|
335 |
} |
3 | 336 |
} |
337 |
} |