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